summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/reporter/timeline.pickle3
-rw-r--r--tests/unit/cli/cmd_report.py23
-rw-r--r--tests/unit/cli/options_test.py9
-rw-r--r--tests/unit/reporter/console_test.py22
-rw-r--r--tests/unit/util/env_test.py94
-rw-r--r--tests/unit/util/logger_test.py9
6 files changed, 150 insertions, 10 deletions
diff --git a/tests/data/reporter/timeline.pickle b/tests/data/reporter/timeline.pickle
new file mode 100644
index 00000000..5c870d93
--- /dev/null
+++ b/tests/data/reporter/timeline.pickle
@@ -0,0 +1,3 @@
+VTimeline\u000a\u000aMONITOR TIME\u000a\u000aT00 1\u000a\u000a\u000aINSPECTOR TIME\u000a\u000aT01 2\u000a\u000aT02 5\u000a\u000aT03 8\u000a\u000a\u000aCONTROLLER TIME\u000a\u000aT04 11\u000a\u000a\u000aNOTIFIER TIME\u000a\u000aT05 16\u000a\u000a\u000aEVALUATOR TIME\u000a\u000aT06 40\u000a\u000a\u000aTotal: 312ms
+p0
+.
diff --git a/tests/unit/cli/cmd_report.py b/tests/unit/cli/cmd_report.py
new file mode 100644
index 00000000..e010b960
--- /dev/null
+++ b/tests/unit/cli/cmd_report.py
@@ -0,0 +1,23 @@
+###############################################################
+# Copyright (c) 2016 ZTE Corp and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import pytest
+from click.testing import CliRunner
+
+from qtip.cli.entry import cli
+
+
+@pytest.fixture(scope="module")
+def runner():
+ return CliRunner()
+
+
+def test_show(runner):
+ result = runner.invoke(cli, ['report', 'show'])
+ assert result.output == ''
diff --git a/tests/unit/cli/options_test.py b/tests/unit/cli/options_test.py
index f9472814..9dbbe6f3 100644
--- a/tests/unit/cli/options_test.py
+++ b/tests/unit/cli/options_test.py
@@ -1,5 +1,5 @@
###############################################################
-# Copyright (c) 2016 ZTE Corp and others.
+# Copyright (c) 2017 taseer94@gmail.com and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -8,8 +8,9 @@
##############################################################################
import pytest
-from click.testing import CliRunner
+import sys
+from click.testing import CliRunner
from qtip.cli.entry import cli
@@ -28,5 +29,5 @@ class TestClass(object):
assert 'dev' in result.output
def test_debug(self, runner):
- result = runner.invoke(cli, ['-d'])
- assert '' in result.output
+ runner.invoke(cli, ['-d'])
+ assert sys.tracebacklimit == 8
diff --git a/tests/unit/reporter/console_test.py b/tests/unit/reporter/console_test.py
index 8150239e..d2816690 100644
--- a/tests/unit/reporter/console_test.py
+++ b/tests/unit/reporter/console_test.py
@@ -7,7 +7,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import pickle
import pytest
+import os
+
from qtip.reporter.console import ConsoleReporter
@@ -21,9 +24,16 @@ def test_constructor(console_reporter):
def test_render(console_reporter):
- var_dict = {
- 'title': 'fake title',
- 'description': 'fake description'
- }
- output = console_reporter.render(var_dict=var_dict)
- assert output == 'fake title: fake description'
+ var_dict = {'title': 'Timeline', 'total': '312ms', 'phases': [{'name': 'Monitor ',
+ 'checkpoints': [{'name': 'T00 ', 'timestamp': '1'}]},
+ {'name': 'Inspector ', 'checkpoints': [{'name': 'T01 ', 'timestamp': '2'},
+ {'name': 'T02 ', 'timestamp': '5'}, {'name': 'T03 ', 'timestamp': '8'}]},
+ {'name': 'Controller ', 'checkpoints': [{'name': 'T04 ', 'timestamp': '11'}]},
+ {'name': 'Notifier ', 'checkpoints': [{'name': 'T05 ', 'timestamp': '16'}]},
+ {'name': 'Evaluator ', 'checkpoints': [{'name': 'T06 ', 'timestamp': '40'}]}]}
+
+ result = console_reporter.render(var_dict=var_dict)
+ path = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
+ os.pardir, 'tests/data/reporter/')
+ timeline = pickle.load(open(path + 'timeline.pickle', 'rb'))
+ assert result == timeline
diff --git a/tests/unit/util/env_test.py b/tests/unit/util/env_test.py
new file mode 100644
index 00000000..38ac988b
--- /dev/null
+++ b/tests/unit/util/env_test.py
@@ -0,0 +1,94 @@
+###############################################################
+# Copyright (c) 2017 ZTE Corporation
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import time
+
+import mock
+import pytest
+
+from qtip.util import env
+
+
+def test_all_files_exist(tmpdir):
+ exist_file = tmpdir.mkdir('qtip').join('hello.txt')
+ exist_file.write("hello")
+ non_exist_file = tmpdir.strpath + '/tmp.txt'
+ assert env.all_files_exist() is False
+ assert env.all_files_exist(str(exist_file))
+ assert env.all_files_exist(non_exist_file) is False
+ assert env.all_files_exist(str(exist_file), non_exist_file) is False
+
+
+def test_clean_file(tmpdir):
+ exist_file = tmpdir.mkdir('qtip').join('hello.txt')
+ exist_file.write("hello")
+ non_exist_file = tmpdir.strpath + '/tmp.txt'
+
+ assert env.clean_file() is False
+ assert env.clean_file(str(exist_file))
+ assert env.clean_file(non_exist_file)
+
+
+def test_generate_host_file_without_setenv(monkeypatch):
+ def setenv(*args):
+ monkeypatch.setenv('INSTALLER_TYPE', args[0])
+ monkeypatch.setenv('INSTALLER_IP', args[1])
+
+ with pytest.raises(KeyError) as excinfo:
+ env.generate_host_file()
+ assert 'INSTALLER_TYPE' in str(excinfo.value)
+
+ with pytest.raises(ValueError) as excinfo:
+ setenv('fuel_1', '10.20.0.2')
+ env.generate_host_file()
+ assert 'fuel_1 is not supported' in str(excinfo.value)
+
+ with pytest.raises(ValueError) as excinfo:
+ setenv('fuel', '')
+ env.generate_host_file()
+ assert 'The value of environment variable INSTALLER_IP is empty' \
+ in str(excinfo.value)
+
+
+def test_generate_host_file(monkeypatch, tmpdir):
+ monkeypatch.setenv('INSTALLER_TYPE', 'fuel')
+ monkeypatch.setenv('INSTALLER_IP', '10.20.0.2')
+ hostfile = tmpdir.mkdir('qtip').join('hosts')
+ hostfile.write('')
+ assert env.generate_host_file(str(hostfile))
+
+
+def test_generate_keypair():
+ with mock.patch('os.system') as mock_os:
+ env.generate_keypair()
+ assert mock_os.call_count == 1
+
+
+def test_pass_keypair(monkeypatch):
+ monkeypatch.setattr(time, 'sleep', lambda s: None)
+ with mock.patch('os.system') as mock_os:
+ env.pass_keypair('10.20.0.10')
+ assert mock_os.call_count == 2
+
+
+@pytest.mark.parametrize("stderrinfo, expected", [
+ ('', True),
+ ('sorry', False)
+])
+@mock.patch('paramiko.SSHClient')
+def test_ssh_is_ok(mock_sshclient, stderrinfo, expected):
+ stderr = mock.MagicMock()
+ stderr.readlines.return_value = stderrinfo
+ test_ssh_client = mock_sshclient.return_value
+ test_ssh_client.exec_command.return_value = ('', '', stderr)
+ result = env.ssh_is_ok('10.20.0.3')
+ assert result == expected
+ test_ssh_client.connect.assert_called_once_with(
+ '10.20.0.3', key_filename=env.PRIVATE_KEY)
+ test_ssh_client.exec_command.assert_called_with('uname')
diff --git a/tests/unit/util/logger_test.py b/tests/unit/util/logger_test.py
index 339b2bf6..78c4c109 100644
--- a/tests/unit/util/logger_test.py
+++ b/tests/unit/util/logger_test.py
@@ -1,3 +1,12 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Corporation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
import pytest
from qtip.util import logger