Repository: incubator-ariatosca Updated Branches: refs/heads/cli-tests cf80675f6 -> f14efbf75
Add tests for logs list Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/f14efbf7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/f14efbf7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/f14efbf7 Branch: refs/heads/cli-tests Commit: f14efbf7527a779a82f73612861981ce3ff51d00 Parents: cf80675 Author: Avia Efrat <[email protected]> Authored: Tue Apr 18 12:28:37 2017 +0300 Committer: Avia Efrat <[email protected]> Committed: Tue Apr 18 12:28:37 2017 +0300 ---------------------------------------------------------------------- aria/cli/commands/logs.py | 2 +- tests/cli/test_logs.py | 23 +++++++++++++++++++++++ tests/cli/utils.py | 10 ++++++++++ tests/mock/models.py | 9 +++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f14efbf7/aria/cli/commands/logs.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py index f8873cd..5382894 100644 --- a/aria/cli/commands/logs.py +++ b/aria/cli/commands/logs.py @@ -42,7 +42,7 @@ def list(execution_id, # TODO: print logs nicely if logs_list: for log in logs_list: - print log + logger.info(log) else: logger.info('\tNo logs') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f14efbf7/tests/cli/test_logs.py ---------------------------------------------------------------------- diff --git a/tests/cli/test_logs.py b/tests/cli/test_logs.py new file mode 100644 index 0000000..ad0c4f1 --- /dev/null +++ b/tests/cli/test_logs.py @@ -0,0 +1,23 @@ +from aria.cli.env import _Environment +from tests.cli.base_test import TestCliBase, mock_storage + + +class TestLogsList(TestCliBase): + + def test_existing_logs(self, monkeypatch, mock_storage): + monkeypatch.setattr(_Environment, 'model_storage', mock_storage) + self.invoke('logs list exec_id') + + assert 'Listing logs for execution id exec_id' in self.logger_output_string + assert 'log_msg' in self.logger_output_string + assert 'No logs' not in self.logger_output_string + + def test_no_logs(self, monkeypatch, mock_object): + m = mock_object + m.log.list.return_value = [] + monkeypatch.setattr(_Environment, 'model_storage', m) + self.invoke('logs list exec_id') + + assert 'Listing logs for execution id exec_id' in self.logger_output_string + assert 'log_msg' not in self.logger_output_string + assert 'No logs' in self.logger_output_string http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f14efbf7/tests/cli/utils.py ---------------------------------------------------------------------- diff --git a/tests/cli/utils.py b/tests/cli/utils.py index 20fdb90..b1537c5 100644 --- a/tests/cli/utils.py +++ b/tests/cli/utils.py @@ -51,6 +51,7 @@ class MockStorage(object): self.service = MockServiceStorage() self.node_template = MockNodeTemplateStorage() self.node = MockNodeStorage() + self.log = MockLogStorage() class MockServiceTemplateStorage(object): @@ -173,3 +174,12 @@ class MockNodeStorage(object): elif id == '2': n.runtime_properties = {'attribute1': 'value1'} return n + + +class MockLogStorage(object): + + def __init__(self): + st = mock_models.create_service_template('test_st') + s = mock_models.create_service(st, 'test_s') + execution = mock_models.create_execution(s) + self.list = MagicMock(return_value=[mock_models.create_log(execution)]) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f14efbf7/tests/mock/models.py ---------------------------------------------------------------------- diff --git a/tests/mock/models.py b/tests/mock/models.py index 38c2b28..0e6bbe4 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -244,6 +244,15 @@ def create_parameter(name, value): return p.wrap(name, value) +def create_log(execution, msg='log_msg', level=0, created_at=datetime.utcnow()): + + return models.Log( + execution=execution, + msg=msg, + level=level, + created_at=created_at) + + def _dictify(item): return dict(((item.name, item),))
