~abentley/juju-ci-tools/client-from-config-4

« back to all changes in this revision

Viewing changes to tests/test_assess_cs_staging.py

  • Committer: Curtis Hovey
  • Date: 2015-12-20 15:14:05 UTC
  • Revision ID: curtis@canonical.com-20151220151405-pm3dauunjr2978gz
skip any client-server that starts with 1.26.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Tests for assess_cs_staging module."""
2
 
 
3
 
import logging
4
 
from mock import Mock, patch
5
 
import StringIO
6
 
 
7
 
from assess_cs_staging import (
8
 
    assess_deploy,
9
 
    _get_ssh_script,
10
 
    parse_args,
11
 
    main,
12
 
    _set_charm_store_ip,
13
 
)
14
 
from tests import (
15
 
    parse_error,
16
 
    TestCase,
17
 
)
18
 
from tests.test_jujupy import (
19
 
    fake_juju_client,
20
 
    fake_juju_client_optional_jes,
21
 
    )
22
 
 
23
 
 
24
 
class TestParseArgs(TestCase):
25
 
 
26
 
    def test_common_args(self):
27
 
        args = parse_args(["an-ip", "an-env", "/bin/juju", "/tmp/logs",
28
 
                           "an-env-mod"])
29
 
        self.assertEqual("an-ip", args.charm_store_ip)
30
 
        self.assertEqual("an-env", args.env)
31
 
        self.assertEqual("/bin/juju", args.juju_bin)
32
 
        self.assertEqual("/tmp/logs", args.logs)
33
 
        self.assertEqual("an-env-mod", args.temp_env_name)
34
 
        self.assertEqual(False, args.debug)
35
 
        self.assertEqual("ubuntu", args.charm)
36
 
 
37
 
    def test_help(self):
38
 
        fake_stdout = StringIO.StringIO()
39
 
        with parse_error(self) as fake_stderr:
40
 
            with patch("sys.stdout", fake_stdout):
41
 
                parse_args(["--help"])
42
 
        self.assertEqual("", fake_stderr.getvalue())
43
 
 
44
 
 
45
 
class TestSetCharmStoreIP(TestCase):
46
 
 
47
 
    def test_default_as_controller(self):
48
 
        client = fake_juju_client_optional_jes(jes_enabled=False)
49
 
        client.bootstrap()
50
 
        with patch.object(client, 'juju', autospec=True) as juju_mock:
51
 
            _set_charm_store_ip(client, '1.2.3.4')
52
 
        juju_mock.assert_called_once_with(
53
 
            'ssh', ('0', _get_ssh_script('1.2.3.4')))
54
 
 
55
 
    def test_separate_controller(self):
56
 
        client = fake_juju_client()
57
 
        client.bootstrap()
58
 
        controller_client = client.get_controller_client()
59
 
        # Force get_controller_client to return the *same* client, instead of
60
 
        # an equivalent one.
61
 
        with patch.object(client, 'get_controller_client',
62
 
                          return_value=controller_client, autospec=True):
63
 
            with patch.object(controller_client, 'juju',
64
 
                              autospec=True) as juju_mock:
65
 
                _set_charm_store_ip(client, '1.2.3.4')
66
 
        juju_mock.assert_called_once_with(
67
 
            'ssh', ('0', _get_ssh_script('1.2.3.4')))
68
 
 
69
 
 
70
 
class TestMain(TestCase):
71
 
 
72
 
    def test_main(self):
73
 
        argv = ["an-ip", "an-env", "/bin/juju", "/tmp/logs", "an-env-mod",
74
 
                "--verbose"]
75
 
        client = Mock(spec=["is_jes_enabled", "juju"])
76
 
        with patch("assess_cs_staging.configure_logging",
77
 
                   autospec=True) as mock_cl:
78
 
            with patch("assess_cs_staging.BootstrapManager.booted_context",
79
 
                       autospec=True) as mock_bc:
80
 
                with patch("deploy_stack.client_from_config",
81
 
                           return_value=client) as mock_c:
82
 
                    with patch("assess_cs_staging._set_charm_store_ip",
83
 
                               autospec=True) as mock_set_ip:
84
 
                        with patch("assess_cs_staging.assess_deploy",
85
 
                                   autospec=True) as mock_assess:
86
 
                            main(argv)
87
 
        mock_cl.assert_called_once_with(logging.DEBUG)
88
 
        mock_c.assert_called_once_with('an-env', "/bin/juju", debug=False)
89
 
        self.assertEqual(mock_bc.call_count, 1)
90
 
        mock_set_ip.assert_called_once_with(client, 'an-ip')
91
 
        mock_assess.assert_called_once_with(client, 'ubuntu')
92
 
 
93
 
 
94
 
class TestAssess(TestCase):
95
 
 
96
 
    def test_cs_staging_deploy(self):
97
 
        mock_client = Mock(spec=["deploy", "juju", "wait_for_started"])
98
 
        assess_deploy(mock_client, "charm")
99
 
        mock_client.deploy.assert_called_once_with('charm')
100
 
        mock_client.wait_for_started.assert_called_once_with()