~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to template_test.py.tmpl

Handle LoggedException in quickstart_deploy, assess_bootstrap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    parse_error,
14
14
    TestCase,
15
15
)
16
 
from tests.test_jujupy import fake_juju_client
17
16
 
18
17
 
19
18
class TestParseArgs(TestCase):
45
44
                   autospec=True) as mock_cl:
46
45
            with patch("assess_TEMPLATE.BootstrapManager.booted_context",
47
46
                       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:
52
 
                        main(argv)
 
47
                with patch("jujupy.SimpleEnvironment.from_config",
 
48
                           return_value=env) as mock_e:
 
49
                    with patch("jujupy.EnvJujuClient.by_version",
 
50
                               return_value=client) as mock_c:
 
51
                        with patch("assess_TEMPLATE.assess_TEMPLATE",
 
52
                                   autospec=True) as mock_assess:
 
53
                            main(argv)
53
54
        mock_cl.assert_called_once_with(logging.DEBUG)
54
 
        mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False)
 
55
        mock_e.assert_called_once_with("an-env")
 
56
        mock_c.assert_called_once_with(env, "/bin/juju", debug=False)
55
57
        self.assertEqual(mock_bc.call_count, 1)
56
58
        mock_assess.assert_called_once_with(client)
57
59
 
59
61
class TestAssess(TestCase):
60
62
 
61
63
    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()
72
 
        self.assertEqual(
73
 
            1, fake_client.get_status().get_service_unit_count('my-charm'))
 
64
        mock_client = Mock(spec=["juju", "wait_for_started"])
 
65
        assess_TEMPLATE(mock_client)
 
66
        mock_client.juju.assert_called_once_with(
 
67
            'deploy', ('local:trusty/my-charm',))
 
68
        mock_client.wait_for_started.assert_called_once_with()
74
69
        self.assertNotIn("TODO", self.log_stream.getvalue())