From b7a2a4390b165e4fb86854acd7628adece5baa38 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 11 Jul 2017 15:12:34 +0300 Subject: [PATCH] Add a basic build logs archiver test --- .../test/test_buildlogsarchiver.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 workers/buildlogsarchiver/test/test_buildlogsarchiver.py diff --git a/workers/buildlogsarchiver/test/test_buildlogsarchiver.py b/workers/buildlogsarchiver/test/test_buildlogsarchiver.py new file mode 100644 index 000000000..9f4bdffd3 --- /dev/null +++ b/workers/buildlogsarchiver/test/test_buildlogsarchiver.py @@ -0,0 +1,33 @@ +from mock import patch, Mock + +from app import storage +from data import model +from workers.buildlogsarchiver.buildlogsarchiver import ArchiveBuildLogsWorker + +from test.fixtures import * + +def test_logarchiving(app): + worker = ArchiveBuildLogsWorker() + logs_mock = Mock() + logs_mock.get_log_entries = Mock(return_value=(1, [{'some': 'entry'}])) + + # Add a build that is ready for archiving. + repo = model.repository.get_repository('devtable', 'simple') + access_token = model.token.create_access_token(repo, 'admin') + build = model.build.create_repository_build(repo, access_token, {}, None, 'foo') + build.phase = 'error' + build.save() + + with patch('workers.buildlogsarchiver.buildlogsarchiver.build_logs', logs_mock): + worker._archive_redis_buildlogs() + + # Ensure the get method was called. + logs_mock.get_log_entries.assert_called_once() + logs_mock.expire_status.assert_called_once() + logs_mock.delete_log_entries.assert_called_once() + + # Ensure the build was marked as archived. + assert model.build.get_repository_build(build.uuid).logs_archived + + # Ensure a file was written to storage. + assert storage.exists(['local_us'], 'logarchive/%s' % build.uuid)