77from __future__ import unicode_literals
88
99import json
10- import requests
1110
1211from django .contrib .auth .models import User
1312from django .test import TransactionTestCase
1413import mock
1514from rest_framework .authtoken .models import Token
1615
1716from api .models import Build
18-
19-
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
17+ from . import mock_status_ok
2518
2619
2720@mock .patch ('api.models.publish_release' , lambda * args : None )
@@ -35,7 +28,7 @@ def setUp(self):
3528 self .user = User .objects .get (username = 'autotest' )
3629 self .token = Token .objects .get (user = self .user ).key
3730
38- @mock .patch ('requests.post' , mock_import_repository_task )
31+ @mock .patch ('requests.post' , mock_status_ok )
3932 def test_build (self ):
4033 """
4134 Test that a null build is created and that users can post new builds
@@ -83,7 +76,7 @@ def test_build(self):
8376 response = self .client .delete (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
8477 self .assertEqual (response .status_code , 405 )
8578
86- @mock .patch ('requests.post' , mock_import_repository_task )
79+ @mock .patch ('requests.post' , mock_status_ok )
8780 def test_response_data (self ):
8881 """Test that the serialized response contains only relevant data."""
8982 body = {'id' : 'test' }
@@ -109,7 +102,7 @@ def test_response_data(self):
109102 }
110103 self .assertDictContainsSubset (expected , response .data )
111104
112- @mock .patch ('requests.post' , mock_import_repository_task )
105+ @mock .patch ('requests.post' , mock_status_ok )
113106 def test_build_default_containers (self ):
114107 url = '/v1/apps'
115108 response = self .client .post (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
@@ -195,7 +188,7 @@ def test_build_default_containers(self):
195188 self .assertEqual (container ['type' ], 'web' )
196189 self .assertEqual (container ['num' ], 1 )
197190
198- @mock .patch ('requests.post' , mock_import_repository_task )
191+ @mock .patch ('requests.post' , mock_status_ok )
199192 def test_build_str (self ):
200193 """Test the text representation of a build."""
201194 url = '/v1/apps'
@@ -212,7 +205,7 @@ def test_build_str(self):
212205 self .assertEqual (str (build ), "{}-{}" .format (
213206 response .data ['app' ], response .data ['uuid' ][:7 ]))
214207
215- @mock .patch ('requests.post' , mock_import_repository_task )
208+ @mock .patch ('requests.post' , mock_status_ok )
216209 def test_admin_can_create_builds_on_other_apps (self ):
217210 """If a user creates an application, an administrator should be able
218211 to push builds.
@@ -234,7 +227,7 @@ def test_admin_can_create_builds_on_other_apps(self):
234227 self .assertEqual (str (build ), "{}-{}" .format (
235228 response .data ['app' ], response .data ['uuid' ][:7 ]))
236229
237- @mock .patch ('requests.post' , mock_import_repository_task )
230+ @mock .patch ('requests.post' , mock_status_ok )
238231 def test_unauthorized_user_cannot_modify_build (self ):
239232 """
240233 An unauthorized user should not be able to modify other builds.
@@ -255,7 +248,7 @@ def test_unauthorized_user_cannot_modify_build(self):
255248 HTTP_AUTHORIZATION = 'token {}' .format (unauthorized_token ))
256249 self .assertEqual (response .status_code , 403 )
257250
258- @mock .patch ('requests.post' , mock_import_repository_task )
251+ @mock .patch ('requests.post' , mock_status_ok )
259252 def test_new_build_does_not_scale_up_automatically (self ):
260253 """
261254 After the first initial deploy, if the containers are scaled down to zero,
0 commit comments