44
55Run the tests with "./manage.py test api"
66"""
7-
8-
97import json
108
119from django .contrib .auth .models import User
@@ -355,6 +353,17 @@ def test_limit_memory(self, mock_requests):
355353 self .assertNotEqual (limit3 ['uuid' ], limit4 ['uuid' ])
356354 self .assertNotIn ('worker' , json .dumps (response .data ['memory' ]))
357355
356+ # bad memory values
357+ mem = {'web' : '1Z' }
358+ body = {'memory' : json .dumps (mem )}
359+ response = self .client .post (url , body )
360+ self .assertEqual (response .status_code , 400 )
361+
362+ mem = {'w3&b' : '1G' }
363+ body = {'memory' : json .dumps (mem )}
364+ response = self .client .post (url , body )
365+ self .assertEqual (response .status_code , 400 )
366+
358367 # disallow put/patch/delete
359368 response = self .client .put (url )
360369 self .assertEqual (response .status_code , 405 )
@@ -397,14 +406,14 @@ def test_limit_cpu(self, mock_requests):
397406 self .assertEqual (cpu ['web' ], '1024' )
398407
399408 # set an additional value
400- body = {'cpu' : json .dumps ({'worker' : '512 ' })}
409+ body = {'cpu' : json .dumps ({'worker' : '512m ' })}
401410 response = self .client .post (url , body )
402411 self .assertEqual (response .status_code , 201 )
403412 limit2 = response .data
404413 self .assertNotEqual (limit1 ['uuid' ], limit2 ['uuid' ])
405414 cpu = response .data ['cpu' ]
406415 self .assertIn ('worker' , cpu )
407- self .assertEqual (cpu ['worker' ], '512 ' )
416+ self .assertEqual (cpu ['worker' ], '512m ' )
408417 self .assertIn ('web' , cpu )
409418 self .assertEqual (cpu ['web' ], '1024' )
410419
@@ -415,17 +424,28 @@ def test_limit_cpu(self, mock_requests):
415424 self .assertEqual (limit2 , limit3 )
416425 cpu = response .data ['cpu' ]
417426 self .assertIn ('worker' , cpu )
418- self .assertEqual (cpu ['worker' ], '512 ' )
427+ self .assertEqual (cpu ['worker' ], '512m ' )
419428 self .assertIn ('web' , cpu )
420429 self .assertEqual (cpu ['web' ], '1024' )
421430
422431 # unset a value
423- body = {'memory ' : json .dumps ({'worker' : None })}
432+ body = {'cpu ' : json .dumps ({'worker' : None })}
424433 response = self .client .post (url , body )
425434 self .assertEqual (response .status_code , 201 )
426435 limit4 = response .data
427436 self .assertNotEqual (limit3 ['uuid' ], limit4 ['uuid' ])
428- self .assertNotIn ('worker' , json .dumps (response .data ['memory' ]))
437+ self .assertNotIn ('worker' , json .dumps (response .data ['cpu' ]))
438+
439+ # bad cpu values
440+ mem = {'web' : '1G' }
441+ body = {'cpu' : json .dumps (mem )}
442+ response = self .client .post (url , body )
443+ self .assertEqual (response .status_code , 400 )
444+
445+ mem = {'w3&b' : '1G' }
446+ body = {'cpu' : json .dumps (mem )}
447+ response = self .client .post (url , body )
448+ self .assertEqual (response .status_code , 400 )
429449
430450 # disallow put/patch/delete
431451 response = self .client .put (url )
0 commit comments