1183.2.3
by Martin Packman
Add missing template test file |
1 |
"""Tests for assess_TEMPLATE module."""
|
2 |
||
3 |
import logging
|
|
4 |
from mock import Mock, patch
|
|
5 |
import StringIO
|
|
6 |
||
7 |
from assess_TEMPLATE import (
|
|
8 |
assess_TEMPLATE,
|
|
9 |
parse_args,
|
|
10 |
main,
|
|
11 |
)
|
|
12 |
from tests import (
|
|
13 |
parse_error,
|
|
14 |
TestCase,
|
|
15 |
)
|
|
1434.1.1
by Aaron Bentley
Update templates to current best practises. |
16 |
from tests.test_jujupy import fake_juju_client
|
1183.2.3
by Martin Packman
Add missing template test file |
17 |
|
18 |
||
19 |
class TestParseArgs(TestCase):
|
|
20 |
||
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)
|
|
28 |
||
29 |
def test_help(self):
|
|
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())
|
|
36 |
||
37 |
||
38 |
class TestMain(TestCase):
|
|
39 |
||
40 |
def test_main(self):
|
|
41 |
argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
|
|
42 |
env = object()
|
|
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("jujupy.SimpleEnvironment.from_config",
|
|
49 |
return_value=env) as mock_e:
|
|
50 |
with patch("jujupy.EnvJujuClient.by_version",
|
|
51 |
return_value=client) as mock_c:
|
|
52 |
with patch("assess_TEMPLATE.assess_TEMPLATE",
|
|
53 |
autospec=True) as mock_assess:
|
|
54 |
main(argv)
|
|
55 |
mock_cl.assert_called_once_with(logging.DEBUG)
|
|
56 |
mock_e.assert_called_once_with("an-env")
|
|
57 |
mock_c.assert_called_once_with(env, "/bin/juju", debug=False)
|
|
58 |
self.assertEqual(mock_bc.call_count, 1)
|
|
59 |
mock_assess.assert_called_once_with(client)
|
|
60 |
||
61 |
||
62 |
class TestAssess(TestCase):
|
|
63 |
||
64 |
def test_TEMPLATE(self):
|
|
1434.1.1
by Aaron Bentley
Update templates to current best practises. |
65 |
# Using fake_client means that deploy and get_status have plausible
|
66 |
# results. Wrapping it in a Mock causes every call to be recorded, and
|
|
1434.1.2
by Aaron Bentley
Update explanation. |
67 |
# allows assertions to be made about calls. Mocks and the fake client
|
68 |
# can also be used separately.
|
|
1434.1.1
by Aaron Bentley
Update templates to current best practises. |
69 |
fake_client = Mock(wraps=fake_juju_client())
|
70 |
fake_client.bootstrap()
|
|
71 |
assess_TEMPLATE(fake_client)
|
|
72 |
fake_client.juju.assert_called_once_with(
|
|
1183.2.3
by Martin Packman
Add missing template test file |
73 |
'deploy', ('local:trusty/my-charm',))
|
1434.1.1
by Aaron Bentley
Update templates to current best practises. |
74 |
fake_client.wait_for_started.assert_called_once_with()
|
75 |
self.assertEqual(
|
|
76 |
1, fake_client.get_status().get_service_unit_count('my-charm'))
|
|
1183.2.3
by Martin Packman
Add missing template test file |
77 |
self.assertNotIn("TODO", self.log_stream.getvalue())
|