Skip to content

Commit b28cd39

Browse files
author
kvgarg
committed
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.
1 parent 8740cd4 commit b28cd39

6 files changed

Lines changed: 242 additions & 10 deletions

File tree

data/tests/test_contrib_data.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
from django.test import TestCase
44

5-
from data.contrib_data import get_contrib_data
5+
from data.contrib_data import get_contrib_data, import_data
6+
from gamification.tests.test_management_commands import (
7+
get_false_contributors_data)
68

79

810
class GetContribDataTest(TestCase):
911

1012
def test_get_contrib_data(self):
1113
with requests_mock.Mocker():
1214
get_contrib_data()
15+
16+
def test_false_contributor_data(self):
17+
for contrib in get_false_contributors_data():
18+
import_data(contrib)

data/tests/test_issues.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
from django.test import TestCase
44

5-
from data.issues import fetch_issues
5+
from data.issues import fetch_issues, import_issue
6+
from gamification.tests.test_management_commands import (
7+
get_false_issues_data)
68

79

810
class FetchIssueTest(TestCase):
911

1012
def test_fetch_issues(self):
1113
with requests_mock.Mocker():
1214
fetch_issues('GitHub')
15+
16+
def test_false_issue_data(self):
17+
for issue in get_false_issues_data():
18+
import_issue('github', issue)

data/tests/test_management_commands.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def test_command_import_issues_data(self):
3232
if not issues:
3333
raise unittest.SkipTest(
3434
'No record of issues from webservices')
35-
self.assertIn('testuser',
36-
[issue.author.login for issue in issues])
35+
self.assertGreater(issues.count(), 0)
3736

3837

3938
class ImportMergeRequestDataTest(TestCase):
@@ -47,5 +46,4 @@ def test_command_import_issues_data(self):
4746
if not mrs:
4847
raise unittest.SkipTest(
4948
'No record of mrs from webservices')
50-
self.assertIn('testuser',
51-
[mr.author.login for mr in mrs])
49+
self.assertGreater(mrs.count(), 0)

data/tests/test_merge_requests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
from django.test import TestCase
44

5-
from data.merge_requests import fetch_mrs
5+
from data.merge_requests import fetch_mrs, import_mr
6+
from gamification.tests.test_management_commands import (get_false_mrs_data)
67

78

89
class FetchMergeRequestTest(TestCase):
910

1011
def test_fetch_mrs(self):
1112
with requests_mock.Mocker():
1213
fetch_mrs('GitHub')
14+
15+
def test_false_mr_data(self):
16+
for mr in get_false_mrs_data():
17+
import_mr('github', mr)

data/tests/test_org_cluster_map_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def setUpTestData(cls):
1313
location='{"latitude": 12.9,'
1414
'"longitude": 77.8}')
1515
Contributor.objects.create(login='testuser',
16-
name='Test User 2',
17-
location='{"latitude": 15.912,'
18-
'"longitude": 90.821}')
16+
name='Test User 2')
1917

2018
def test_with_output_dir(self):
2119
org_cluster_map_handler()

gamification/tests/test_management_commands.py

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
from django.core.management import call_command
22
from django.test import TestCase
33

4+
from data.issues import import_issue
5+
from community.git import get_org_name
6+
from data.merge_requests import import_mr
47
from gamification.models import (
58
Level,
69
Badge,
710
Participant,
811
BadgeActivity,
912
)
13+
from data.contrib_data import import_data
1014
from data.newcomers import active_newcomers
1115

16+
ORG_NAME = get_org_name()
17+
1218

1319
class CreateConfigDataTest(TestCase):
1420

@@ -79,6 +85,18 @@ class UpdateParticipantsTest(TestCase):
7985

8086
@classmethod
8187
def setUpTestData(cls):
88+
for contrib in get_false_contributors_data():
89+
import_data(contrib)
90+
91+
for issue in get_false_issues_data():
92+
import_issue('github', issue)
93+
94+
for mr in get_false_mrs_data():
95+
import_mr('github', mr)
96+
97+
for contrib in get_false_active_newcomers():
98+
Participant.objects.create(username=contrib['username'])
99+
82100
call_command('import_issues_data')
83101
call_command('import_merge_requests_data')
84102
call_command('create_config_data')
@@ -98,3 +116,204 @@ def test_command_update_particiapants_data(self):
98116

99117
number_of_badges = participant.badges.all().count()
100118
self.assertEquals(number_of_badges, 2)
119+
120+
121+
def get_false_contributors_data():
122+
return [
123+
{
124+
'bio': '',
125+
'teams': [
126+
f'{ORG_NAME} newcomers'
127+
],
128+
'reviews': 0,
129+
'issues': 0,
130+
'name': '',
131+
'login': 'testuser',
132+
'contributions': 1
133+
},
134+
{
135+
'bio': '',
136+
'teams': [
137+
f'{ORG_NAME} newcomers'
138+
],
139+
'reviews': 0,
140+
'issues': 0,
141+
'name': '',
142+
'login': 'testuser',
143+
'contributions': 1
144+
},
145+
{
146+
'bio': '',
147+
'teams': [
148+
],
149+
'reviews': 0,
150+
'name': '',
151+
'login': 'testuser1',
152+
'contributions': 1
153+
}
154+
]
155+
156+
157+
def get_false_issues_data():
158+
return [
159+
{
160+
'created_at': '2016-11-21T00:46:14',
161+
'hoster': 'github',
162+
'updated_at': '2017-12-21T00:00:48',
163+
'labels': [
164+
'status/duplicate'
165+
],
166+
'number': 1,
167+
'assignees': [],
168+
'repo_id': 254525111,
169+
'title': 'Test issue',
170+
'state': 'closed',
171+
'repo': f'{ORG_NAME}/{ORG_NAME}',
172+
'url': f'https://github.com/{ORG_NAME}/corobo/issues/585',
173+
'author': 'testuser'
174+
},
175+
{
176+
'created_at': '2016-11-21T00:46:14',
177+
'hoster': 'github',
178+
'updated_at': '2017-12-21T00:00:48',
179+
'labels': [
180+
'difficulty/newcomer',
181+
'type/bug'
182+
],
183+
'number': 3,
184+
'assignees': [],
185+
'repo_id': 254525111,
186+
'title': 'Test issue',
187+
'state': 'closed',
188+
'repo': f'{ORG_NAME}/{ORG_NAME}',
189+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/issues/1',
190+
'author': 'testuser1'
191+
},
192+
{
193+
'created_at': '2016-11-21T00:46:14',
194+
'hoster': 'github',
195+
'updated_at': '2017-12-21T00:00:48',
196+
'labels': [
197+
'difficulty/newcomer',
198+
'type/bug'
199+
],
200+
'number': 2,
201+
'assignees': [],
202+
'repo_id': 254525111,
203+
'title': 'Test issue',
204+
'state': 'closed',
205+
'repo': f'{ORG_NAME}/{ORG_NAME}',
206+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/issues/2',
207+
'author': 'testuser'
208+
},
209+
{
210+
'created_at': '2016-11-21T00:46:14',
211+
'hoster': 'github',
212+
'updated_at': '2017-12-21T00:00:48',
213+
'labels': [
214+
'difficulty/newcomer',
215+
'type/bug'
216+
],
217+
'number': 2,
218+
'assignees': [],
219+
'title': 'Test issue',
220+
'state': 'closed',
221+
'repo': 'test/test',
222+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/issues/3',
223+
'author': 'testuser1'
224+
}
225+
]
226+
227+
228+
def get_false_mrs_data():
229+
return [
230+
{
231+
'created_at': '2016-02-21T05:04:25',
232+
'hoster': 'github',
233+
'ci_status': True,
234+
'labels': [
235+
'difficulty/newcomer',
236+
'type/bug'
237+
],
238+
'title': 'Test merge request-I',
239+
'number': 1625,
240+
'updated_at': '2016-04-21T12:06:19',
241+
'assignees': [],
242+
'repo_id': 254525111,
243+
'closes_issues': [
244+
2,
245+
3
246+
],
247+
'repo': f'{ORG_NAME}/{ORG_NAME}',
248+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1625',
249+
'state': 'merged',
250+
'author': 'testuser'
251+
},
252+
{
253+
'created_at': '2016-02-21T05:04:25',
254+
'hoster': 'github',
255+
'ci_status': True,
256+
'labels': [
257+
'status/STALE'
258+
],
259+
'title': 'Test merge request-II',
260+
'number': 1626,
261+
'updated_at': '2016-02-21T12:06:19',
262+
'assignees': [],
263+
'repo_id': 25452511,
264+
'closes_issues': [
265+
],
266+
'repo': f'{ORG_NAME}/{ORG_NAME}',
267+
'state': 'merged',
268+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1626',
269+
'author': 'testuser'
270+
},
271+
{
272+
'created_at': '2016-02-21T05:04:25',
273+
'hoster': 'github',
274+
'ci_status': True,
275+
'labels': [
276+
'difficulty/low',
277+
'type/bug'
278+
],
279+
'title': 'Test merge request-III',
280+
'number': 1626,
281+
'updated_at': '2016-02-21T12:06:19',
282+
'assignees': [
283+
'testuser',
284+
'testuser1'
285+
],
286+
'repo_id': 25452511,
287+
'closes_issues': [
288+
],
289+
'repo': f'{ORG_NAME}/{ORG_NAME}',
290+
'state': 'merged',
291+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1625',
292+
'author': 'testuser'
293+
},
294+
{
295+
'created_at': '2016-02-21T05:04:25',
296+
'hoster': 'github',
297+
'labels': [
298+
'difficulty/low',
299+
'type/bug'
300+
],
301+
'title': 'Test merge request-III',
302+
'number': 1626,
303+
'updated_at': '2016-02-21T12:06:19',
304+
'assignees': [],
305+
'repo_id': 25452511,
306+
'repo': f'{ORG_NAME}/{ORG_NAME}',
307+
'url': f'https://github.com/{ORG_NAME}/{ORG_NAME}/pull/1625',
308+
'closes_issues': [
309+
],
310+
'author': 'testuser1'
311+
}
312+
]
313+
314+
315+
def get_false_active_newcomers():
316+
return [
317+
{'username': 'testuser'},
318+
{'username': 'testuser1'}
319+
]

0 commit comments

Comments
 (0)