77from __future__ import unicode_literals
88
99import json
10+ import logging
1011import mock
1112import os .path
1213import requests
@@ -131,22 +132,18 @@ def test_app_actions(self):
131132 os .remove (path )
132133 # TODO: test run needs an initial build
133134
134- def test_app_release_notes_in_logs (self ):
135+ @mock .patch ('api.models.logger' )
136+ def test_app_release_notes_in_logs (self , mock_logger ):
135137 """Verifies that an app's release summary is dumped into the logs."""
136138 url = '/v1/apps'
137139 body = {'id' : 'autotest' }
138140 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
139141 HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
140142 self .assertEqual (response .status_code , 201 )
141- app_id = response .data ['id' ] # noqa
142- path = os .path .join (settings .DEIS_LOG_DIR , app_id + '.log' )
143- url = '/v1/apps/{app_id}/logs' .format (** locals ())
144- response = self .client .get (url ,
145- HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
146- self .assertIn ('autotest created initial release' , response .data )
147- self .assertEqual (response .status_code , 200 )
148- # delete file for future runs
149- os .remove (path )
143+ # check app logs
144+ exp_msg = "autotest created initial release"
145+ exp_log_call = mock .call (logging .INFO , exp_msg )
146+ mock_logger .log .has_calls (exp_log_call )
150147
151148 def test_app_errors (self ):
152149 app_id = 'autotest-errors'
@@ -202,7 +199,8 @@ def test_app_structure_is_valid_json(self):
202199 self .assertEqual (response .data ['structure' ], {"web" : 1 })
203200
204201 @mock .patch ('requests.post' , mock_import_repository_task )
205- def test_admin_can_manage_other_apps (self ):
202+ @mock .patch ('api.models.logger' )
203+ def test_admin_can_manage_other_apps (self , mock_logger ):
206204 """Administrators of Deis should be able to manage all applications.
207205 """
208206 # log in as non-admin user and create an app
@@ -213,18 +211,15 @@ def test_admin_can_manage_other_apps(self):
213211 body = {'id' : app_id }
214212 response = self .client .post (url , json .dumps (body ), content_type = 'application/json' ,
215213 HTTP_AUTHORIZATION = 'token {}' .format (token ))
216- app = App .objects .get (id = app_id )
217214 # log in as admin, check to see if they have access
218215 url = '/v1/apps/{}' .format (app_id )
219216 response = self .client .get (url ,
220217 HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
221218 self .assertEqual (response .status_code , 200 )
222219 # check app logs
223- url = '/v1/apps/{app_id}/logs' .format (** locals ())
224- response = self .client .get (url ,
225- HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
226- self .assertEqual (response .status_code , 200 )
227- self .assertIn ('autotest2 created initial release' , response .data )
220+ exp_msg = "autotest2 created initial release"
221+ exp_log_call = mock .call (logging .INFO , exp_msg )
222+ mock_logger .log .has_calls (exp_log_call )
228223 # TODO: test run needs an initial build
229224 # delete the app
230225 url = '/v1/apps/{}' .format (app_id )
0 commit comments