@@ -201,6 +201,76 @@ def test_container_single_layer(self):
201201 self .assertEqual (response .status_code , 200 )
202202 self .assertEqual (response .data ['containers' ], json .dumps (body ))
203203
204+ def test_container_multiple_apps (self ):
205+ url = '/api/apps'
206+ body = {'formation' : 'autotest' }
207+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
208+ self .assertEqual (response .status_code , 201 )
209+ app1_id = response .data ['id' ]
210+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
211+ self .assertEqual (response .status_code , 201 )
212+ app2_id = response .data ['id' ]
213+ # scale up
214+ url = "/api/apps/{app1_id}/scale" .format (** locals ())
215+ body = {'web' : 4 , 'worker' : 2 }
216+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
217+ self .assertEqual (response .status_code , 200 )
218+ url = "/api/apps/{app2_id}/scale" .format (** locals ())
219+ body = {'web' : 4 , 'worker' : 2 }
220+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
221+ self .assertEqual (response .status_code , 200 )
222+ url = "/api/apps/{app1_id}/containers" .format (** locals ())
223+ response = self .client .get (url )
224+ self .assertEqual (response .status_code , 200 )
225+ self .assertEqual (len (response .data ['results' ]), 6 )
226+ url = "/api/apps/{app2_id}/containers" .format (** locals ())
227+ response = self .client .get (url )
228+ self .assertEqual (response .status_code , 200 )
229+ self .assertEqual (len (response .data ['results' ]), 6 )
230+ # check port assignments
231+ url = '/api/formations/autotest/calculate'
232+ response = self .client .post (url )
233+ self .assertEqual (response .status_code , 200 )
234+ databag = response .data .copy ()
235+ ports = []
236+ for app in databag ['apps' ].values ():
237+ for containers_set in app ['containers' ].values ():
238+ for node_port in containers_set .values ():
239+ _ , port = node_port .split (':' )
240+ ports .append (int (port ))
241+ ports .sort ()
242+ self .assertEqual (ports , range (10001 , 10013 ))
243+ # scale down
244+ url = "/api/apps/{app1_id}/scale" .format (** locals ())
245+ body = {'web' : 2 , 'worker' : 1 }
246+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
247+ self .assertEqual (response .status_code , 200 )
248+ url = "/api/apps/{app2_id}/scale" .format (** locals ())
249+ body = {'web' : 2 , 'worker' : 1 }
250+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
251+ self .assertEqual (response .status_code , 200 )
252+ url = "/api/apps/{app1_id}/containers" .format (** locals ())
253+ response = self .client .get (url )
254+ self .assertEqual (response .status_code , 200 )
255+ self .assertEqual (len (response .data ['results' ]), 3 )
256+ url = "/api/apps/{app2_id}/containers" .format (** locals ())
257+ response = self .client .get (url )
258+ self .assertEqual (response .status_code , 200 )
259+ self .assertEqual (len (response .data ['results' ]), 3 )
260+ # check port assignments
261+ url = '/api/formations/autotest/calculate'
262+ response = self .client .post (url )
263+ self .assertEqual (response .status_code , 200 )
264+ databag = response .data .copy ()
265+ ports = []
266+ for app in databag ['apps' ].values ():
267+ for containers_set in app ['containers' ].values ():
268+ for node_port in containers_set .values ():
269+ _ , port = node_port .split (':' )
270+ ports .append (int (port ))
271+ ports .sort ()
272+ self .assertEqual (len (set (ports )), 6 )
273+
204274 def test_container_allocation (self ):
205275 url = '/api/apps'
206276 formation_id = 'autotest'
0 commit comments