test(endpoints/web): test buildlogs endpoint

This commit is contained in:
EvB 2017-04-26 18:16:26 -04:00
parent 51ff7cab20
commit b216290e31

View file

@ -140,6 +140,32 @@ class EndpointTestCase(unittest.TestCase):
class BuildLogsTestCase(EndpointTestCase):
build_uuid = 'deadpork-dead-pork-dead-porkdeadpork'
def test_buildlogs_invalid_build_uuid(self):
self.login('public', 'password')
self.getResponse('web.buildlogs', build_uuid='bad_build_uuid', expected_code=400)
def test_buildlogs_not_logged_in(self):
self.getResponse('web.buildlogs', build_uuid=self.build_uuid, expected_code=401)
def test_buildlogs_unauthorized(self):
self.login('reader', 'password')
self.getResponse('web.buildlogs', build_uuid=self.build_uuid, expected_code=403)
def test_buildlogs_logsarchived(self):
self.login('public', 'password')
with patch('data.model.build.RepositoryBuild', logs_archived=True):
self.getResponse('web.buildlogs', build_uuid=self.build_uuid, expected_code=403)
def test_buildlogs_successful(self):
self.login('public', 'password')
logs = ['log1', 'log2']
with patch('endpoints.web.build_logs.get_log_entries', return_value=(None, logs) ):
resp = self.getResponse('web.buildlogs', build_uuid=self.build_uuid, expected_code=200)
self.assertEquals('{"logs":["log1","log2"]}\n', resp)
class ArchivedLogsTestCase(EndpointTestCase):
build_uuid = 'deadpork-dead-pork-dead-porkdeadpork'
def test_logarchive_invalid_build_uuid(self):
self.login('public', 'password')
self.getResponse('web.logarchive', file_id='bad_build_uuid', expected_code=403)