Skip to content

Commit

Permalink
tests/: Remove dependency of testusers'
Browse files Browse the repository at this point in the history
As in future, the data will be fetched
from coala-webservices intead of @sks444
repository (webservices.coala.io). So,
to remove that dependency the tests have
been modified accordingly.
  • Loading branch information
kvgarg committed Jun 28, 2019
1 parent 394f03d commit d273573
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 10 deletions.
8 changes: 7 additions & 1 deletion data/tests/test_contrib_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

from django.test import TestCase

from data.contrib_data import get_contrib_data
from data.contrib_data import get_contrib_data, import_data
from gamification.tests.test_management_commands import (
get_false_contributors_data)


class GetContribDataTest(TestCase):

def test_get_contrib_data(self):
with requests_mock.Mocker():
get_contrib_data()

def test_false_contributor_data(self):
for contrib in get_false_contributors_data():
import_data(contrib)
8 changes: 7 additions & 1 deletion data/tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

from django.test import TestCase

from data.issues import fetch_issues
from data.issues import fetch_issues, import_issue
from gamification.tests.test_management_commands import (
get_false_issues_data)


class FetchIssueTest(TestCase):

def test_fetch_issues(self):
with requests_mock.Mocker():
fetch_issues('GitHub')

def test_false_issue_data(self):
for issue in get_false_issues_data():
import_issue('github', issue)
6 changes: 2 additions & 4 deletions data/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def test_command_import_issues_data(self):
if not issues:
raise unittest.SkipTest(
'No record of issues from webservices')
self.assertIn('testuser',
[issue.author.login for issue in issues])
self.assertGreater(issues.count(), 0)


class ImportMergeRequestDataTest(TestCase):
Expand All @@ -47,5 +46,4 @@ def test_command_import_issues_data(self):
if not mrs:
raise unittest.SkipTest(
'No record of mrs from webservices')
self.assertIn('testuser',
[mr.author.login for mr in mrs])
self.assertGreater(mrs.count(), 0)
7 changes: 6 additions & 1 deletion data/tests/test_merge_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

from django.test import TestCase

from data.merge_requests import fetch_mrs
from data.merge_requests import fetch_mrs, import_mr
from gamification.tests.test_management_commands import (get_false_mrs_data)


class FetchMergeRequestTest(TestCase):

def test_fetch_mrs(self):
with requests_mock.Mocker():
fetch_mrs('GitHub')

def test_false_mr_data(self):
for mr in get_false_mrs_data():
import_mr('github', mr)
4 changes: 1 addition & 3 deletions data/tests/test_org_cluster_map_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def setUpTestData(cls):
location='{"latitude": 12.9,'
'"longitude": 77.8}')
Contributor.objects.create(login='testuser',
name='Test User 2',
location='{"latitude": 15.912,'
'"longitude": 90.821}')
name='Test User 2')

def test_with_output_dir(self):
org_cluster_map_handler()
Expand Down
219 changes: 219 additions & 0 deletions gamification/tests/test_management_commands.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from django.core.management import call_command
from django.test import TestCase

from data.issues import import_issue
from community.git import get_org_name
from data.merge_requests import import_mr
from gamification.models import (
Level,
Badge,
Participant,
BadgeActivity,
)
from data.contrib_data import import_data
from data.newcomers import active_newcomers

ORG_NAME = get_org_name()


class CreateConfigDataTest(TestCase):

Expand Down Expand Up @@ -79,6 +85,18 @@ class UpdateParticipantsTest(TestCase):

@classmethod
def setUpTestData(cls):
for contrib in get_false_contributors_data():
import_data(contrib)

for issue in get_false_issues_data():
import_issue('github', issue)

for mr in get_false_mrs_data():
import_mr('github', mr)

for contrib in get_false_active_newcomers():
Participant.objects.create(username=contrib['username'])

call_command('import_issues_data')
call_command('import_merge_requests_data')
call_command('create_config_data')
Expand All @@ -98,3 +116,204 @@ def test_command_update_particiapants_data(self):

number_of_badges = participant.badges.all().count()
self.assertEquals(number_of_badges, 2)


def get_false_contributors_data():
return [
{
'bio': '',
'teams': [
f'{ORG_NAME} newcomers'
],
'reviews': 0,
'issues': 0,
'name': '',
'login': 'testuser',
'contributions': 1
},
{
'bio': '',
'teams': [
f'{ORG_NAME} newcomers'
],
'reviews': 0,
'issues': 0,
'name': '',
'login': 'testuser',
'contributions': 1
},
{
'bio': '',
'teams': [
],
'reviews': 0,
'name': '',
'login': 'testuser1',
'contributions': 1
}
]


def get_false_issues_data():
return [
{
'created_at': '2016-11-21T00:46:14',
'hoster': 'github',
'updated_at': '2017-12-21T00:00:48',
'labels': [
'status/duplicate'
],
'number': 1,
'assignees': [],
'repo_id': 254525111,
'title': 'Test issue',
'state': 'closed',
'repo': f'{ORG_NAME}/{ORG_NAME}',
'url': f'https://github.com/{ORG_NAME}/corobo/issues/585',
'author': 'testuser'
},
{
'created_at': '2016-11-21T00:46:14',
'hoster': 'github',
'updated_at': '2017-12-21T00:00:48',
'labels': [
'difficulty/newcomer',
'type/bug'
],
'number': 3,
'assignees': [],
'repo_id': 254525111,
'title': 'Test issue',
'state': 'closed',
'repo': f'{ORG_NAME}/{ORG_NAME}',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/issues/1',
'author': 'testuser1'
},
{
'created_at': '2016-11-21T00:46:14',
'hoster': 'github',
'updated_at': '2017-12-21T00:00:48',
'labels': [
'difficulty/newcomer',
'type/bug'
],
'number': 2,
'assignees': [],
'repo_id': 254525111,
'title': 'Test issue',
'state': 'closed',
'repo': f'{ORG_NAME}/{ORG_NAME}',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/issues/2',
'author': 'testuser'
},
{
'created_at': '2016-11-21T00:46:14',
'hoster': 'github',
'updated_at': '2017-12-21T00:00:48',
'labels': [
'difficulty/newcomer',
'type/bug'
],
'number': 2,
'assignees': [],
'title': 'Test issue',
'state': 'closed',
'repo': 'test/test',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/issues/3',
'author': 'testuser1'
}
]


def get_false_mrs_data():
return [
{
'created_at': '2016-02-21T05:04:25',
'hoster': 'github',
'ci_status': True,
'labels': [
'difficulty/newcomer',
'type/bug'
],
'title': 'Test merge request-I',
'number': 1625,
'updated_at': '2016-04-21T12:06:19',
'assignees': [],
'repo_id': 254525111,
'closes_issues': [
2,
3
],
'repo': f'{ORG_NAME}/{ORG_NAME}',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1625',
'state': 'merged',
'author': 'testuser'
},
{
'created_at': '2016-02-21T05:04:25',
'hoster': 'github',
'ci_status': True,
'labels': [
'status/STALE'
],
'title': 'Test merge request-II',
'number': 1626,
'updated_at': '2016-02-21T12:06:19',
'assignees': [],
'repo_id': 25452511,
'closes_issues': [
],
'repo': f'{ORG_NAME}/{ORG_NAME}',
'state': 'merged',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1626',
'author': 'testuser'
},
{
'created_at': '2016-02-21T05:04:25',
'hoster': 'github',
'ci_status': True,
'labels': [
'difficulty/low',
'type/bug'
],
'title': 'Test merge request-III',
'number': 1626,
'updated_at': '2016-02-21T12:06:19',
'assignees': [
'testuser',
'testuser1'
],
'repo_id': 25452511,
'closes_issues': [
],
'repo': f'{ORG_NAME}/{ORG_NAME}',
'state': 'merged',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1625',
'author': 'testuser'
},
{
'created_at': '2016-02-21T05:04:25',
'hoster': 'github',
'labels': [
'difficulty/low',
'type/bug'
],
'title': 'Test merge request-III',
'number': 1626,
'updated_at': '2016-02-21T12:06:19',
'assignees': [],
'repo_id': 25452511,
'repo': f'{ORG_NAME}/{ORG_NAME}',
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1625',
'closes_issues': [
],
'author': 'testuser1'
}
]


def get_false_active_newcomers():
return [
{'username': 'testuser'},
{'username': 'testuser1'}
]

0 comments on commit d273573

Please sign in to comment.