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

« back to all changes in this revision

Viewing changes to template_test.py.tmpl

  • Committer: Aaron Bentley
  • Date: 2014-02-24 17:18:29 UTC
  • mto: This revision was merged to the branch mainline in revision 252.
  • Revision ID: aaron.bentley@canonical.com-20140224171829-sz644yhoygu7m9dm
Use tags to identify and shut down instances.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
)
16
 
from tests.test_jujupy import fake_juju_client
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('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)
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)
57
 
 
58
 
 
59
 
class TestAssess(TestCase):
60
 
 
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()
72
 
        self.assertEqual(
73
 
            1, fake_client.get_status().get_service_unit_count('my-charm'))
74
 
        self.assertNotIn("TODO", self.log_stream.getvalue())