1
"""Tests for assess_cs_staging module."""
4
from mock import Mock, patch
7
from assess_cs_staging import (
18
from tests.test_jujupy import (
20
fake_juju_client_optional_jes,
24
class TestParseArgs(TestCase):
26
def test_common_args(self):
27
args = parse_args(["an-ip", "an-env", "/bin/juju", "/tmp/logs",
29
self.assertEqual("an-ip", args.charm_store_ip)
30
self.assertEqual("an-env", args.env)
31
self.assertEqual("/bin/juju", args.juju_bin)
32
self.assertEqual("/tmp/logs", args.logs)
33
self.assertEqual("an-env-mod", args.temp_env_name)
34
self.assertEqual(False, args.debug)
35
self.assertEqual("ubuntu", args.charm)
38
fake_stdout = StringIO.StringIO()
39
with parse_error(self) as fake_stderr:
40
with patch("sys.stdout", fake_stdout):
41
parse_args(["--help"])
42
self.assertEqual("", fake_stderr.getvalue())
45
class TestSetCharmStoreIP(TestCase):
47
def test_default_as_controller(self):
48
client = fake_juju_client_optional_jes(jes_enabled=False)
50
with patch.object(client, 'juju', autospec=True) as juju_mock:
51
_set_charm_store_ip(client, '1.2.3.4')
52
juju_mock.assert_called_once_with(
53
'ssh', ('0', _get_ssh_script('1.2.3.4')))
55
def test_separate_controller(self):
56
client = fake_juju_client()
58
controller_client = client.get_controller_client()
59
# Force get_controller_client to return the *same* client, instead of
61
with patch.object(client, 'get_controller_client',
62
return_value=controller_client, autospec=True):
63
with patch.object(controller_client, 'juju',
64
autospec=True) as juju_mock:
65
_set_charm_store_ip(client, '1.2.3.4')
66
juju_mock.assert_called_once_with(
67
'ssh', ('0', _get_ssh_script('1.2.3.4')))
70
class TestMain(TestCase):
73
argv = ["an-ip", "an-env", "/bin/juju", "/tmp/logs", "an-env-mod",
75
client = Mock(spec=["is_jes_enabled", "juju"])
76
with patch("assess_cs_staging.configure_logging",
77
autospec=True) as mock_cl:
78
with patch("assess_cs_staging.BootstrapManager.booted_context",
79
autospec=True) as mock_bc:
80
with patch("deploy_stack.client_from_config",
81
return_value=client) as mock_c:
82
with patch("assess_cs_staging._set_charm_store_ip",
83
autospec=True) as mock_set_ip:
84
with patch("assess_cs_staging.assess_deploy",
85
autospec=True) as mock_assess:
87
mock_cl.assert_called_once_with(logging.DEBUG)
88
mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False)
89
self.assertEqual(mock_bc.call_count, 1)
90
mock_set_ip.assert_called_once_with(client, 'an-ip')
91
mock_assess.assert_called_once_with(client, 'ubuntu')
94
class TestAssess(TestCase):
96
def test_cs_staging_deploy(self):
97
mock_client = Mock(spec=["deploy", "juju", "wait_for_started"])
98
assess_deploy(mock_client, "charm")
99
mock_client.deploy.assert_called_once_with('charm')
100
mock_client.wait_for_started.assert_called_once_with()