summaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/cli/test_cli_base.py
blob: fe065c2aab98666509f9ffaba808e380c614fd15 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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)