@@ -114,7 +114,7 @@ def test_response_data(self):
114114 response = self .client .post ('/v1/apps' , json .dumps (body ),
115115 content_type = 'application/json' ,
116116 HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
117- url = "/v1/apps/test/config" . format ()
117+ url = "/v1/apps/test/config"
118118 # set an initial config value
119119 body = {'values' : json .dumps ({'PORT' : '5000' })}
120120 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
@@ -132,6 +132,38 @@ def test_response_data(self):
132132 }
133133 self .assertDictContainsSubset (expected , response .data )
134134
135+ @mock .patch ('requests.post' , mock_import_repository_task )
136+ def test_response_data_types_converted (self ):
137+ """Test that config data is converted into the correct type."""
138+ body = {'id' : 'test' }
139+ response = self .client .post ('/v1/apps' , json .dumps (body ),
140+ content_type = 'application/json' ,
141+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
142+ url = "/v1/apps/test/config"
143+
144+ body = {'values' : json .dumps ({'PORT' : 5000 }), 'cpu' : json .dumps ({'web' : '1024' })}
145+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
146+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
147+ self .assertEqual (response .status_code , 201 )
148+ for key in response .data :
149+ self .assertIn (key , ['uuid' , 'owner' , 'created' , 'updated' , 'app' , 'values' , 'memory' ,
150+ 'cpu' , 'tags' ])
151+ expected = {
152+ 'owner' : self .user .username ,
153+ 'app' : 'test' ,
154+ 'values' : {'PORT' : '5000' },
155+ 'memory' : {},
156+ 'cpu' : {'web' : 1024 },
157+ 'tags' : {}
158+ }
159+ self .assertDictContainsSubset (expected , response .data )
160+
161+ body = {'cpu' : json .dumps ({'web' : 'this will fail' })}
162+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
163+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
164+ self .assertEqual (response .status_code , 400 )
165+ self .assertIn ('CPU shares must be an integer' , response .data ['cpu' ])
166+
135167 @mock .patch ('requests.post' , mock_import_repository_task )
136168 def test_config_set_same_key (self ):
137169 """
@@ -185,7 +217,7 @@ def test_config_set_unicode(self):
185217 HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
186218 self .assertEqual (response .status_code , 201 )
187219 self .assertIn ('INTEGER' , response .data ['values' ])
188- self .assertEqual (response .data ['values' ]['INTEGER' ], 1 )
220+ self .assertEqual (response .data ['values' ]['INTEGER' ], '1' )
189221
190222 @mock .patch ('requests.post' , mock_import_repository_task )
191223 def test_config_str (self ):
@@ -333,7 +365,7 @@ def test_limit_cpu(self):
333365 self .assertIn ('cpu' , response .data )
334366 cpu = response .data ['cpu' ]
335367 self .assertIn ('web' , cpu )
336- self .assertEqual (cpu ['web' ], ' 1024' )
368+ self .assertEqual (cpu ['web' ], 1024 )
337369 # set an additional value
338370 body = {'cpu' : json .dumps ({'worker' : '512' })}
339371 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
@@ -343,19 +375,19 @@ def test_limit_cpu(self):
343375 self .assertNotEqual (limit1 ['uuid' ], limit2 ['uuid' ])
344376 cpu = response .data ['cpu' ]
345377 self .assertIn ('worker' , cpu )
346- self .assertEqual (cpu ['worker' ], ' 512' )
378+ self .assertEqual (cpu ['worker' ], 512 )
347379 self .assertIn ('web' , cpu )
348- self .assertEqual (cpu ['web' ], ' 1024' )
380+ self .assertEqual (cpu ['web' ], 1024 )
349381 # read the limit again
350382 response = self .client .get (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
351383 self .assertEqual (response .status_code , 200 )
352384 limit3 = response .data
353385 self .assertEqual (limit2 , limit3 )
354386 cpu = response .data ['cpu' ]
355387 self .assertIn ('worker' , cpu )
356- self .assertEqual (cpu ['worker' ], ' 512' )
388+ self .assertEqual (cpu ['worker' ], 512 )
357389 self .assertIn ('web' , cpu )
358- self .assertEqual (cpu ['web' ], ' 1024' )
390+ self .assertEqual (cpu ['web' ], 1024 )
359391 # unset a value
360392 body = {'memory' : json .dumps ({'worker' : None })}
361393 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
0 commit comments