77from __future__ import unicode_literals
88
99import json
10- import mock
11- import requests
1210
1311from django .contrib .auth .models import User
1412from django .test import TransactionTestCase
13+ import mock
1514from rest_framework .authtoken .models import Token
1615
1716from api .models import Build
17+ from . import mock_status_ok
1818
1919
20- def mock_import_repository_task (* args , ** kwargs ):
21- resp = requests .Response ()
22- resp .status_code = 200
23- resp ._content_consumed = True
24- return resp
25-
26-
20+ @mock .patch ('api.models.publish_release' , lambda * args : None )
2721class BuildTest (TransactionTestCase ):
2822
2923 """Tests build notification from build system"""
@@ -34,7 +28,7 @@ def setUp(self):
3428 self .user = User .objects .get (username = 'autotest' )
3529 self .token = Token .objects .get (user = self .user ).key
3630
37- @mock .patch ('requests.post' , mock_import_repository_task )
31+ @mock .patch ('requests.post' , mock_status_ok )
3832 def test_build (self ):
3933 """
4034 Test that a null build is created and that users can post new builds
@@ -82,7 +76,7 @@ def test_build(self):
8276 response = self .client .delete (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
8377 self .assertEqual (response .status_code , 405 )
8478
85- @mock .patch ('requests.post' , mock_import_repository_task )
79+ @mock .patch ('requests.post' , mock_status_ok )
8680 def test_response_data (self ):
8781 """Test that the serialized response contains only relevant data."""
8882 body = {'id' : 'test' }
@@ -108,7 +102,7 @@ def test_response_data(self):
108102 }
109103 self .assertDictContainsSubset (expected , response .data )
110104
111- @mock .patch ('requests.post' , mock_import_repository_task )
105+ @mock .patch ('requests.post' , mock_status_ok )
112106 def test_build_default_containers (self ):
113107 url = '/v1/apps'
114108 response = self .client .post (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
@@ -194,7 +188,7 @@ def test_build_default_containers(self):
194188 self .assertEqual (container ['type' ], 'web' )
195189 self .assertEqual (container ['num' ], 1 )
196190
197- @mock .patch ('requests.post' , mock_import_repository_task )
191+ @mock .patch ('requests.post' , mock_status_ok )
198192 def test_build_str (self ):
199193 """Test the text representation of a build."""
200194 url = '/v1/apps'
@@ -211,7 +205,7 @@ def test_build_str(self):
211205 self .assertEqual (str (build ), "{}-{}" .format (
212206 response .data ['app' ], response .data ['uuid' ][:7 ]))
213207
214- @mock .patch ('requests.post' , mock_import_repository_task )
208+ @mock .patch ('requests.post' , mock_status_ok )
215209 def test_admin_can_create_builds_on_other_apps (self ):
216210 """If a user creates an application, an administrator should be able
217211 to push builds.
@@ -233,7 +227,7 @@ def test_admin_can_create_builds_on_other_apps(self):
233227 self .assertEqual (str (build ), "{}-{}" .format (
234228 response .data ['app' ], response .data ['uuid' ][:7 ]))
235229
236- @mock .patch ('requests.post' , mock_import_repository_task )
230+ @mock .patch ('requests.post' , mock_status_ok )
237231 def test_unauthorized_user_cannot_modify_build (self ):
238232 """
239233 An unauthorized user should not be able to modify other builds.
@@ -254,7 +248,7 @@ def test_unauthorized_user_cannot_modify_build(self):
254248 HTTP_AUTHORIZATION = 'token {}' .format (unauthorized_token ))
255249 self .assertEqual (response .status_code , 403 )
256250
257- @mock .patch ('requests.post' , mock_import_repository_task )
251+ @mock .patch ('requests.post' , mock_status_ok )
258252 def test_new_build_does_not_scale_up_automatically (self ):
259253 """
260254 After the first initial deploy, if the containers are scaled down to zero,
0 commit comments