10
10
import json
11
11
import ast
12
12
from main .management .commands import updatecomponents
13
+ try :
14
+ from biojs .config import *
15
+ except :
16
+ GITHUB_CLIENT_ID = ''
17
+ GITHUB_CLIENT_SECRET = ''
13
18
14
19
class IndexViewTest (TestCase ):
15
20
@@ -192,9 +197,9 @@ def setUpTestData(cls):
192
197
except :
193
198
pass
194
199
try :
195
- github_url = component_data ['links' ]['repository' ]
196
- url_list = github_url .split ('/' )
197
- _component .github_url = 'https://api.github.com/repos/' + str (url_list [3 ]) + '/' + str (url_list [4 ])
200
+ github_url = component_data ['links' ]['repository' ]
201
+ url_list = github_url .split ('/' )
202
+ _component .github_url = 'https://api.github.com/repos/' + str (url_list [3 ]) + '/' + str (url_list [4 ]) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
198
203
except :
199
204
pass
200
205
try :
@@ -208,9 +213,15 @@ def setUpTestData(cls):
208
213
_component .save ()
209
214
210
215
if _component .github_url :
216
+ # print _component.github_url
211
217
response = urllib .urlopen (_component .github_url )
212
218
github_data = json .load (response )
213
- _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
214
225
_component .forks = github_data ['forks' ]
215
226
_component .watchers = github_data ['watchers' ]
216
227
_component .icon_url = github_data ['owner' ]['avatar_url' ]
@@ -230,13 +241,13 @@ def setUpTestData(cls):
230
241
req_date = datetime .strptime (str_date , "%Y-%m-%dT%H:%M:%SZ" )
231
242
aware_date = pytz .utc .localize (req_date )
232
243
_component .github_update_time = aware_date
233
- commits_url = github_data ['commits_url' ].split ('{' )[0 ]
244
+ commits_url = github_data ['commits_url' ].split ('{' )[0 ] + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
234
245
response = urllib .urlopen (commits_url )
235
246
data = json .loads (response .read ())[0 ]
236
247
_component .latest_commit_hash = data ['sha' ]
237
248
_component .save ()
238
249
updatecomponents .update_visualizations (_component , _component .latest_commit_hash , True )
239
- contributors_data = json .load (urllib .urlopen (str (github_data ['contributors_url' ])))
250
+ contributors_data = json .load (urllib .urlopen (str (github_data ['contributors_url' ] + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET )))
240
251
commits = 0
241
252
count = 0
242
253
for contributor in contributors_data :
@@ -252,7 +263,7 @@ def setUpTestData(cls):
252
263
_contribution = Contribution .objects .create (component = _component , contributor = _contributor , contributions = contributor ["contributions" ])
253
264
commits += _contribution .contributions
254
265
count += 1
255
- response = urllib .urlopen (github_data ['downloads_url' ])
266
+ response = urllib .urlopen (github_data ['downloads_url' ] + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET )
256
267
downloads = 0
257
268
data = ast .literal_eval (response .read ())
258
269
for download in data :
@@ -281,6 +292,7 @@ def test_view_accessible_by_name(self):
281
292
# Tests whether the relevant keys are present in the json response and length of response list is same as number of components in database
282
293
def test_relevance_of_response (self ):
283
294
# call for biojs-vis-rohart-msc-test
295
+ current_component = Component .objects .get (url_name = "biojs-vis-rohart-msc-test" )
284
296
response_1 = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'biojs-vis-rohart-msc-test' }))
285
297
self .assertTrue ('details' in response_1 .json ())
286
298
objects = []
@@ -294,110 +306,115 @@ def test_relevance_of_response(self):
294
306
self .assertTrue ('details' in response_3 .json ())
295
307
objects .append (response_3 .json ()['details' ])
296
308
# Test if all the required fields are present in the response
297
- for object in objects :
298
- self .assertTrue (
299
- 'name' in object and
300
- 'tags' in object and
301
- 'stars' in object and
302
- 'downloads' in object and
303
- 'created_time' in object and
304
- 'modified_time' in object and
305
- 'icon_url' in object and
306
- 'github_url' in object and
307
- 'short_description' in object and
308
- 'url_name' in object and
309
- 'commits' in object and
310
- 'forks' in object and
311
- 'watchers' in object and
312
- 'no_of_contributors' in object and
313
- 'open_issues' in object and
314
- 'version' in object and
315
- 'author' in object and
316
- 'license' in object and
317
- 'github_update_time' in object and
318
- 'latest_commit_hash' in object
319
- )
320
- # check if number of commits >= 50 for biojs-vis-rohart-msc-test
321
- # and >= 3757 for cytoscape, from the time the tests were initiated
322
- ### As number of stars, watchers might go down in the future so they haven't been tested
323
- self .assertTrue (int (response_1 .json ()['details' ]['commits' ]) >= 50 )
324
- 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 )
325
338
326
339
# Tests for benchmark component
327
- self .assertTrue (int (response_3 .json ()['details' ]['stars' ]) >= 3 )
328
- 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 )
329
342
330
343
# modified date should be after created date
331
- self .assertTrue (response_1 .json ()['details' ]['created_time' ] <= response_1 .json ()['details' ]['github_update_time' ]) # for biojs-vis-rohart-msc-test
332
- self .assertTrue (response_2 .json ()['details' ]['created_time' ] <= response_2 .json ()['details' ]['github_update_time' ]) # for cytoscape
333
- self .assertTrue (response_3 .json ()['details' ]['created_time' ] <= response_3 .json ()['details' ]['github_update_time' ]) # for mplexviz-ngraph
334
- # check if number of contributors is same as contributors added
335
- self .assertEqual (response_1 .json ()['details' ]['no_of_contributors' ], Contribution .objects .filter (component = Component .objects .get (name = 'biojs-vis-rohart-msc-test' )).count ())
336
- self .assertEqual (response_1 .json ()['details' ]['no_of_contributors' ], len (response_1 .json ()['contributors' ]))
337
- self .assertEqual (response_2 .json ()['details' ]['no_of_contributors' ], Contribution .objects .filter (component = Component .objects .get (name = 'cytoscape' )).count ())
338
- self .assertEqual (response_2 .json ()['details' ]['no_of_contributors' ], len (response_2 .json ()['contributors' ]))
339
- self .assertEqual (response_3 .json ()['details' ]['no_of_contributors' ], Contribution .objects .filter (component = Component .objects .get (name = 'mplexviz-ngraph' )).count ())
340
- self .assertEqual (response_3 .json ()['details' ]['no_of_contributors' ], len (response_3 .json ()['contributors' ]))
341
- for object in response_1 .json ()['contributors' ] + response_2 .json ()['contributors' ] + response_3 .json ()['contributors' ]:
342
- self .assertTrue (
343
- 'contributor' in object and
344
- 'contributions' in object and
345
- 'id' in object
346
- )
347
- contributor_details = object ['contributor' ]
348
- self .assertTrue (
349
- 'username' in contributor_details and
350
- 'avatar_url' in contributor_details
351
- )
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
+ )
352
365
353
- # tests for visualizations
354
- # Test for JS and CSS dependencies as well as snippets names.
355
- # Cytoscape
356
- if 'js_dependencies' in response_2 .json ():
357
- for js_dependency in response_2 .json ()['js_dependencies' ]:
358
- url = js_dependency ['js_url' ]
359
- latest_commit_hash = response_2 .json ()['details' ]['latest_commit_hash' ]
360
- # Verify that cdn URL is configured correctly
361
- if ('cdn.rawgit.com' in url ):
362
- self .assertTrue (latest_commit_hash in url )
363
- if 'css_dependencies' in response_2 .json ():
364
- for css_dependency in response_2 .json ()['css_dependencies' ]:
365
- url = css_dependency ['css_url' ]
366
- latest_commit_hash = response_2 .json ()['details' ]['latest_commit_hash' ]
367
- # Verify that cdn URL is configured correctly
368
- if ('cdn.rawgit.com' in url ):
369
- self .assertTrue (latest_commit_hash in url )
370
- if 'snippets' in response_2 .json ():
371
- snippets_list = ['animated-bfs' , 'images' , 'performance-tuning' , 'visual' ]
372
- for snippet in response_2 .json ()['snippets' ]:
373
- latest_commit_hash = response_2 .json ()['details' ]['latest_commit_hash' ]
374
- url = snippet ['url' ]
375
- name = snippet ['name' ]
376
- if ('cdn.rawgit.com' in url ):
377
- self .assertTrue (latest_commit_hash in url )
378
- 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 )
379
396
380
- # mplexviz-ngraph
381
- if 'js_dependencies' in response_3 .json ():
382
- for js_dependency in response_3 .json ()['js_dependencies' ]:
383
- url = js_dependency ['js_url' ]
384
- latest_commit_hash = response_3 .json ()['details' ]['latest_commit_hash' ]
385
- # Verify that cdn URL is configured correctly
386
- if ('cdn.rawgit.com' in url ):
387
- self .assertTrue (latest_commit_hash in url )
388
- if 'css_dependencies' in response_3 .json ():
389
- for css_dependency in response_3 .json ()['css_dependencies' ]:
390
- url = css_dependency ['css_url' ]
391
- latest_commit_hash = response_3 .json ()['details' ]['latest_commit_hash' ]
392
- # Verify that cdn URL is configured correctly
393
- if ('cdn.rawgit.com' in url ):
394
- self .assertTrue (latest_commit_hash in url )
395
- if 'snippets' in response_3 .json ():
396
- snippets_list = ['one' , 'two' , 'three' ]
397
- for snippet in response_3 .json ()['snippets' ]:
398
- latest_commit_hash = response_3 .json ()['details' ]['latest_commit_hash' ]
399
- url = snippet ['url' ]
400
- name = snippet ['name' ]
401
- if ('cdn.rawgit.com' in url ):
402
- self .assertTrue (latest_commit_hash in url )
403
- 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