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

« back to all changes in this revision

Viewing changes to landscape/ui/model/configuration/tests/test_proxy.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.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:
 
9
    import dbus
 
10
from landscape.tests.helpers import LandscapeTest
 
11
 
 
12
 
 
13
class AuthenticationFailureTest(LandscapeTest):
 
14
    """
 
15
    Test that an authentication failure is handled correctly.
 
16
    """
 
17
    helpers = [ConfigurationProxyHelper]
 
18
 
 
19
    def setUp(self):
 
20
        self.config_string = ""
 
21
 
 
22
        super(AuthenticationFailureTest, self).setUp()
 
23
 
 
24
    def test_failed_authentication(self):
 
25
        """
 
26
        Test that load returns False when authentication fails.
 
27
        """
 
28
 
 
29
        def fake_policy_failure_load(arglist):
 
30
            """
 
31
            This simulates what you see if you click "Cancel" or give the wrong
 
32
            credentials 3 times when L{PolicyKit} challenges you.
 
33
            """
 
34
            raise PermissionDeniedByPolicy()
 
35
 
 
36
        def fake_timeout_failure_load(arglist):
 
37
            """
 
38
            This simulates what you see if you take no action when L{PolicyKit}
 
39
            challenges you.
 
40
            """
 
41
 
 
42
            class FakeNoReply(dbus.DBusException):
 
43
                """
 
44
                Simulate a L{DBus} L{NoReply} exception.
 
45
                """
 
46
                _dbus_error_name = "org.freedesktop.DBus.Error.NoReply"
 
47
 
 
48
            raise FakeNoReply()
 
49
 
 
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([]))
 
54
 
 
55
    if not got_gobject_introspection:
 
56
        skip = gobject_skip_message
 
57
    elif dbus_test_should_skip:
 
58
        skip = dbus_skip_message
 
59
 
 
60
 
 
61
class ConfigurationProxyInterfaceTest(LandscapeTest):
 
62
    """
 
63
    Test that we define the correct interface to a
 
64
    L{LandscapeSetupConfiguration} by really using one as the interface.
 
65
    """
 
66
 
 
67
    helpers = [ConfigurationProxyHelper]
 
68
 
 
69
    def setUp(self):
 
70
        self.config_string = "[client]\n" \
 
71
            "data_path = /var/lib/landscape/client/\n" \
 
72
            "http_proxy = http://proxy.localdomain:3192\n" \
 
73
            "tags = a_tag\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"
 
80
 
 
81
        super(ConfigurationProxyInterfaceTest, self).setUp()
 
82
 
 
83
    def test_method_docstrings(self):
 
84
        """
 
85
        Test that we pass through the docstrings for methods.
 
86
        """
 
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__)
 
93
 
 
94
    def test_account_name(self):
 
95
        """
 
96
        Test that we can get and set an account name via the configuration
 
97
        proxy.
 
98
        """
 
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)
 
103
 
 
104
    def test_computer_title(self):
 
105
        """
 
106
        Test that we can get and set a computer title via the configuration
 
107
        proxy.
 
108
        """
 
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)
 
113
 
 
114
    def test_data_path(self):
 
115
        """
 
116
        Test that we can get and set the data path via the configuration proxy.
 
117
        """
 
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)
 
122
 
 
123
    def test_http_proxy(self):
 
124
        """
 
125
        Test that we can get and set the HTTP proxy via the configuration
 
126
        proxy.
 
127
        """
 
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)
 
133
 
 
134
    def test_https_proxy(self):
 
135
        """
 
136
        Test that we can get and set the HTTPS proxy via the configuration
 
137
        proxy.
 
138
        """
 
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)
 
144
 
 
145
    def test_ping_url(self):
 
146
        """
 
147
        Test that we can get and set the ping URL via the configuration proxy.
 
148
        """
 
149
        self.assertEqual("http://landscape.canonical.com/ping",
 
150
                         self.proxy.ping_url)
 
151
        self.proxy.ping_url = "bar"
 
152
        self.assertEqual("bar", self.proxy.ping_url)
 
153
        self.assertEqual("bar", self.config.ping_url)
 
154
 
 
155
    def test_registration_password(self):
 
156
        """
 
157
        Test that we can get and set the registration password via the
 
158
        configuration proxy.
 
159
        """
 
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)
 
164
 
 
165
    def test_tags(self):
 
166
        """
 
167
        Test that we can get and set the tags via the configuration proxy.
 
168
        """
 
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)
 
173
 
 
174
    def test_url(self):
 
175
        """
 
176
        Test that we can get and set the URL via the configuration proxy.
 
177
        """
 
178
        self.assertEqual("https://landscape.canonical.com/message-system",
 
179
                         self.proxy.url)
 
180
        self.proxy.url = "bar"
 
181
        self.assertEqual("bar", self.proxy.url)
 
182
        self.assertEqual("bar", self.config.url)
 
183
 
 
184
    def test_exit(self):
 
185
        """
 
186
        Test that we can cause the mechanism to exit.
 
187
        """
 
188
        self.assertRaises(SystemExit, self.proxy.exit, asynchronous=False)
 
189
 
 
190
    if not got_gobject_introspection:
 
191
        skip = gobject_skip_message
 
192
    elif dbus_test_should_skip:
 
193
        skip = dbus_skip_message