1
"""Tests for assess_mixed_images module."""
10
from assess_mixed_images import (
19
from tests.test_jujupy import FakeJujuClient
22
class TestParseArgs(TestCase):
24
def test_defaults(self):
25
args = parse_args(["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"])
26
self.assertEqual("an-env", args.env)
27
self.assertEqual("/bin/juju", args.juju_bin)
28
self.assertEqual("/tmp/logs", args.logs)
29
self.assertEqual("an-env-mod", args.temp_env_name)
30
self.assertEqual(False, args.debug)
31
self.assertEqual('trusty', args.series)
34
fake_stdout = StringIO.StringIO()
35
with parse_error(self) as fake_stderr:
36
with patch("sys.stdout", fake_stdout):
37
parse_args(["--help"])
38
self.assertEqual("", fake_stderr.getvalue())
41
class TestMain(TestCase):
44
argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
45
client = FakeJujuClient()
46
with patch("assess_mixed_images.configure_logging",
47
autospec=True) as mock_cl:
48
with patch("assess_mixed_images.BootstrapManager.booted_context",
49
autospec=True) as mock_bc:
50
with patch("jujupy.SimpleEnvironment.from_config",
51
return_value=client.env) as mock_e:
52
with patch("jujupy.EnvJujuClient.by_version",
53
return_value=client) as mock_c:
54
with patch("assess_mixed_images.assess_mixed_images",
55
autospec=True) as mock_assess:
57
mock_cl.assert_called_once_with(logging.DEBUG)
58
mock_e.assert_called_once_with("an-env")
59
mock_c.assert_called_once_with(client.env, "/bin/juju", debug=False)
60
self.assertEqual(mock_bc.call_count, 1)
61
mock_assess.assert_called_once_with(client)
64
class TestAssess(TestCase):
66
def test_mixed_images(self):
67
mock_client = FakeJujuClient()
68
assess_mixed_images(mock_client)
71
'0': {'dns-name': '0.example.com'},
72
'1': {'dns-name': '1.example.com'},
77
'relations': {'source': ['dummy-source']},
78
'units': {'dummy-sink/0': {'machine': '0'}}
83
'units': {'dummy-source/0': {'machine': '1'}}
86
}, mock_client.get_status().status)
88
def test_mixed_images_charm_2x(self):
89
mock_client = FakeJujuClient()
90
with patch.object(mock_client, 'deploy') as mock_d:
91
with patch('assess_mixed_images.assess_juju_relations',
92
autospec=True) as mock_ajr:
93
assess_mixed_images(mock_client)
94
calls = [call('dummy-sink'), call('dummy-source')]
95
self.assertEqual(mock_d.mock_calls, calls)
96
mock_ajr.assert_called_once_with(mock_client)
98
def test_mixed_images_charm_1x(self):
99
mock_client = FakeJujuClient(version='1.25.0')
100
with patch.object(mock_client, 'deploy') as mock_d:
101
with patch('assess_mixed_images.assess_juju_relations',
102
autospec=True) as mock_ajr:
103
assess_mixed_images(mock_client)
104
calls = [call('local:centos7/dummy-sink'),
105
call('local:trusty/dummy-source')]
106
self.assertEqual(mock_d.mock_calls, calls)
107
mock_ajr.assert_called_once_with(mock_client)