1
"""Tests for assess_block module."""
6
from mock import Mock, patch, call
8
from assess_block import (
21
class TestParseArgs(TestCase):
23
def test_common_args(self):
24
args = parse_args(["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"])
25
self.assertEqual("an-env", args.env)
26
self.assertEqual("/bin/juju", args.juju_bin)
27
self.assertEqual("/tmp/logs", args.logs)
28
self.assertEqual("an-env-mod", args.temp_env_name)
29
self.assertEqual(False, args.debug)
32
fake_stdout = StringIO.StringIO()
33
with parse_error(self) as fake_stderr:
34
with patch("sys.stdout", fake_stdout):
35
parse_args(["--help"])
36
self.assertEqual("", fake_stderr.getvalue())
37
self.assertNotIn("TODO", fake_stdout.getvalue())
40
class TestMain(TestCase):
43
argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
44
client = Mock(spec=["is_jes_enabled"])
45
with patch("assess_block.configure_logging",
46
autospec=True) as mock_cl:
47
with patch("assess_block.BootstrapManager.booted_context",
48
autospec=True) as mock_bc:
49
with patch("deploy_stack.client_from_config",
50
return_value=client) as mock_c:
51
with patch("assess_block.assess_block",
52
autospec=True) as mock_assess:
54
mock_cl.assert_called_once_with(logging.DEBUG)
55
mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False,
57
self.assertEqual(mock_bc.call_count, 1)
58
mock_assess.assert_called_once_with(client, 'trusty')
61
class TestAssess(TestCase):
64
mock_client = Mock(spec=[
65
"juju", "wait_for_started", "list_disabled_commands",
66
"disable_command", "enable_command",
67
"remove_service", "env", "deploy", "expose",
68
"destroy-model", "remove-machine", "get_status"])
69
mock_client.destroy_model_command = 'destroy-model'
70
mock_client.list_disabled_commands.side_effect = [
72
make_block_list([DisableCommandTypes.destroy_mode]),
74
make_block_list([DisableCommandTypes.remove_object]),
76
make_block_list([DisableCommandTypes.all]),
79
mock_client.env.environment = 'foo'
80
mock_client.version = '1.25'
81
with patch('assess_block.deploy_dummy_stack', autospec=True):
82
with patch('assess_block.wait_for_removed_services',
84
assess_block(mock_client, 'trusty')
85
mock_client.wait_for_started.assert_called_with()
86
self.assertEqual([call('destroy-model',
87
('-y', 'foo'), include_e=False),
89
('-y', 'foo'), include_e=False),
91
('dummy-source/1',), include_e=True),
92
call('remove-relation',
93
('dummy-source', 'dummy-sink'), include_e=True),
94
call('remove-relation',
95
('dummy-source', 'dummy-sink')),
97
('dummy-source', 'dummy-sink'), include_e=True),
99
('dummy-sink',), include_e=True),
100
call('unexpose', ('dummy-sink',)),
101
call('expose', ('dummy-sink',), include_e=True),
102
call('destroy-model',
103
('-y', 'foo'), include_e=False)],
104
mock_client.juju.mock_calls)
105
self.assertEqual([call('destroy-model'),
106
call('remove-object'),
110
mock_client.disable_command.mock_calls)
111
self.assertEqual([call('destroy-model'),
112
call('remove-object'),
116
mock_client.enable_command.mock_calls)
117
self.assertEqual([call('dummy-source'),
119
call('dummy-source'),
122
mock_client.remove_service.mock_calls)