@@ -253,3 +253,48 @@ def test_unauthorized_user_cannot_modify_build(self):
253253 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
254254 HTTP_AUTHORIZATION = 'token {}' .format (unauthorized_token ))
255255 self .assertEqual (response .status_code , 403 )
256+
257+ @mock .patch ('requests.post' , mock_import_repository_task )
258+ def test_new_build_does_not_scale_up_automatically (self ):
259+ """
260+ After the first initial deploy, if the containers are scaled down to zero,
261+ they should stay that way on a new release.
262+ """
263+ url = '/v1/apps'
264+ response = self .client .post (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
265+ self .assertEqual (response .status_code , 201 )
266+ app_id = response .data ['id' ]
267+ # post a new build
268+ url = "/v1/apps/{app_id}/builds" .format (** locals ())
269+ body = {'image' : 'autotest/example' ,
270+ 'sha' : 'a' * 40 ,
271+ 'procfile' : json .dumps ({'web' : 'node server.js' ,
272+ 'worker' : 'node worker.js' })}
273+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
274+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
275+ self .assertEqual (response .status_code , 201 )
276+ url = "/v1/apps/{app_id}/containers/web" .format (** locals ())
277+ response = self .client .get (url ,
278+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
279+ self .assertEqual (response .status_code , 200 )
280+ self .assertEqual (len (response .data ['results' ]), 1 )
281+ # scale to zero
282+ url = "/v1/apps/{app_id}/scale" .format (** locals ())
283+ body = {'web' : 0 }
284+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
285+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
286+ self .assertEqual (response .status_code , 204 )
287+ # post another build
288+ url = "/v1/apps/{app_id}/builds" .format (** locals ())
289+ body = {'image' : 'autotest/example' ,
290+ 'sha' : 'a' * 40 ,
291+ 'procfile' : json .dumps ({'web' : 'node server.js' ,
292+ 'worker' : 'node worker.js' })}
293+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
294+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
295+ self .assertEqual (response .status_code , 201 )
296+ url = "/v1/apps/{app_id}/containers/web" .format (** locals ())
297+ response = self .client .get (url ,
298+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
299+ self .assertEqual (response .status_code , 200 )
300+ self .assertEqual (len (response .data ['results' ]), 0 )
0 commit comments