77
88
99import json
10- import requests
1110
1211from django .contrib .auth .models import User
1312from django .core .cache import cache
1615from rest_framework .authtoken .models import Token
1716
1817from api .models import App , Config
19- from . import mock_status_ok
20-
21-
22- def mock_status_not_found (* args , ** kwargs ):
23- resp = requests .Response ()
24- resp .status_code = 404
25- resp ._content_consumed = True
26- return resp
27-
28-
29- def mock_request_connection_error (* args , ** kwargs ):
30- raise requests .exceptions .ConnectionError ("connection error" )
3118
3219
3320@mock .patch ('api.models.release.publish_release' , lambda * args : None )
@@ -49,7 +36,6 @@ def tearDown(self):
4936 # make sure every test has a clean slate for k8s mocking
5037 cache .clear ()
5138
52- @mock .patch ('requests.post' , mock_status_ok )
5339 def test_config (self ):
5440 """
5541 Test that config is auto-created for a new app and that
@@ -121,7 +107,6 @@ def test_config(self):
121107 self .assertEqual (response .status_code , 405 )
122108 return config5
123109
124- @mock .patch ('requests.post' , mock_status_ok )
125110 def test_response_data (self ):
126111 """Test that the serialized response contains only relevant data."""
127112 body = {'id' : 'test' }
@@ -146,7 +131,6 @@ def test_response_data(self):
146131 }
147132 self .assertDictContainsSubset (expected , response .data )
148133
149- @mock .patch ('requests.post' , mock_status_ok )
150134 def test_response_data_types_converted (self ):
151135 """Test that config data is converted into the correct type."""
152136 body = {'id' : 'test' }
@@ -178,7 +162,6 @@ def test_response_data_types_converted(self):
178162 self .assertEqual (response .status_code , 400 )
179163 self .assertIn ('CPU shares must be a numeric value' , response .data ['cpu' ])
180164
181- @mock .patch ('requests.post' , mock_status_ok )
182165 def test_config_set_same_key (self ):
183166 """
184167 Test that config sets on the same key function properly
@@ -202,7 +185,6 @@ def test_config_set_same_key(self):
202185 self .assertIn ('PORT' , response .data ['values' ])
203186 self .assertEqual (response .data ['values' ]['PORT' ], '5001' )
204187
205- @mock .patch ('requests.post' , mock_status_ok )
206188 def test_config_set_unicode (self ):
207189 """
208190 Test that config sets with unicode values are accepted.
@@ -233,14 +215,12 @@ def test_config_set_unicode(self):
233215 self .assertIn ('INTEGER' , response .data ['values' ])
234216 self .assertEqual (response .data ['values' ]['INTEGER' ], '1' )
235217
236- @mock .patch ('requests.post' , mock_status_ok )
237218 def test_config_str (self ):
238219 """Test the text representation of a node."""
239220 config5 = self .test_config ()
240221 config = Config .objects .get (uuid = config5 ['uuid' ])
241222 self .assertEqual (str (config ), "{}-{}" .format (config5 ['app' ], str (config5 ['uuid' ])[:7 ]))
242223
243- @mock .patch ('requests.post' , mock_status_ok )
244224 def test_valid_config_keys (self ):
245225 """Test that valid config keys are accepted.
246226 """
@@ -258,7 +238,6 @@ def test_valid_config_keys(self):
258238 self .assertEqual (resp .status_code , 201 )
259239 self .assertIn (k , resp .data ['values' ])
260240
261- @mock .patch ('requests.post' , mock_status_ok )
262241 def test_invalid_config_keys (self ):
263242 """Test that invalid config keys are rejected.
264243 """
@@ -275,7 +254,6 @@ def test_invalid_config_keys(self):
275254 HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
276255 self .assertEqual (resp .status_code , 400 )
277256
278- @mock .patch ('requests.post' , mock_status_ok )
279257 def test_admin_can_create_config_on_other_apps (self ):
280258 """If a non-admin creates an app, an administrator should be able to set config
281259 values for that app.
@@ -295,7 +273,6 @@ def test_admin_can_create_config_on_other_apps(self):
295273 self .assertIn ('PORT' , response .data ['values' ])
296274 return response
297275
298- @mock .patch ('requests.post' , mock_status_ok )
299276 def test_limit_memory (self ):
300277 """
301278 Test that limit is auto-created for a new app and that
@@ -383,7 +360,6 @@ def test_limit_memory(self):
383360 self .assertEqual (response .status_code , 405 )
384361 return limit4
385362
386- @mock .patch ('requests.post' , mock_status_ok )
387363 def test_limit_cpu (self ):
388364 """
389365 Test that CPU limits can be set
@@ -454,7 +430,6 @@ def test_limit_cpu(self):
454430 self .assertEqual (response .status_code , 405 )
455431 return limit4
456432
457- @mock .patch ('requests.post' , mock_status_ok )
458433 def test_tags (self ):
459434 """
460435 Test that tags can be set on an application
0 commit comments