@@ -362,3 +362,41 @@ def test_container_command_format(self):
362362 uuid = response .data ['results' ][0 ]['uuid' ]
363363 container = Container .objects .get (uuid = uuid )
364364 self .assertNotIn ('{c_type}' , container ._command )
365+
366+ def test_container_scale_errors (self ):
367+ url = '/api/apps'
368+ body = {'cluster' : 'autotest' }
369+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
370+ self .assertEqual (response .status_code , 201 )
371+ app_id = response .data ['id' ]
372+ # should start with zero
373+ url = "/api/apps/{app_id}/containers" .format (** locals ())
374+ response = self .client .get (url )
375+ self .assertEqual (response .status_code , 200 )
376+ self .assertEqual (len (response .data ['results' ]), 0 )
377+ # post a new build
378+ url = "/api/apps/{app_id}/builds" .format (** locals ())
379+ body = {'image' : 'autotest/example' , 'sha' : 'a' * 40 ,
380+ 'procfile' : json .dumps ({'web' : 'node server.js' , 'worker' : 'node worker.js' })}
381+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
382+ self .assertEqual (response .status_code , 201 )
383+ # scale to a negative number
384+ url = "/api/apps/{app_id}/scale" .format (** locals ())
385+ body = {'web' : - 1 }
386+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
387+ self .assertEqual (response .status_code , 400 )
388+ # scale to something other than a number
389+ url = "/api/apps/{app_id}/scale" .format (** locals ())
390+ body = {'web' : 'one' }
391+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
392+ self .assertEqual (response .status_code , 400 )
393+ # scale to something other than a number
394+ url = "/api/apps/{app_id}/scale" .format (** locals ())
395+ body = {'web' : [1 ]}
396+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
397+ self .assertEqual (response .status_code , 400 )
398+ # scale up to an integer as a sanity check
399+ url = "/api/apps/{app_id}/scale" .format (** locals ())
400+ body = {'web' : 1 }
401+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
402+ self .assertEqual (response .status_code , 204 )
0 commit comments