9
9
import urllib , urllib2
10
10
import json
11
11
import ast
12
+ from main .management .commands import updatecomponents
12
13
13
14
class IndexViewTest (TestCase ):
14
15
@@ -147,6 +148,11 @@ def setUpTestData(cls):
147
148
req = urllib2 .Request ("http://registry.npmjs.com/-/v1/search?text=cytoscape&size=1" , headers = hdr )
148
149
response = urllib2 .urlopen (req )
149
150
data ['objects' ].append (json .load (response )['objects' ][0 ])
151
+ ### BENCHMARK COMPONENT
152
+ hdr = {'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' }
153
+ req = urllib2 .Request ("http://registry.npmjs.com/-/v1/search?text=gmkhsuorlom4n85u&size=1" , headers = hdr )
154
+ response = urllib2 .urlopen (req )
155
+ data ['objects' ].append (json .load (response )['objects' ][0 ])
150
156
for component in data ['objects' ]:
151
157
component_data = component ['package' ]
152
158
_component = Component .objects .create (name = component_data ['name' ])
@@ -220,7 +226,16 @@ def setUpTestData(cls):
220
226
_component .created_time = aware_date
221
227
except :
222
228
pass
229
+ str_date = github_data ['updated_at' ]
230
+ req_date = datetime .strptime (str_date , "%Y-%m-%dT%H:%M:%SZ" )
231
+ aware_date = pytz .utc .localize (req_date )
232
+ _component .github_update_time = aware_date
233
+ commits_url = github_data ['commits_url' ].split ('{' )[0 ]
234
+ response = urllib .urlopen (commits_url )
235
+ data = json .loads (response .read ())[0 ]
236
+ _component .latest_commit_hash = data ['sha' ]
223
237
_component .save ()
238
+ updatecomponents .update_visualizations (_component , _component .latest_commit_hash , True )
224
239
contributors_data = json .load (urllib .urlopen (str (github_data ['contributors_url' ])))
225
240
commits = 0
226
241
count = 0
@@ -252,12 +267,16 @@ def test_view_url_exists_at_desired_location(self):
252
267
self .assertEqual (response .status_code , 200 )
253
268
response = self .client .get ('/details/cytoscape/' )
254
269
self .assertEqual (response .status_code , 200 )
270
+ response = self .client .get ('/details/mplexviz-ngraph/' )
271
+ self .assertEqual (response .status_code , 200 )
255
272
256
273
def test_view_accessible_by_name (self ):
257
274
response = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'biojs-vis-rohart-msc-test' }))
258
275
self .assertEqual (response .status_code , 200 )
259
276
response = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'cytoscape' }))
260
277
self .assertEqual (response .status_code , 200 )
278
+ response = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'mplexviz-ngraph' }))
279
+ self .assertEqual (response .status_code , 200 )
261
280
262
281
# Tests whether the relevant keys are present in the json response and length of response list is same as number of components in database
263
282
def test_relevance_of_response (self ):
@@ -270,6 +289,10 @@ def test_relevance_of_response(self):
270
289
response_2 = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'cytoscape' }))
271
290
self .assertTrue ('details' in response_2 .json ())
272
291
objects .append (response_2 .json ()['details' ])
292
+ # call for mplexviz-ngraph
293
+ response_3 = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'mplexviz-ngraph' }))
294
+ self .assertTrue ('details' in response_3 .json ())
295
+ objects .append (response_3 .json ()['details' ])
273
296
# Test if all the required fields are present in the response
274
297
for object in objects :
275
298
self .assertTrue (
@@ -290,23 +313,32 @@ def test_relevance_of_response(self):
290
313
'open_issues' in object and
291
314
'version' in object and
292
315
'author' in object and
293
- 'license' in object
316
+ 'license' in object and
317
+ 'github_update_time' in object and
318
+ 'latest_commit_hash' in object
294
319
)
295
320
# check if number of commits >= 50 for biojs-vis-rohart-msc-test
296
321
# and >= 3757 for cytoscape, from the time the tests were initiated
297
322
### As number of stars, watchers might go down in the future so they haven't been tested
298
323
self .assertTrue (int (response_1 .json ()['details' ]['commits' ]) >= 50 )
299
324
self .assertTrue (int (response_2 .json ()['details' ]['commits' ]) >= 3757 )
300
325
326
+ # Tests for benchmark component
327
+ self .assertTrue (int (response_3 .json ()['details' ]['stars' ]) >= 3 )
328
+ self .assertTrue (int (response_2 .json ()['details' ]['commits' ]) >= 70 )
329
+
301
330
# modified date should be after created date
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
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
304
334
# check if number of contributors is same as contributors added
305
335
self .assertEqual (response_1 .json ()['details' ]['no_of_contributors' ], Contribution .objects .filter (component = Component .objects .get (name = 'biojs-vis-rohart-msc-test' )).count ())
306
336
self .assertEqual (response_1 .json ()['details' ]['no_of_contributors' ], len (response_1 .json ()['contributors' ]))
307
337
self .assertEqual (response_2 .json ()['details' ]['no_of_contributors' ], Contribution .objects .filter (component = Component .objects .get (name = 'cytoscape' )).count ())
308
338
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' ]:
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' ]:
310
342
self .assertTrue (
311
343
'contributor' in object and
312
344
'contributions' in object and
@@ -317,3 +349,55 @@ def test_relevance_of_response(self):
317
349
'username' in contributor_details and
318
350
'avatar_url' in contributor_details
319
351
)
352
+
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.js' , 'images.js' , 'performance-tuning.js' , 'visual.js' ]
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 )
379
+
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.js' , 'two.js' , 'three.js' ]
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 )
0 commit comments