From d273573ab9e0cc805b1dce00237b4ee08c58871e Mon Sep 17 00:00:00 2001 From: kvgarg Date: Tue, 25 Jun 2019 15:57:07 +0530 Subject: [PATCH] tests/: Remove dependency of testusers' 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. --- data/tests/test_contrib_data.py | 8 +- data/tests/test_issues.py | 8 +- data/tests/test_management_commands.py | 6 +- data/tests/test_merge_requests.py | 7 +- data/tests/test_org_cluster_map_handler.py | 4 +- .../tests/test_management_commands.py | 219 ++++++++++++++++++ 6 files changed, 242 insertions(+), 10 deletions(-) diff --git a/data/tests/test_contrib_data.py b/data/tests/test_contrib_data.py index e820e413..88a20ac8 100644 --- a/data/tests/test_contrib_data.py +++ b/data/tests/test_contrib_data.py @@ -2,7 +2,9 @@ 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): @@ -10,3 +12,7 @@ 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) diff --git a/data/tests/test_issues.py b/data/tests/test_issues.py index f94e23e3..b75bc041 100644 --- a/data/tests/test_issues.py +++ b/data/tests/test_issues.py @@ -2,7 +2,9 @@ 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): @@ -10,3 +12,7 @@ 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) diff --git a/data/tests/test_management_commands.py b/data/tests/test_management_commands.py index f1309700..866616eb 100644 --- a/data/tests/test_management_commands.py +++ b/data/tests/test_management_commands.py @@ -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): @@ -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) diff --git a/data/tests/test_merge_requests.py b/data/tests/test_merge_requests.py index 3d4350a8..f0efdead 100644 --- a/data/tests/test_merge_requests.py +++ b/data/tests/test_merge_requests.py @@ -2,7 +2,8 @@ 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): @@ -10,3 +11,7 @@ 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) diff --git a/data/tests/test_org_cluster_map_handler.py b/data/tests/test_org_cluster_map_handler.py index 009af1fc..8199dcc0 100644 --- a/data/tests/test_org_cluster_map_handler.py +++ b/data/tests/test_org_cluster_map_handler.py @@ -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() diff --git a/gamification/tests/test_management_commands.py b/gamification/tests/test_management_commands.py index 7519d3ad..ba795dc8 100644 --- a/gamification/tests/test_management_commands.py +++ b/gamification/tests/test_management_commands.py @@ -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): @@ -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') @@ -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'} + ]