Skip to content

Commit 32bac5b

Browse files
committed
Updated test for build/ dependencies
1 parent 23edfff commit 32bac5b

File tree

1 file changed

+113
-102
lines changed

1 file changed

+113
-102
lines changed

tests/test_views.py

Lines changed: 113 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ def setUpTestData(cls):
216216
# print _component.github_url
217217
response = urllib.urlopen(_component.github_url)
218218
github_data = json.load(response)
219-
_component.stars = github_data['stargazers_count']
219+
try:
220+
_component.stars = github_data['stargazers_count']
221+
except:
222+
_component.github_url = None
223+
_component.save()
224+
continue
220225
_component.forks = github_data['forks']
221226
_component.watchers = github_data['watchers']
222227
_component.icon_url = github_data['owner']['avatar_url']
@@ -287,6 +292,7 @@ def test_view_accessible_by_name(self):
287292
# Tests whether the relevant keys are present in the json response and length of response list is same as number of components in database
288293
def test_relevance_of_response(self):
289294
# call for biojs-vis-rohart-msc-test
295+
current_component = Component.objects.get(url_name="biojs-vis-rohart-msc-test")
290296
response_1 = self.client.get(reverse('main:component_details', kwargs={'url_name':'biojs-vis-rohart-msc-test'}))
291297
self.assertTrue('details' in response_1.json())
292298
objects = []
@@ -300,110 +306,115 @@ def test_relevance_of_response(self):
300306
self.assertTrue('details' in response_3.json())
301307
objects.append(response_3.json()['details'])
302308
# Test if all the required fields are present in the response
303-
for object in objects:
304-
self.assertTrue(
305-
'name' in object and
306-
'tags' in object and
307-
'stars' in object and
308-
'downloads' in object and
309-
'created_time' in object and
310-
'modified_time' in object and
311-
'icon_url' in object and
312-
'github_url' in object and
313-
'short_description' in object and
314-
'url_name' in object and
315-
'commits' in object and
316-
'forks' in object and
317-
'watchers' in object and
318-
'no_of_contributors' in object and
319-
'open_issues' in object and
320-
'version' in object and
321-
'author' in object and
322-
'license' in object and
323-
'github_update_time' in object and
324-
'latest_commit_hash' in object
325-
)
326-
# check if number of commits >= 50 for biojs-vis-rohart-msc-test
327-
# and >= 3757 for cytoscape, from the time the tests were initiated
328-
### As number of stars, watchers might go down in the future so they haven't been tested
329-
self.assertTrue(int(response_1.json()['details']['commits']) >= 50)
330-
self.assertTrue(int(response_2.json()['details']['commits']) >= 3757)
309+
if current_component.github_url: # Make sure data was returned by Github API. Ignore if no data returned
310+
for object in objects:
311+
self.assertTrue(
312+
'name' in object and
313+
'tags' in object and
314+
'stars' in object and
315+
'downloads' in object and
316+
'created_time' in object and
317+
'modified_time' in object and
318+
'icon_url' in object and
319+
'github_url' in object and
320+
'short_description' in object and
321+
'url_name' in object and
322+
'commits' in object and
323+
'forks' in object and
324+
'watchers' in object and
325+
'no_of_contributors' in object and
326+
'open_issues' in object and
327+
'version' in object and
328+
'author' in object and
329+
'license' in object and
330+
'github_update_time' in object and
331+
'latest_commit_hash' in object
332+
)
333+
# check if number of commits >= 50 for biojs-vis-rohart-msc-test
334+
# and >= 3757 for cytoscape, from the time the tests were initiated
335+
### As number of stars, watchers might go down in the future so they haven't been tested
336+
self.assertTrue(int(response_1.json()['details']['commits']) >= 50)
337+
self.assertTrue(int(response_2.json()['details']['commits']) >= 3757)
331338

332339
# Tests for benchmark component
333-
self.assertTrue(int(response_3.json()['details']['stars']) >= 3)
334-
self.assertTrue(int(response_2.json()['details']['commits']) >= 70)
340+
self.assertTrue(int(response_3.json()['details']['stars']) >= 3)
341+
self.assertTrue(int(response_2.json()['details']['commits']) >= 70)
335342

336343
# modified date should be after created date
337-
self.assertTrue(response_1.json()['details']['created_time'] <= response_1.json()['details']['github_update_time']) # for biojs-vis-rohart-msc-test
338-
self.assertTrue(response_2.json()['details']['created_time'] <= response_2.json()['details']['github_update_time']) # for cytoscape
339-
self.assertTrue(response_3.json()['details']['created_time'] <= response_3.json()['details']['github_update_time']) # for mplexviz-ngraph
340-
# check if number of contributors is same as contributors added
341-
self.assertEqual(response_1.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='biojs-vis-rohart-msc-test')).count())
342-
self.assertEqual(response_1.json()['details']['no_of_contributors'], len(response_1.json()['contributors']))
343-
self.assertEqual(response_2.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='cytoscape')).count())
344-
self.assertEqual(response_2.json()['details']['no_of_contributors'], len(response_2.json()['contributors']))
345-
self.assertEqual(response_3.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='mplexviz-ngraph')).count())
346-
self.assertEqual(response_3.json()['details']['no_of_contributors'], len(response_3.json()['contributors']))
347-
for object in response_1.json()['contributors'] + response_2.json()['contributors'] + response_3.json()['contributors']:
348-
self.assertTrue(
349-
'contributor' in object and
350-
'contributions' in object and
351-
'id' in object
352-
)
353-
contributor_details = object['contributor']
354-
self.assertTrue(
355-
'username' in contributor_details and
356-
'avatar_url' in contributor_details
357-
)
344+
self.assertTrue(response_1.json()['details']['created_time'] <= response_1.json()['details']['github_update_time']) # for biojs-vis-rohart-msc-test
345+
self.assertTrue(response_2.json()['details']['created_time'] <= response_2.json()['details']['github_update_time']) # for cytoscape
346+
self.assertTrue(response_3.json()['details']['created_time'] <= response_3.json()['details']['github_update_time']) # for mplexviz-ngraph
347+
# check if number of contributors is same as contributors added
348+
self.assertEqual(response_1.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='biojs-vis-rohart-msc-test')).count())
349+
self.assertEqual(response_1.json()['details']['no_of_contributors'], len(response_1.json()['contributors']))
350+
self.assertEqual(response_2.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='cytoscape')).count())
351+
self.assertEqual(response_2.json()['details']['no_of_contributors'], len(response_2.json()['contributors']))
352+
self.assertEqual(response_3.json()['details']['no_of_contributors'], Contribution.objects.filter(component=Component.objects.get(name='mplexviz-ngraph')).count())
353+
self.assertEqual(response_3.json()['details']['no_of_contributors'], len(response_3.json()['contributors']))
354+
for object in response_1.json()['contributors'] + response_2.json()['contributors'] + response_3.json()['contributors']:
355+
self.assertTrue(
356+
'contributor' in object and
357+
'contributions' in object and
358+
'id' in object
359+
)
360+
contributor_details = object['contributor']
361+
self.assertTrue(
362+
'username' in contributor_details and
363+
'avatar_url' in contributor_details
364+
)
358365

359-
# tests for visualizations
360-
# Test for JS and CSS dependencies as well as snippets names.
361-
# Cytoscape
362-
if 'js_dependencies' in response_2.json():
363-
for js_dependency in response_2.json()['js_dependencies']:
364-
url = js_dependency['js_url']
365-
latest_commit_hash = response_2.json()['details']['latest_commit_hash']
366-
# Verify that cdn URL is configured correctly
367-
if('cdn.rawgit.com' in url):
368-
self.assertTrue(latest_commit_hash in url)
369-
if 'css_dependencies' in response_2.json():
370-
for css_dependency in response_2.json()['css_dependencies']:
371-
url = css_dependency['css_url']
372-
latest_commit_hash = response_2.json()['details']['latest_commit_hash']
373-
# Verify that cdn URL is configured correctly
374-
if('cdn.rawgit.com' in url):
375-
self.assertTrue(latest_commit_hash in url)
376-
if 'snippets' in response_2.json():
377-
snippets_list = ['animated-bfs', 'images', 'performance-tuning', 'visual']
378-
for snippet in response_2.json()['snippets']:
379-
latest_commit_hash = response_2.json()['details']['latest_commit_hash']
380-
url = snippet['url']
381-
name = snippet['name']
382-
if('cdn.rawgit.com' in url):
383-
self.assertTrue(latest_commit_hash in url)
384-
self.assertTrue(name in snippets_list)
366+
# tests for visualizations
367+
# Test for JS and CSS dependencies as well as snippets names.
368+
# Cytoscape
369+
if 'js_dependencies' in response_2.json():
370+
for js_dependency in response_2.json()['js_dependencies']:
371+
url = js_dependency['js_url']
372+
print url
373+
# verify absence of 'build/' dependencies
374+
self.assertTrue('build/' not in url)
375+
latest_commit_hash = response_2.json()['details']['latest_commit_hash']
376+
# Verify that cdn URL is configured correctly
377+
if('cdn.rawgit.com' in url):
378+
self.assertTrue(latest_commit_hash in url)
379+
if 'css_dependencies' in response_2.json():
380+
for css_dependency in response_2.json()['css_dependencies']:
381+
url = css_dependency['css_url']
382+
self.assertTrue('build/' not in url)
383+
latest_commit_hash = response_2.json()['details']['latest_commit_hash']
384+
# Verify that cdn URL is configured correctly
385+
if('cdn.rawgit.com' in url):
386+
self.assertTrue(latest_commit_hash in url)
387+
if 'snippets' in response_2.json():
388+
snippets_list = ['animated-bfs', 'images', 'performance-tuning', 'visual']
389+
for snippet in response_2.json()['snippets']:
390+
latest_commit_hash = response_2.json()['details']['latest_commit_hash']
391+
url = snippet['url']
392+
name = snippet['name']
393+
if('cdn.rawgit.com' in url):
394+
self.assertTrue(latest_commit_hash in url)
395+
self.assertTrue(name in snippets_list)
385396

386-
# mplexviz-ngraph
387-
if 'js_dependencies' in response_3.json():
388-
for js_dependency in response_3.json()['js_dependencies']:
389-
url = js_dependency['js_url']
390-
latest_commit_hash = response_3.json()['details']['latest_commit_hash']
391-
# Verify that cdn URL is configured correctly
392-
if('cdn.rawgit.com' in url):
393-
self.assertTrue(latest_commit_hash in url)
394-
if 'css_dependencies' in response_3.json():
395-
for css_dependency in response_3.json()['css_dependencies']:
396-
url = css_dependency['css_url']
397-
latest_commit_hash = response_3.json()['details']['latest_commit_hash']
398-
# Verify that cdn URL is configured correctly
399-
if('cdn.rawgit.com' in url):
400-
self.assertTrue(latest_commit_hash in url)
401-
if 'snippets' in response_3.json():
402-
snippets_list = ['one', 'two', 'three']
403-
for snippet in response_3.json()['snippets']:
404-
latest_commit_hash = response_3.json()['details']['latest_commit_hash']
405-
url = snippet['url']
406-
name = snippet['name']
407-
if('cdn.rawgit.com' in url):
408-
self.assertTrue(latest_commit_hash in url)
409-
self.assertTrue(name in snippets_list)
397+
# mplexviz-ngraph
398+
if 'js_dependencies' in response_3.json():
399+
for js_dependency in response_3.json()['js_dependencies']:
400+
url = js_dependency['js_url']
401+
latest_commit_hash = response_3.json()['details']['latest_commit_hash']
402+
# Verify that cdn URL is configured correctly
403+
if('cdn.rawgit.com' in url):
404+
self.assertTrue(latest_commit_hash in url)
405+
if 'css_dependencies' in response_3.json():
406+
for css_dependency in response_3.json()['css_dependencies']:
407+
url = css_dependency['css_url']
408+
latest_commit_hash = response_3.json()['details']['latest_commit_hash']
409+
# Verify that cdn URL is configured correctly
410+
if('cdn.rawgit.com' in url):
411+
self.assertTrue(latest_commit_hash in url)
412+
if 'snippets' in response_3.json():
413+
snippets_list = ['one', 'two', 'three']
414+
for snippet in response_3.json()['snippets']:
415+
latest_commit_hash = response_3.json()['details']['latest_commit_hash']
416+
url = snippet['url']
417+
name = snippet['name']
418+
if('cdn.rawgit.com' in url):
419+
self.assertTrue(latest_commit_hash in url)
420+
self.assertTrue(name in snippets_list)

0 commit comments

Comments
 (0)