@@ -138,10 +138,15 @@ class DetailComponentViewTest(TestCase):
138
138
def setUpTestData (cls ):
139
139
# Called initially when test is executed, create objects to be used by test methods
140
140
# create a random object
141
+ # Add a benchmark component
141
142
hdr = {'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' }
142
143
req = urllib2 .Request ("http://registry.npmjs.com/-/v1/search?text=biojs-vis-rohart-msc-test" , headers = hdr )
143
144
response = urllib2 .urlopen (req )
144
145
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 ])
145
150
for component in data ['objects' ]:
146
151
component_data = component ['package' ]
147
152
_component = Component .objects .create (name = component_data ['name' ])
@@ -245,47 +250,63 @@ def setUpTestData(cls):
245
250
def test_view_url_exists_at_desired_location (self ):
246
251
response = self .client .get ('/details/biojs-vis-rohart-msc-test/' )
247
252
self .assertEqual (response .status_code , 200 )
253
+ response = self .client .get ('/details/cytoscape/' )
254
+ self .assertEqual (response .status_code , 200 )
248
255
249
256
def test_view_accessible_by_name (self ):
250
257
response = self .client .get (reverse ('main:component_details' , kwargs = {'url_name' :'biojs-vis-rohart-msc-test' }))
251
258
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 )
252
261
253
262
# Tests whether the relevant keys are present in the json response and length of response list is same as number of components in database
254
263
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' ])
257
273
# 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
280
297
### 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 )
282
300
283
301
# 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
285
304
# 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' ]:
289
310
self .assertTrue (
290
311
'contributor' in object and
291
312
'contributions' in object and
0 commit comments