~clint-fewbar/pyjuju/repo-from-env

« back to all changes in this revision

Viewing changes to juju/control/tests/test_config_set.py

  • Committer: Benjamin Saller
  • Date: 2012-01-20 22:34:20 UTC
  • mfrom: (440.1.4 config-set-filename)
  • Revision ID: bcsaller@gmail.com-20120120223420-qu3guvs7by4gihl7
Add --config <file.yaml> to juju set [f=902143] [r=gmb, hazmat]\n\nReplaces the unimplemented --filename argument with --config taking the same type of file as juju deploy --config

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import yaml
1
2
from yaml import dump
2
3
 
3
4
from twisted.internet.defer import inlineCallbacks
37
38
        self.assertEqual(state, {"blog-title": "Hello Tribune?"})
38
39
 
39
40
    @inlineCallbacks
 
41
    def test_set_with_config_file(self):
 
42
        finished = self.setup_cli_reactor()
 
43
        self.setup_exit(0)
 
44
        self.mocker.replay()
 
45
        config_file = self.makeFile(dump(dict(
 
46
            wordpress={"blog-title": "Hello World"})))
 
47
 
 
48
        main(["set", "wordpress",
 
49
              "--config=%s" % config_file])
 
50
        yield finished
 
51
 
 
52
        # Verify the state is accessible
 
53
        state = yield self.service_state.get_config()
 
54
        self.assertEqual(state, {"blog-title": "Hello World"})
 
55
 
 
56
    @inlineCallbacks
 
57
    def test_set_with_invalid_file(self):
 
58
        finished = self.setup_cli_reactor()
 
59
        self.setup_exit(0)
 
60
        self.mocker.replay()
 
61
        # missing the service_name dict (will do nothing to values)
 
62
        config_file = self.makeFile(dump({"blog-title": "Hello World"}))
 
63
 
 
64
        main(["set", "wordpress",
 
65
              "--config=%s" % config_file])
 
66
 
 
67
        yield finished
 
68
        state = yield self.service_state.get_config()
 
69
        self.assertEqual(state, {})
 
70
 
 
71
    @inlineCallbacks
 
72
    def test_set_with_garbage_file(self):
 
73
        finished = self.setup_cli_reactor()
 
74
        self.setup_exit(1)
 
75
        self.mocker.replay()
 
76
 
 
77
        # file exists but is not valid YAML
 
78
        config_file = self.makeFile("blah")
 
79
 
 
80
        main(["-v", "set", "wordpress",
 
81
              "--config=%s" % config_file])
 
82
 
 
83
        yield finished
 
84
        self.assertIn("Config file %r invalid" % config_file, self.stderr.getvalue())
 
85
        state = yield self.service_state.get_config()
 
86
        self.assertEqual(state, {})
 
87
 
 
88
    @inlineCallbacks
 
89
    def test_config_and_cli_options_errors(self):
 
90
        """Verify --config and cli kvpairs can't be used together"""
 
91
        finished = self.setup_cli_reactor()
 
92
        self.setup_exit(1)
 
93
        self.mocker.replay()
 
94
 
 
95
        # valid file, but incorrect cli usage
 
96
        config_file = self.makeFile(dump(dict(
 
97
            wordpress={"blog-title": "Hello World"})))
 
98
 
 
99
        main(["-v", "set", "wordpress",
 
100
              "blog-title=Test",
 
101
              "--config=%s" % config_file])
 
102
 
 
103
        yield finished
 
104
        self.assertIn("--config and command line options", self.stderr.getvalue())
 
105
 
 
106
    @inlineCallbacks
40
107
    def test_set_invalid_option(self):
41
108
        finished = self.setup_cli_reactor()
42
109
        self.setup_exit(0)