aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/cli/test_cli_base.py
blob: 876e8aa152811ed03c2d92ef9ebfb9b6b54e5654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/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

# pylint: disable=missing-docstring

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):

    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_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_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_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__":
    logging.disable(logging.CRITICAL)
    unittest.main(verbosity=2)