77from __future__ import unicode_literals
88
99import json
10+ import mock
11+ import requests
1012
1113from django .test import TransactionTestCase
1214from django .test .utils import override_settings
1315
1416from api .models import Release
1517
1618
19+ def mock_import_repository_task (* args , ** kwargs ):
20+ resp = requests .Response ()
21+ resp .status_code = 200
22+ resp ._content_consumed = True
23+ return resp
24+
25+
1726@override_settings (CELERY_ALWAYS_EAGER = True )
1827class ReleaseTest (TransactionTestCase ):
1928
@@ -30,6 +39,7 @@ def setUp(self):
3039 content_type = 'application/json' )
3140 self .assertEqual (response .status_code , 201 )
3241
42+ @mock .patch ('requests.post' , mock_import_repository_task )
3343 def test_release (self ):
3444 """
3545 Test that a release is created when a cluster is created, and
@@ -101,6 +111,7 @@ def test_release(self):
101111 self .assertEqual (self .client .delete (url ).status_code , 405 )
102112 return release3
103113
114+ @mock .patch ('requests.post' , mock_import_repository_task )
104115 def test_release_rollback (self ):
105116 url = '/api/apps'
106117 body = {'cluster' : 'autotest' }
@@ -187,12 +198,14 @@ def test_release_rollback(self):
187198 self .assertIn ('NEW_URL1' , values )
188199 self .assertEqual ('http://localhost:8080/' , values ['NEW_URL1' ])
189200
201+ @mock .patch ('requests.post' , mock_import_repository_task )
190202 def test_release_str (self ):
191203 """Test the text representation of a release."""
192204 release3 = self .test_release ()
193205 release = Release .objects .get (uuid = release3 ['uuid' ])
194206 self .assertEqual (str (release ), "{}-v3" .format (release3 ['app' ]))
195207
208+ @mock .patch ('requests.post' , mock_import_repository_task )
196209 def test_release_summary (self ):
197210 """Test the text summary of a release."""
198211 release3 = self .test_release ()
0 commit comments