1
from landscape.ui.tests.helpers import (
2
ConfigurationProxyHelper, dbus_test_should_skip, dbus_skip_message,
3
FakeGSettings, got_gobject_introspection, gobject_skip_message)
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
12
from landscape.tests.helpers import LandscapeTest
15
class ConfigControllerTest(LandscapeTest):
17
helpers = [ConfigurationProxyHelper]
20
self.config_string = "\n".join(
22
"data_path = /var/lib/landscape/client/",
23
"http_proxy = http://proxy.localdomain:3192",
25
"url = https://landscape.canonical.com/message-system",
27
"registration_password = bar",
28
"computer_title = baz",
29
"https_proxy = https://proxy.localdomain:6192",
30
"ping_url = http://landscape.canonical.com/ping"])
32
self.default_data = {"management-type": "canonical",
34
"hosted-landscape-host": "",
35
"hosted-account-name": "",
36
"hosted-password": "",
37
"local-landscape-host": "",
38
"local-account-name": "",
41
super(ConfigControllerTest, self).setUp()
42
landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
44
settings = FakeGSettings(data=self.default_data)
45
uisettings = UISettings(settings)
46
model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
48
def disable(on_suceed, on_fail):
51
def register(on_notify, on_error, on_succeed, on_fail):
54
self.controller = ConfigController(model)
55
self.controller.disable = disable
56
self.controller.register = register
57
self.controller.load()
61
Test that when we create a controller it has initial state read in
62
directly from the configuration file.
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)
75
def test_set_hosted_account_name(self):
77
Test that we can set the L{hosted_account_name} property.
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")
84
def test_set_local_account_name(self):
86
Test that we can set the L{local_account_name} property.
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")
93
def test_set_hosted_password(self):
95
Test that we can set the L{hosted_password} property.
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")
102
def test_set_local_password(self):
104
Test that we can set the L{local_password} property.
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")
111
def test_set_local_landscape_host(self):
113
Test that we can set the L{local_landscape_host} property.
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")
120
def test_revert(self):
122
Test that we can revert the controller to it's initial state.
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")
131
def test_is_modified(self):
133
Test that we can determine when something has been modified.
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)
148
def test_persist(self):
150
Test that we can write configuration settings back to the config file.
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)
165
if not got_gobject_introspection:
166
skip = gobject_skip_message
167
elif dbus_test_should_skip:
168
skip = dbus_skip_message
171
class EmptyConfigControllerTest(LandscapeTest):
173
helpers = [ConfigurationProxyHelper]
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": ""}
186
super(EmptyConfigControllerTest, self).setUp()
187
landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
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()
195
def test_defaulting(self):
197
Test we set the correct values when loading a blank configuration.
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)
209
if not got_gobject_introspection:
210
skip = gobject_skip_message
211
elif dbus_test_should_skip:
212
skip = dbus_skip_message