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

« back to all changes in this revision

Viewing changes to tests/test_assess_mixed_images.py

  • Committer: Curtis Hovey
  • Date: 2014-08-01 12:44:38 UTC
  • Revision ID: curtis@canonical.com-20140801124438-l48516pldkzh7g5n
Do not show all the files in the tarball because it distracts from the test output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Tests for assess_mixed_images module."""
2
 
 
3
 
import logging
4
 
from mock import (
5
 
    call,
6
 
    patch
7
 
)
8
 
import StringIO
9
 
 
10
 
from assess_mixed_images import (
11
 
    assess_mixed_images,
12
 
    parse_args,
13
 
    main,
14
 
)
15
 
from tests import (
16
 
    parse_error,
17
 
    TestCase,
18
 
)
19
 
from tests.test_jujupy import FakeJujuClient
20
 
 
21
 
 
22
 
class TestParseArgs(TestCase):
23
 
 
24
 
    def test_defaults(self):
25
 
        args = parse_args(["an-env", "/bin/juju", "/tmp/logs", "an-env-mod"])
26
 
        self.assertEqual("an-env", args.env)
27
 
        self.assertEqual("/bin/juju", args.juju_bin)
28
 
        self.assertEqual("/tmp/logs", args.logs)
29
 
        self.assertEqual("an-env-mod", args.temp_env_name)
30
 
        self.assertEqual(False, args.debug)
31
 
        self.assertEqual('trusty', args.series)
32
 
 
33
 
    def test_help(self):
34
 
        fake_stdout = StringIO.StringIO()
35
 
        with parse_error(self) as fake_stderr:
36
 
            with patch("sys.stdout", fake_stdout):
37
 
                parse_args(["--help"])
38
 
        self.assertEqual("", fake_stderr.getvalue())
39
 
 
40
 
 
41
 
class TestMain(TestCase):
42
 
 
43
 
    def test_main(self):
44
 
        argv = ["an-env", "/bin/juju", "/tmp/logs", "an-env-mod", "--verbose"]
45
 
        client = FakeJujuClient()
46
 
        with patch("assess_mixed_images.configure_logging",
47
 
                   autospec=True) as mock_cl:
48
 
            with patch("assess_mixed_images.BootstrapManager.booted_context",
49
 
                       autospec=True) as mock_bc:
50
 
                with patch("jujupy.SimpleEnvironment.from_config",
51
 
                           return_value=client.env) as mock_e:
52
 
                    with patch("jujupy.EnvJujuClient.by_version",
53
 
                               return_value=client) as mock_c:
54
 
                        with patch("assess_mixed_images.assess_mixed_images",
55
 
                                   autospec=True) as mock_assess:
56
 
                            main(argv)
57
 
        mock_cl.assert_called_once_with(logging.DEBUG)
58
 
        mock_e.assert_called_once_with("an-env")
59
 
        mock_c.assert_called_once_with(client.env, "/bin/juju", debug=False)
60
 
        self.assertEqual(mock_bc.call_count, 1)
61
 
        mock_assess.assert_called_once_with(client)
62
 
 
63
 
 
64
 
class TestAssess(TestCase):
65
 
 
66
 
    def test_mixed_images(self):
67
 
        mock_client = FakeJujuClient()
68
 
        assess_mixed_images(mock_client)
69
 
        self.assertEqual({
70
 
            'machines': {
71
 
                '0': {'dns-name': '0.example.com'},
72
 
                '1': {'dns-name': '1.example.com'},
73
 
                },
74
 
            'services': {
75
 
                'dummy-sink': {
76
 
                    'exposed': False,
77
 
                    'relations': {'source': ['dummy-source']},
78
 
                    'units': {'dummy-sink/0': {'machine': '0'}}
79
 
                    },
80
 
                'dummy-source': {
81
 
                    'exposed': False,
82
 
                    'relations': {},
83
 
                    'units': {'dummy-source/0': {'machine': '1'}}
84
 
                    }
85
 
                }
86
 
            }, mock_client.get_status().status)
87
 
 
88
 
    def test_mixed_images_charm_2x(self):
89
 
        mock_client = FakeJujuClient()
90
 
        with patch.object(mock_client, 'deploy') as mock_d:
91
 
            with patch('assess_mixed_images.assess_juju_relations',
92
 
                       autospec=True) as mock_ajr:
93
 
                assess_mixed_images(mock_client)
94
 
        calls = [call('dummy-sink'), call('dummy-source')]
95
 
        self.assertEqual(mock_d.mock_calls, calls)
96
 
        mock_ajr.assert_called_once_with(mock_client)
97
 
 
98
 
    def test_mixed_images_charm_1x(self):
99
 
        mock_client = FakeJujuClient(version='1.25.0')
100
 
        with patch.object(mock_client, 'deploy') as mock_d:
101
 
            with patch('assess_mixed_images.assess_juju_relations',
102
 
                       autospec=True) as mock_ajr:
103
 
                assess_mixed_images(mock_client)
104
 
        calls = [call('local:centos7/dummy-sink'),
105
 
                 call('local:trusty/dummy-source')]
106
 
        self.assertEqual(mock_d.mock_calls, calls)
107
 
        mock_ajr.assert_called_once_with(mock_client)