aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/cli/test_cli_base.py
diff options
context:
space:
mode:
authorashishk1994 <ashishk.iiit@gmail.com>2016-12-17 23:45:31 +0530
committerAshish Kumar <ashishk.iiit@gmail.com>2017-01-04 09:05:06 +0000
commit3f7c5e340178ce9e4183dd023ef5d1b04f72baad (patch)
treeb946877e1680f6fe323f2a7e09e7f60fbc3d66af /functest/tests/unit/cli/test_cli_base.py
parentd1816afb6ff28313347f656b6145dd1fb22c5a68 (diff)
Added Unit Tests for cli.
JIRA: FUNCTEST-590 Change-Id: I5e28145cae742598927e8edbe65091fedb533a4d Signed-off-by: ashishk1994 <ashishk.iiit@gmail.com>
Diffstat (limited to 'functest/tests/unit/cli/test_cli_base.py')
-rw-r--r--functest/tests/unit/cli/test_cli_base.py138
1 files changed, 138 insertions, 0 deletions
diff --git a/functest/tests/unit/cli/test_cli_base.py b/functest/tests/unit/cli/test_cli_base.py
new file mode 100644
index 00000000..fe065c2a
--- /dev/null
+++ b/functest/tests/unit/cli/test_cli_base.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016 Orange 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 logging
+import unittest
+
+import mock
+from click.testing import CliRunner
+
+with mock.patch('functest.cli.commands.cli_testcase.CliTestcase.__init__',
+ mock.Mock(return_value=None)), \
+ mock.patch('functest.cli.commands.cli_tier.CliTier.__init__',
+ mock.Mock(return_value=None)):
+ from functest.cli import cli_base
+
+
+class CliBaseTesting(unittest.TestCase):
+
+ logging.disable(logging.CRITICAL)
+
+ def setUp(self):
+ self.runner = CliRunner()
+ self._openstack = cli_base._openstack
+ self._env = cli_base._env
+ self._testcase = cli_base._testcase
+ self._tier = cli_base._tier
+
+ def test_os_check(self):
+ with mock.patch.object(self._openstack, 'check') as mock_method:
+ result = self.runner.invoke(cli_base.os_check)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_os_snapshot_create(self):
+ with mock.patch.object(self._openstack, 'snapshot_create') \
+ as mock_method:
+ result = self.runner.invoke(cli_base.os_snapshot_create)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_os_snapshot_show(self):
+ with mock.patch.object(self._openstack, 'snapshot_show') \
+ as mock_method:
+ result = self.runner.invoke(cli_base.os_snapshot_show)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_os_clean(self):
+ with mock.patch.object(self._openstack, 'clean') as mock_method:
+ result = self.runner.invoke(cli_base.os_clean)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_os_show_credentials(self):
+ with mock.patch.object(self._openstack, 'show_credentials') \
+ as mock_method:
+ result = self.runner.invoke(cli_base.os_show_credentials)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_os_fetch_rc(self):
+ with mock.patch.object(self._openstack, 'fetch_credentials') \
+ as mock_method:
+ result = self.runner.invoke(cli_base.os_fetch_rc)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_env_prepare(self):
+ with mock.patch.object(self._env, 'prepare') as mock_method:
+ result = self.runner.invoke(cli_base.env_prepare)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_env_show(self):
+ with mock.patch.object(self._env, 'show') as mock_method:
+ result = self.runner.invoke(cli_base.env_show)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_env_status(self):
+ with mock.patch.object(self._env, 'status') as mock_method:
+ result = self.runner.invoke(cli_base.env_status)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_testcase_list(self):
+ with mock.patch.object(self._testcase, 'list') as mock_method:
+ result = self.runner.invoke(cli_base.testcase_list)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_testcase_show(self):
+ with mock.patch.object(self._testcase, 'show') as mock_method:
+ result = self.runner.invoke(cli_base.testcase_show, ['testname'])
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_testcase_run(self):
+ with mock.patch.object(self._testcase, 'run') as mock_method:
+ result = self.runner.invoke(cli_base.testcase_run,
+ ['testname', '--noclean'])
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_tier_list(self):
+ with mock.patch.object(self._tier, 'list') as mock_method:
+ result = self.runner.invoke(cli_base.tier_list)
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_tier_show(self):
+ with mock.patch.object(self._tier, 'show') as mock_method:
+ result = self.runner.invoke(cli_base.tier_show, ['tiername'])
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_tier_gettests(self):
+ with mock.patch.object(self._tier, 'gettests') as mock_method:
+ result = self.runner.invoke(cli_base.tier_gettests, ['tiername'])
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+ def test_tier_run(self):
+ with mock.patch.object(self._tier, 'run') as mock_method:
+ result = self.runner.invoke(cli_base.tier_run,
+ ['tiername', '--noclean'])
+ self.assertEqual(result.exit_code, 0)
+ self.assertTrue(mock_method.called)
+
+
+if __name__ == "__main__":
+ unittest.main(verbosity=2)