~hazmat/pyjuju/proposed-support

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import yaml

from twisted.internet.defer import inlineCallbacks

from juju.control import main

from juju.charm.tests import local_charm_id
from .common import MachineControlToolTest


class ControlJujuGetTest(MachineControlToolTest):

    @inlineCallbacks
    def setUp(self):
        yield super(ControlJujuGetTest, self).setUp()
        self.stderr = self.capture_stream("stderr")

    @inlineCallbacks
    def test_get_service_config(self):
        finished = self.setup_cli_reactor()
        self.setup_exit(0)
        self.mocker.replay()

        self.service_state = yield self.add_service_from_charm("wordpress")
        config = yield self.service_state.get_config()
        # The value which isn't in the config won't be displayed.
        settings = {"blog-title": "Hello World", "world": 123}
        config.update(settings)
        yield config.write()

        output = self.capture_stream("stdout")
        main(["get", "wordpress"])

        yield finished
        data = yaml.load(output.getvalue())
        self.assertEqual(
            {"service": "wordpress",
             "charm": "local:series/wordpress-3",
             'settings': {'blog-title': {
                 'description': 'A descriptive title used for the blog.',
                 'type': 'string',
                 'value': 'Hello World'}}},
            data)

    @inlineCallbacks
    def test_get_service_config_with_no_value(self):
        finished = self.setup_cli_reactor()
        self.setup_exit(0)
        self.mocker.replay()

        self.service_state = yield self.add_service_from_charm(
            "dummy", local_charm_id(self.charm))
        config = yield self.service_state.get_config()
        config["title"] = "hello movie"
        config["skill-level"] = 24
        yield config.write()

        output = self.capture_stream("stdout")
        main(["get", "dummy"])

        yield finished
        data = yaml.load(output.getvalue())

        self.assertEqual(
            {"service": "dummy",
             "charm": "local:series/dummy-1",
             "settings": {
                 'outlook': {
                     'description': 'No default outlook.',
                     'type': 'string',
                     'value': '-Not set-'},
                 'skill-level': {
                     'description': 'A number indicating skill.',
                     'value': 24,
                     'type': 'int'},
                 'title': {
                     'description': ('A descriptive title used '
                                    'for the service.'),
                     'value': 'hello movie',
                     'type': 'string'},
                 'username': {
                     'description': ('The name of the initial account (given '
                                     'admin permissions).'),
                     'value': 'admin001',
                     'default': True,
                     'type': 'string'}}},
            data)

    @inlineCallbacks
    def test_set_invalid_service(self):
        finished = self.setup_cli_reactor()
        self.setup_exit(0)
        self.mocker.replay()

        main(["get", "whatever"])

        yield finished

        self.assertIn("Service 'whatever' was not found",
                      self.stderr.getvalue())