Skip to content

Commit daf1d9c

Browse files
committed
Added >= test for cytoscape
1 parent d221ed2 commit daf1d9c

File tree

2 files changed

+64
-33
lines changed

2 files changed

+64
-33
lines changed

main/management/commands/updatecomponents.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ def handle(self, *args, **options):
105105

106106
if _component.github_url:
107107
print _component.github_url
108-
github_data = get_github_data(_component.github_url)
108+
try:
109+
github_data = get_github_data(_component.github_url)
110+
except:
111+
continue
109112
_component.stars = github_data['stargazers_count']
110113
_component.forks = github_data['forks']
111-
_component.watchers = github_data['watchers']
114+
# subscriber_count
115+
_component.watchers = github_data['subscribers_count']
112116
_component.icon_url = github_data['owner']['avatar_url']
113117
_component.open_issues = github_data['open_issues']
114118
try:
@@ -124,7 +128,10 @@ def handle(self, *args, **options):
124128
pass
125129
_component.save()
126130
print str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
127-
contributors_data = get_contributors_data(str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
131+
try:
132+
contributors_data = get_contributors_data(str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
133+
except:
134+
continue
128135
commits = 0
129136
count = 0
130137
for contributor in contributors_data:
@@ -140,7 +147,10 @@ def handle(self, *args, **options):
140147
_contribution = Contribution.objects.create(component=_component, contributor=_contributor, contributions=contributor["contributions"])
141148
commits += _contribution.contributions
142149
count +=1
143-
_component.downloads = get_downloads(str(github_data['downloads_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
150+
try:
151+
_component.downloads = get_downloads(str(github_data['downloads_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
152+
except:
153+
pass
144154
_component.commits = commits
145155
_component.no_of_contributors = count
146156
_component.save()

tests/test_views.py

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,15 @@ class DetailComponentViewTest(TestCase):
138138
def setUpTestData(cls):
139139
# Called initially when test is executed, create objects to be used by test methods
140140
# create a random object
141+
# Add a benchmark component
141142
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
142143
req = urllib2.Request("http://registry.npmjs.com/-/v1/search?text=biojs-vis-rohart-msc-test", headers=hdr)
143144
response = urllib2.urlopen(req)
144145
data = json.load(response)
146+
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
147+
req = urllib2.Request("http://registry.npmjs.com/-/v1/search?text=cytoscape&size=1", headers=hdr)
148+
response = urllib2.urlopen(req)
149+
data['objects'].append(json.load(response)['objects'][0])
145150
for component in data['objects']:
146151
component_data = component['package']
147152
_component = Component.objects.create(name=component_data['name'])
@@ -245,47 +250,63 @@ def setUpTestData(cls):
245250
def test_view_url_exists_at_desired_location(self):
246251
response = self.client.get('/details/biojs-vis-rohart-msc-test/')
247252
self.assertEqual(response.status_code, 200)
253+
response = self.client.get('/details/cytoscape/')
254+
self.assertEqual(response.status_code, 200)
248255

249256
def test_view_accessible_by_name(self):
250257
response = self.client.get(reverse('main:component_details', kwargs={'url_name':'biojs-vis-rohart-msc-test'}))
251258
self.assertEqual(response.status_code, 200)
259+
response = self.client.get(reverse('main:component_details', kwargs={'url_name':'cytoscape'}))
260+
self.assertEqual(response.status_code, 200)
252261

253262
# Tests whether the relevant keys are present in the json response and length of response list is same as number of components in database
254263
def test_relevance_of_response(self):
255-
response = self.client.get(reverse('main:component_details', kwargs={'url_name':'biojs-vis-rohart-msc-test'}))
256-
self.assertTrue('details' in response.json())
264+
# call for biojs-vis-rohart-msc-test
265+
response_1 = self.client.get(reverse('main:component_details', kwargs={'url_name':'biojs-vis-rohart-msc-test'}))
266+
self.assertTrue('details' in response_1.json())
267+
objects = []
268+
objects.append(response_1.json()['details'])
269+
# call for cytoscape
270+
response_2 = self.client.get(reverse('main:component_details', kwargs={'url_name':'cytoscape'}))
271+
self.assertTrue('details' in response_2.json())
272+
objects.append(response_2.json()['details'])
257273
# Test if all the required fields are present in the response
258-
object = response.json()['details']
259-
self.assertTrue(
260-
'name' in object and
261-
'tags' in object and
262-
'stars' in object and
263-
'downloads' in object and
264-
'created_time' in object and
265-
'modified_time' in object and
266-
'icon_url' in object and
267-
'github_url' in object and
268-
'short_description' in object and
269-
'url_name' in object and
270-
'commits' in object and
271-
'forks' in object and
272-
'watchers' in object and
273-
'no_of_contributors' in object and
274-
'open_issues' in object and
275-
'version' in object and
276-
'author' in object and
277-
'license' in object
278-
)
279-
# check if number of commits >= 50, from the time the tests were initiated
274+
for object in objects:
275+
self.assertTrue(
276+
'name' in object and
277+
'tags' in object and
278+
'stars' in object and
279+
'downloads' in object and
280+
'created_time' in object and
281+
'modified_time' in object and
282+
'icon_url' in object and
283+
'github_url' in object and
284+
'short_description' in object and
285+
'url_name' in object and
286+
'commits' in object and
287+
'forks' in object and
288+
'watchers' in object and
289+
'no_of_contributors' in object and
290+
'open_issues' in object and
291+
'version' in object and
292+
'author' in object and
293+
'license' in object
294+
)
295+
# check if number of commits >= 50 for biojs-vis-rohart-msc-test
296+
# and >= 3757 for cytoscape, from the time the tests were initiated
280297
### As number of stars, watchers might go down in the future so they haven't been tested
281-
self.assertTrue(int(response.json()['details']['commits']) >= 50)
298+
self.assertTrue(int(response_1.json()['details']['commits']) >= 50)
299+
self.assertTrue(int(response_2.json()['details']['commits']) >= 3757)
282300

283301
# modified date should be after created date
284-
self.assertTrue(response.json()['details']['created_time'] <= response.json()['details']['modified_time'])
302+
self.assertTrue(response_1.json()['details']['created_time'] <= response_1.json()['details']['modified_time']) # for biojs-vis-rohart-msc-test
303+
self.assertTrue(response_2.json()['details']['created_time'] <= response_2.json()['details']['modified_time']) # for cytoscape
285304
# check if number of contributors is same as contributors added
286-
self.assertEqual(response.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='biojs-vis-rohart-msc-test')).count())
287-
self.assertEqual(response.json()['details']['no_of_contributors'], len(response.json()['contributors']))
288-
for object in response.json()['contributors']:
305+
self.assertEqual(response_1.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='biojs-vis-rohart-msc-test')).count())
306+
self.assertEqual(response_1.json()['details']['no_of_contributors'], len(response_1.json()['contributors']))
307+
self.assertEqual(response_2.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='cytoscape')).count())
308+
self.assertEqual(response_2.json()['details']['no_of_contributors'], len(response_2.json()['contributors']))
309+
for object in response_1.json()['contributors'] + response_2.json()['contributors']:
289310
self.assertTrue(
290311
'contributor' in object and
291312
'contributions' in object and

0 commit comments

Comments
 (0)