~ubuntu-branches/ubuntu/lucid/landscape-client/lucid-updates

« back to all changes in this revision

Viewing changes to landscape/ui/controller/tests/test_configuration.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-04-10 14:28:48 UTC
  • mfrom: (1.1.27)
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: package-import@ubuntu.com-20120410142848-7xsy4g2xii7y7ntc
ImportĀ upstreamĀ versionĀ 12.04.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from landscape.ui.tests.helpers import (
 
2
    ConfigurationProxyHelper, dbus_test_should_skip, dbus_skip_message,
 
3
    FakeGSettings, got_gobject_introspection, gobject_skip_message)
 
4
 
 
5
if got_gobject_introspection:
 
6
    from landscape.ui.controller.configuration import ConfigController
 
7
    import landscape.ui.model.configuration.state
 
8
    from landscape.ui.model.configuration.state import (
 
9
        ConfigurationModel, COMPUTER_TITLE)
 
10
    from landscape.ui.model.configuration.uisettings import UISettings
 
11
 
 
12
from landscape.tests.helpers import LandscapeTest
 
13
 
 
14
 
 
15
class ConfigControllerTest(LandscapeTest):
 
16
 
 
17
    helpers = [ConfigurationProxyHelper]
 
18
 
 
19
    def setUp(self):
 
20
        self.config_string = "\n".join(
 
21
            ["[client]",
 
22
             "data_path = /var/lib/landscape/client/",
 
23
             "http_proxy = http://proxy.localdomain:3192",
 
24
             "tags = a_tag",
 
25
             "url = https://landscape.canonical.com/message-system",
 
26
             "account_name = foo",
 
27
             "registration_password = bar",
 
28
             "computer_title = baz",
 
29
             "https_proxy = https://proxy.localdomain:6192",
 
30
             "ping_url = http://landscape.canonical.com/ping"])
 
31
 
 
32
        self.default_data = {"management-type": "canonical",
 
33
                             "computer-title": "",
 
34
                             "hosted-landscape-host": "",
 
35
                             "hosted-account-name": "",
 
36
                             "hosted-password": "",
 
37
                             "local-landscape-host": "",
 
38
                             "local-account-name": "",
 
39
                             "local-password": ""}
 
40
 
 
41
        super(ConfigControllerTest, self).setUp()
 
42
        landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
 
43
            = "me.here.com"
 
44
        settings = FakeGSettings(data=self.default_data)
 
45
        uisettings = UISettings(settings)
 
46
        model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
 
47
 
 
48
        def disable(on_suceed, on_fail):
 
49
            pass
 
50
 
 
51
        def register(on_notify, on_error, on_succeed, on_fail):
 
52
            pass
 
53
 
 
54
        self.controller = ConfigController(model)
 
55
        self.controller.disable = disable
 
56
        self.controller.register = register
 
57
        self.controller.load()
 
58
 
 
59
    def test_init(self):
 
60
        """
 
61
        Test that when we create a controller it has initial state read in
 
62
        directly from the configuration file.
 
63
        """
 
64
        self.controller.load()
 
65
        self.assertEqual("baz", self.controller.computer_title)
 
66
        self.assertTrue(self.controller.management_type)
 
67
        self.assertEqual("landscape.canonical.com",
 
68
                         self.controller.hosted_landscape_host)
 
69
        self.assertEqual("foo", self.controller.hosted_account_name)
 
70
        self.assertEqual("bar", self.controller.hosted_password)
 
71
        self.assertEqual("", self.controller.local_landscape_host)
 
72
        self.assertEqual("standalone", self.controller.local_account_name)
 
73
        self.assertEqual("", self.controller.local_password)
 
74
 
 
75
    def test_set_hosted_account_name(self):
 
76
        """
 
77
        Test that we can set the L{hosted_account_name} property.
 
78
        """
 
79
        self.controller.load()
 
80
        self.assertEqual(self.controller.hosted_account_name, "foo")
 
81
        self.controller.hosted_account_name = "shoe"
 
82
        self.assertEqual(self.controller.hosted_account_name, "shoe")
 
83
 
 
84
    def test_set_local_account_name(self):
 
85
        """
 
86
        Test that we can set the L{local_account_name} property.
 
87
        """
 
88
        self.controller.load()
 
89
        self.assertEqual("standalone", self.controller.local_account_name)
 
90
        self.controller.local_account_name = "shoe"
 
91
        self.assertEqual(self.controller.local_account_name, "shoe")
 
92
 
 
93
    def test_set_hosted_password(self):
 
94
        """
 
95
        Test that we can set the L{hosted_password} property.
 
96
        """
 
97
        self.controller.load()
 
98
        self.assertEqual(self.controller.hosted_password, "bar")
 
99
        self.controller.hosted_password = "nucker"
 
100
        self.assertEqual(self.controller.hosted_password, "nucker")
 
101
 
 
102
    def test_set_local_password(self):
 
103
        """
 
104
        Test that we can set the L{local_password} property.
 
105
        """
 
106
        self.controller.load()
 
107
        self.assertEqual(self.controller.local_password, "")
 
108
        self.controller.local_password = "nucker"
 
109
        self.assertEqual(self.controller.local_password, "nucker")
 
110
 
 
111
    def test_set_local_landscape_host(self):
 
112
        """
 
113
        Test that we can set the L{local_landscape_host} property.
 
114
        """
 
115
        self.controller.load()
 
116
        self.assertEqual("", self.controller.local_landscape_host)
 
117
        self.controller.local_landscape_host = "smelly.pants"
 
118
        self.assertEqual(self.controller.local_landscape_host, "smelly.pants")
 
119
 
 
120
    def test_revert(self):
 
121
        """
 
122
        Test that we can revert the controller to it's initial state.
 
123
        """
 
124
        self.controller.load()
 
125
        self.assertEqual(self.controller.hosted_account_name, "foo")
 
126
        self.controller.hosted_account_name = "Hildaborg"
 
127
        self.assertEqual(self.controller.hosted_account_name, "Hildaborg")
 
128
        self.controller.revert()
 
129
        self.assertEqual(self.controller.hosted_account_name, "foo")
 
130
 
 
131
    def test_is_modified(self):
 
132
        """
 
133
        Test that we can determine when something has been modified.
 
134
        """
 
135
        self.controller.load()
 
136
        self.assertFalse(self.controller.is_modified)
 
137
        self.controller.local_landscape_host = "bing.bang.a.bang"
 
138
        self.assertTrue(self.controller.is_modified)
 
139
        self.controller.revert()
 
140
        self.assertFalse(self.controller.is_modified)
 
141
        self.controller.account_name = "soldierBlue"
 
142
        self.assertTrue(self.controller.is_modified)
 
143
        self.controller.revert()
 
144
        self.assertFalse(self.controller.is_modified)
 
145
        self.controller.registration_password = "HesAnIndianCowboyInTheRodeo"
 
146
        self.assertTrue(self.controller.is_modified)
 
147
 
 
148
    def test_persist(self):
 
149
        """
 
150
        Test that we can write configuration settings back to the config file.
 
151
        """
 
152
        self.controller.load()
 
153
        self.assertEqual("", self.controller.local_landscape_host)
 
154
        self.controller.local_landscape_host = "landscape.localdomain"
 
155
        self.assertEqual("landscape.localdomain",
 
156
                         self.controller.local_landscape_host)
 
157
        self.controller.persist(None, None, None, None)
 
158
        self.assertEqual("landscape.localdomain",
 
159
                         self.controller.local_landscape_host)
 
160
        self.controller.local_landscape_host = "boo"
 
161
        self.controller.revert()
 
162
        self.assertEqual("landscape.localdomain",
 
163
                         self.controller.local_landscape_host)
 
164
 
 
165
    if not got_gobject_introspection:
 
166
        skip = gobject_skip_message
 
167
    elif dbus_test_should_skip:
 
168
        skip = dbus_skip_message
 
169
 
 
170
 
 
171
class EmptyConfigControllerTest(LandscapeTest):
 
172
 
 
173
    helpers = [ConfigurationProxyHelper]
 
174
 
 
175
    def setUp(self):
 
176
        self.config_string = ""
 
177
        self.default_data = {"management-type": "not",
 
178
                             "computer-title": "",
 
179
                             "hosted-landscape-host": "",
 
180
                             "hosted-account-name": "",
 
181
                             "hosted-password": "",
 
182
                             "local-landscape-host": "",
 
183
                             "local-account-name": "",
 
184
                             "local-password": ""}
 
185
 
 
186
        super(EmptyConfigControllerTest, self).setUp()
 
187
        landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
 
188
            = "me.here.com"
 
189
        settings = FakeGSettings(data=self.default_data)
 
190
        uisettings = UISettings(settings)
 
191
        model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
 
192
        self.controller = ConfigController(model)
 
193
        self.controller.load()
 
194
 
 
195
    def test_defaulting(self):
 
196
        """
 
197
        Test we set the correct values when loading a blank configuration.
 
198
        """
 
199
        self.controller.load()
 
200
        self.assertEqual("not", self.controller.management_type)
 
201
        self.assertEqual("", self.controller.hosted_account_name)
 
202
        self.assertEqual("", self.controller.hosted_password)
 
203
        self.assertEqual("landscape.canonical.com",
 
204
                         self.controller.hosted_landscape_host)
 
205
        self.assertEqual("standalone", self.controller.local_account_name)
 
206
        self.assertEqual("", self.controller.local_password)
 
207
        self.assertEqual("me.here.com", self.controller.computer_title)
 
208
 
 
209
    if not got_gobject_introspection:
 
210
        skip = gobject_skip_message
 
211
    elif dbus_test_should_skip:
 
212
        skip = dbus_skip_message