ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/3] incubator-ariatosca git commit: Add tests for logs list
Date Wed, 19 Apr 2017 12:36:21 GMT
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/da42f99d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/da42f99d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/da42f99d

Branch: refs/heads/ARIA-48-aria-cli
Commit: da42f99d4a32fa57feeefd34a721512771dc9fe8
Parents: 82591f0
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Tue Apr 18 12:28:37 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Wed Apr 19 15:35:17 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/da42f99d/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 8888fef..6c83347 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/da42f99d/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/da42f99d/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/da42f99d/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 8a9273b..328453a 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -245,6 +245,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),))
 


Mime
View raw message