1
from landscape.configuration import LandscapeSetupConfiguration
2
from landscape.ui.tests.helpers import (
3
ConfigurationProxyHelper, dbus_test_should_skip, dbus_skip_message,
4
got_gobject_introspection, gobject_skip_message)
5
if got_gobject_introspection:
6
from landscape.ui.model.configuration.mechanism import (
7
PermissionDeniedByPolicy)
8
if not dbus_test_should_skip:
10
from landscape.tests.helpers import LandscapeTest
13
class AuthenticationFailureTest(LandscapeTest):
15
Test that an authentication failure is handled correctly.
17
helpers = [ConfigurationProxyHelper]
20
self.config_string = ""
22
super(AuthenticationFailureTest, self).setUp()
24
def test_failed_authentication(self):
26
Test that load returns False when authentication fails.
29
def fake_policy_failure_load(arglist):
31
This simulates what you see if you click "Cancel" or give the wrong
32
credentials 3 times when L{PolicyKit} challenges you.
34
raise PermissionDeniedByPolicy()
36
def fake_timeout_failure_load(arglist):
38
This simulates what you see if you take no action when L{PolicyKit}
42
class FakeNoReply(dbus.DBusException):
44
Simulate a L{DBus} L{NoReply} exception.
46
_dbus_error_name = "org.freedesktop.DBus.Error.NoReply"
50
self.mechanism.load = fake_policy_failure_load
51
self.assertFalse(self.proxy.load([]))
52
self.mechanism.load = fake_timeout_failure_load
53
self.assertFalse(self.proxy.load([]))
55
if not got_gobject_introspection:
56
skip = gobject_skip_message
57
elif dbus_test_should_skip:
58
skip = dbus_skip_message
61
class ConfigurationProxyInterfaceTest(LandscapeTest):
63
Test that we define the correct interface to a
64
L{LandscapeSetupConfiguration} by really using one as the interface.
67
helpers = [ConfigurationProxyHelper]
70
self.config_string = "[client]\n" \
71
"data_path = /var/lib/landscape/client/\n" \
72
"http_proxy = http://proxy.localdomain:3192\n" \
74
"url = https://landscape.canonical.com/message-system\n" \
75
"account_name = foo\n" \
76
"registration_password = boink\n" \
77
"computer_title = baz\n" \
78
"https_proxy = https://proxy.localdomain:6192\n" \
79
"ping_url = http://landscape.canonical.com/ping\n"
81
super(ConfigurationProxyInterfaceTest, self).setUp()
83
def test_method_docstrings(self):
85
Test that we pass through the docstrings for methods.
87
self.assertEqual(self.proxy.load.__doc__,
88
LandscapeSetupConfiguration.load.__doc__)
89
self.assertEqual(self.proxy.reload.__doc__,
90
LandscapeSetupConfiguration.reload.__doc__)
91
self.assertEqual(self.proxy.write.__doc__,
92
LandscapeSetupConfiguration.write.__doc__)
94
def test_account_name(self):
96
Test that we can get and set an account name via the configuration
99
self.assertEqual("foo", self.proxy.account_name)
100
self.proxy.account_name = "bar"
101
self.assertEqual("bar", self.proxy.account_name)
102
self.assertEqual("bar", self.config.account_name)
104
def test_computer_title(self):
106
Test that we can get and set a computer title via the configuration
109
self.assertEqual("baz", self.proxy.computer_title)
110
self.proxy.computer_title = "bar"
111
self.assertEqual("bar", self.proxy.computer_title)
112
self.assertEqual("bar", self.config.computer_title)
114
def test_data_path(self):
116
Test that we can get and set the data path via the configuration proxy.
118
self.assertEqual("/var/lib/landscape/client/", self.proxy.data_path)
119
self.proxy.data_path = "bar"
120
self.assertEqual("bar", self.proxy.data_path)
121
self.assertEqual("bar", self.config.data_path)
123
def test_http_proxy(self):
125
Test that we can get and set the HTTP proxy via the configuration
128
self.assertEqual("http://proxy.localdomain:3192",
129
self.proxy.http_proxy)
130
self.proxy.http_proxy = "bar"
131
self.assertEqual("bar", self.proxy.http_proxy)
132
self.assertEqual("bar", self.config.http_proxy)
134
def test_https_proxy(self):
136
Test that we can get and set the HTTPS proxy via the configuration
139
self.assertEqual("https://proxy.localdomain:6192",
140
self.proxy.https_proxy)
141
self.proxy.https_proxy = "bar"
142
self.assertEqual("bar", self.proxy.https_proxy)
143
self.assertEqual("bar", self.config.https_proxy)
145
def test_ping_url(self):
147
Test that we can get and set the ping URL via the configuration proxy.
149
self.assertEqual("http://landscape.canonical.com/ping",
151
self.proxy.ping_url = "bar"
152
self.assertEqual("bar", self.proxy.ping_url)
153
self.assertEqual("bar", self.config.ping_url)
155
def test_registration_password(self):
157
Test that we can get and set the registration password via the
160
self.assertEqual("boink", self.proxy.registration_password)
161
self.proxy.registration_password = "bar"
162
self.assertEqual("bar", self.proxy.registration_password)
163
self.assertEqual("bar", self.config.registration_password)
167
Test that we can get and set the tags via the configuration proxy.
169
self.assertEqual("a_tag", self.proxy.tags)
170
self.proxy.tags = "bar"
171
self.assertEqual("bar", self.proxy.tags)
172
self.assertEqual("bar", self.config.tags)
176
Test that we can get and set the URL via the configuration proxy.
178
self.assertEqual("https://landscape.canonical.com/message-system",
180
self.proxy.url = "bar"
181
self.assertEqual("bar", self.proxy.url)
182
self.assertEqual("bar", self.config.url)
186
Test that we can cause the mechanism to exit.
188
self.assertRaises(SystemExit, self.proxy.exit, asynchronous=False)
190
if not got_gobject_introspection:
191
skip = gobject_skip_message
192
elif dbus_test_should_skip:
193
skip = dbus_skip_message