1
"""Tests for assess_terms module."""
11
from assess_terms import (
16
from fakejuju import fake_juju_client
23
class TestParseArgs(TestCase):
25
def test_common_args(self):
26
args = parse_args(["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"])
27
self.assertEqual("an-env", args.env)
28
self.assertEqual("/bin/juju", args.juju_bin)
29
self.assertEqual("/tmp/logs", args.logs)
30
self.assertEqual("an-env-mod", args.temp_env_name)
31
self.assertEqual(False, args.debug)
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())
39
self.assertNotIn("TODO", fake_stdout.getvalue())
42
class TestMain(TestCase):
45
argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
47
client = Mock(spec=["is_jes_enabled"])
48
with patch("assess_terms.configure_logging",
49
autospec=True) as mock_cl:
50
with patch("assess_terms.BootstrapManager.booted_context",
51
autospec=True) as mock_bc:
52
with patch('deploy_stack.client_from_config',
53
return_value=client) as mock_cfc:
54
with patch("assess_terms.assess_terms",
55
autospec=True) as mock_assess:
57
mock_cl.assert_called_once_with(logging.DEBUG)
58
mock_cfc.assert_called_once_with('an-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):
67
# Using fake_client means that deploy and get_status have plausible
68
# results. Wrapping it in a Mock causes every call to be recorded, and
69
# allows assertions to be made about calls. Mocks and the fake client
70
# can also be used separately.
71
fake_client = Mock(wraps=fake_juju_client())
72
fake_client.bootstrap()
73
assess_terms(fake_client)
74
fake_client.deploy.assert_called_once_with(
75
'local:trusty/my-charm')
76
fake_client.wait_for_started.assert_called_once_with()
78
1, fake_client.get_status().get_service_unit_count('my-charm'))
79
self.assertNotIn("TODO", self.log_stream.getvalue())