1
"""Tests for assess_TEMPLATE module."""
4
from mock import Mock, patch
7
from assess_TEMPLATE import (
16
from tests.test_jujupy import fake_juju_client
19
class TestParseArgs(TestCase):
21
def test_common_args(self):
22
args = parse_args(["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"])
23
self.assertEqual("an-env", args.env)
24
self.assertEqual("/bin/juju", args.juju_bin)
25
self.assertEqual("/tmp/logs", args.logs)
26
self.assertEqual("an-env-mod", args.temp_env_name)
27
self.assertEqual(False, args.debug)
30
fake_stdout = StringIO.StringIO()
31
with parse_error(self) as fake_stderr:
32
with patch("sys.stdout", fake_stdout):
33
parse_args(["--help"])
34
self.assertEqual("", fake_stderr.getvalue())
35
self.assertNotIn("TODO", fake_stdout.getvalue())
38
class TestMain(TestCase):
41
argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
43
client = Mock(spec=["is_jes_enabled"])
44
with patch("assess_TEMPLATE.configure_logging",
45
autospec=True) as mock_cl:
46
with patch("assess_TEMPLATE.BootstrapManager.booted_context",
47
autospec=True) as mock_bc:
48
with patch('deploy_stack.client_from_config',
49
return_value=client) as mock_c:
50
with patch("assess_TEMPLATE.assess_TEMPLATE",
51
autospec=True) as mock_assess:
53
mock_cl.assert_called_once_with(logging.DEBUG)
54
mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False)
55
self.assertEqual(mock_bc.call_count, 1)
56
mock_assess.assert_called_once_with(client)
59
class TestAssess(TestCase):
61
def test_TEMPLATE(self):
62
# Using fake_client means that deploy and get_status have plausible
63
# results. Wrapping it in a Mock causes every call to be recorded, and
64
# allows assertions to be made about calls. Mocks and the fake client
65
# can also be used separately.
66
fake_client = Mock(wraps=fake_juju_client())
67
fake_client.bootstrap()
68
assess_TEMPLATE(fake_client)
69
fake_client.deploy.assert_called_once_with(
70
'local:trusty/my-charm')
71
fake_client.wait_for_started.assert_called_once_with()
73
1, fake_client.get_status().get_service_unit_count('my-charm'))
74
self.assertNotIn("TODO", self.log_stream.getvalue())