Debian Codegraph @

osc_lib/tests/command/test_command.py

raw
1 # Copyright 2016 NEC Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from unittest import mock
16
17 from osc_lib.command import command
18 from osc_lib import exceptions
19 from osc_lib.test import base
20 from osc_lib.test import fakes
21
22
23 class FakeCommand(command.Command):
24 def take_action(self, parsed_args):
25 pass
26
27
28 class TestCommand(base.TestCase):
29 def test_command_has_logger(self):
30 cmd = FakeCommand(mock.Mock(), mock.Mock())
31 self.assertTrue(hasattr(cmd, 'log'))
32 self.assertEqual(
33 'osc_lib.tests.command.test_command.FakeCommand',
34 cmd.log.name,
35 )
36
37 def test_validate_os_beta_command_enabled(self):
38 cmd = FakeCommand(mock.Mock(), mock.Mock())
39 cmd.app = mock.Mock()
40 cmd.app.options = fakes.FakeOptions()
41
42 # No exception is raised when enabled.
43 cmd.app.options.os_beta_command = True
44 cmd.validate_os_beta_command_enabled()
45
46 cmd.app.options.os_beta_command = False
47 self.assertRaises(
48 exceptions.CommandError,
49 cmd.validate_os_beta_command_enabled,
50 )