Merge lp:~ack/landscape-client/drop-ui into lp:~landscape/landscape-client/trunk

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 826
Merged at revision: 833
Proposed branch: lp:~ack/landscape-client/drop-ui
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 6054 lines (+8/-5688)
47 files modified
.bzrignore (+0/-7)
applications/landscape-client-settings.desktop.in (+0/-13)
dbus-1/com.canonical.LandscapeClientRegistration.conf (+0/-16)
dbus-1/com.canonical.LandscapeClientRegistration.service (+0/-4)
dbus-1/com.canonical.LandscapeClientSettings.conf (+0/-16)
dbus-1/com.canonical.LandscapeClientSettings.service (+0/-4)
debian/control (+2/-36)
debian/landscape-client-ui-install.install (+0/-4)
debian/landscape-client-ui.install (+0/-10)
debian/landscape-client.install (+1/-0)
debian/rules (+0/-5)
glib-2.0/schemas/com.canonical.landscape-client-settings.gschema.xml (+0/-37)
icons/preferences-management-service.svg (+0/-54)
landscape/package/facade.py (+0/-13)
landscape/package/tests/test_facade.py (+0/-11)
landscape/ui/constants.py (+0/-3)
landscape/ui/controller/app.py (+0/-91)
landscape/ui/controller/configuration.py (+0/-122)
landscape/ui/controller/tests/test_app.py (+0/-135)
landscape/ui/controller/tests/test_configuration.py (+0/-208)
landscape/ui/lib/polkit.py (+0/-102)
landscape/ui/model/configuration/mechanism.py (+0/-113)
landscape/ui/model/configuration/proxy.py (+0/-110)
landscape/ui/model/configuration/state.py (+0/-586)
landscape/ui/model/configuration/tests/test_mechanism.py (+0/-201)
landscape/ui/model/configuration/tests/test_proxy.py (+0/-187)
landscape/ui/model/configuration/tests/test_state.py (+0/-635)
landscape/ui/model/configuration/tests/test_uisettings.py (+0/-167)
landscape/ui/model/configuration/uisettings.py (+0/-57)
landscape/ui/model/registration/mechanism.py (+0/-177)
landscape/ui/model/registration/proxy.py (+0/-139)
landscape/ui/model/registration/tests/test_mechanism.py (+0/-100)
landscape/ui/model/registration/tests/test_proxy.py (+0/-141)
landscape/ui/tests/helpers.py (+0/-188)
landscape/ui/view/configuration.py (+0/-356)
landscape/ui/view/tests/test_configuration.py (+0/-608)
landscape/ui/view/ui/landscape-client-settings.glade (+0/-462)
po/POTFILES.in (+0/-8)
po/fr.po (+0/-185)
po/landscape-client.pot (+0/-170)
polkit-1/com.canonical.LandscapeClientSettings.policy.in (+0/-21)
scripts/landscape-client-registration-mechanism (+0/-15)
scripts/landscape-client-settings-mechanism (+0/-17)
scripts/landscape-client-settings-ui (+0/-35)
scripts/landscape-client-ui-install (+0/-78)
setup.cfg (+0/-9)
setup.py (+5/-32)
To merge this branch: bzr merge lp:~ack/landscape-client/drop-ui
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Chris Glass (community) Approve
Review via email: mp+288669@code.launchpad.net

Commit message

This removes landscape-client-ui and landscape-client-ui-install packages and drops all UI-related code.
We want to drop these packages starting from Xenial.

Description of the change

This removes landscape-client-ui and landscape-client-ui-install packages and drops all UI-related code.
We want to drop these packages starting from Xenial.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

Great, I love seeing so much red in a branch :)

I tested that this package still registers against hosted - and ran the tests.

+1

review: Approve
Revision history for this message
Данило Шеган (danilo) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-09-18 08:03:43 +0000
3+++ .bzrignore 2016-03-10 16:35:24 +0000
4@@ -16,17 +16,10 @@
5 debian/landscape-common.postrm.debhelper
6 debian/landscape-common.prerm.debhelper
7 debian/landscape-common.substvars
8-debian/landscape-client-ui/
9-debian/landscape-client-ui-install/
10-debian/landscape-client-ui-install.debhelper.log
11-debian/landscape-client-ui-install.substvars
12-debian/landscape-client-ui.debhelper.log
13-debian/landscape-client-ui.substvars
14 man/landscape-client.1
15 man/landscape-config.1
16 man/landscape-message.1
17 man/landscape-sysinfo.1
18-smart-update/smart-update
19 apt-update/apt-update
20 docs
21 tags
22
23=== removed directory 'applications'
24=== removed file 'applications/landscape-client-settings.desktop.in'
25--- applications/landscape-client-settings.desktop.in 2015-07-20 10:00:42 +0000
26+++ applications/landscape-client-settings.desktop.in 1970-01-01 00:00:00 +0000
27@@ -1,13 +0,0 @@
28-[Desktop Entry]
29-_Name=Landscape Service
30-_Comment=Landscape Management Service Preferences
31-Exec=landscape-client-ui-install
32-Icon=preferences-management-service
33-Terminal=False
34-Type=Application
35-StartupNotify=true
36-Categories=GNOME;GTK;Settings;X-GNOME-SystemSettings;X-GNOME-Settings-Panel;X-Unity-Settings-Panel;
37-OnlyShowIn=GNOME;Unity;MATE;
38-X-Unity-Settings-Panel=landscape
39-X-GNOME-Settings-Panel=landscape
40-X-Ubuntu-Gettext-Domain=landscape-client
41
42=== removed file 'dbus-1/com.canonical.LandscapeClientRegistration.conf'
43--- dbus-1/com.canonical.LandscapeClientRegistration.conf 2012-01-19 14:06:45 +0000
44+++ dbus-1/com.canonical.LandscapeClientRegistration.conf 1970-01-01 00:00:00 +0000
45@@ -1,16 +0,0 @@
46-<?xml version="1.0" encoding="UTF-8"?>
47-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
48-"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
49-<busconfig>
50- <type>system</type>
51- <policy user="root">
52- <allow own="com.canonical.LandscapeClientRegistration"/>
53- <allow send_destination="com.canonical.LandscapeClientRegistration"/>
54- <allow send_interface="com.canonical.LandscapeClientRegistration"/>
55- </policy>
56-
57- <policy context="default">
58- <allow send_destination="com.canonical.LandscapeClientRegistration"/>
59- <allow send_interface="com.canonical.LandscapeClientRegistration"/>
60- </policy>
61-</busconfig>
62
63=== removed file 'dbus-1/com.canonical.LandscapeClientRegistration.service'
64--- dbus-1/com.canonical.LandscapeClientRegistration.service 2012-01-19 14:06:45 +0000
65+++ dbus-1/com.canonical.LandscapeClientRegistration.service 1970-01-01 00:00:00 +0000
66@@ -1,4 +0,0 @@
67-[D-BUS Service]
68-Name=com.canonical.LandscapeClientRegistration
69-Exec=/usr/bin/landscape-client-registration-mechanism
70-User=root
71\ No newline at end of file
72
73=== removed file 'dbus-1/com.canonical.LandscapeClientSettings.conf'
74--- dbus-1/com.canonical.LandscapeClientSettings.conf 2012-01-19 14:06:45 +0000
75+++ dbus-1/com.canonical.LandscapeClientSettings.conf 1970-01-01 00:00:00 +0000
76@@ -1,16 +0,0 @@
77-<?xml version="1.0" encoding="UTF-8"?>
78-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
79-"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
80-<busconfig>
81- <type>system</type>
82- <policy user="root">
83- <allow own="com.canonical.LandscapeClientSettings"/>
84- <allow send_destination="com.canonical.LandscapeClientSettings"/>
85- <allow send_interface="com.canonical.LandscapeClientSettings"/>
86- </policy>
87-
88- <policy context="default">
89- <allow send_destination="com.canonical.LandscapeClientSettings"/>
90- <allow send_interface="com.canonical.LandscapeClientSettings"/>
91- </policy>
92-</busconfig>
93
94=== removed file 'dbus-1/com.canonical.LandscapeClientSettings.service'
95--- dbus-1/com.canonical.LandscapeClientSettings.service 2012-01-19 14:06:45 +0000
96+++ dbus-1/com.canonical.LandscapeClientSettings.service 1970-01-01 00:00:00 +0000
97@@ -1,4 +0,0 @@
98-[D-BUS Service]
99-Name=com.canonical.LandscapeClientSettings
100-Exec=/usr/bin/landscape-client-settings-mechanism
101-User=root
102\ No newline at end of file
103
104=== modified file 'debian/control'
105--- debian/control 2014-11-20 20:47:08 +0000
106+++ debian/control 2016-03-10 16:35:24 +0000
107@@ -44,6 +44,8 @@
108 python-twisted-web,
109 python-pycurl,
110 landscape-common (= ${binary:Version})
111+Replaces: landscape-client-ui, landscape-client-ui-install
112+Conflicts: landscape-client-ui, landscape-client-ui-install
113 Suggests: ${extra:Suggests}
114 Description: The Landscape administration system client
115 Landscape is a web-based tool for managing Ubuntu systems. This
116@@ -52,39 +54,3 @@
117 .
118 This package provides the Landscape client and requires a Landscape account.
119 XB-Python-Version: ${python:Versions}
120-
121-Package: landscape-client-ui
122-Architecture: any
123-Depends: ${python:Depends}, ${misc:Depends},
124- landscape-client (= ${binary:Version}),
125- landscape-client-ui-install (= ${binary:Version}),
126- python-gi,
127- python-dbus,
128- policykit-1,
129- gir1.2-notify-0.7,
130- gir1.2-gtk-3.0
131-# Added when we moved the /etc/dbus-1/system.d/landscape.conf file from -client to
132-# -client-ui in r682. There is no accompaining "Breaks" because -client-ui requires
133-# the exact same version of -client, which will trigger the upgrade
134-# and avoid the case discussed in
135-# http://www.debian.org/doc/debian-policy/footnotes.html#f53
136-Replaces: landscape-client (<< 13.05.1+bzr682)
137-Description: The Landscape administration system client - UI configuration
138- Landscape is a web-based tool for managing Ubuntu systems.
139- .
140- This package provides the Landscape client configuration UI.
141-XB-Python-Version: ${python:Versions}
142-
143-Package: landscape-client-ui-install
144-Architecture: any
145-Depends: ${python:Depends}, ${misc:Depends},
146- python-gi,
147- python-dbus,
148- policykit-1,
149- gir1.2-gtk-3.0,
150- python-aptdaemon.gtk3widgets
151-Description: The Landscape administration system client - UI installer
152- Landscape is a web-based tool for managing Ubuntu systems.
153- .
154- This package provides an automatic installer for landscape-client-ui.
155-XB-Python-Version: ${python:Versions}
156
157=== removed file 'debian/landscape-client-ui-install.install'
158--- debian/landscape-client-ui-install.install 2012-03-22 18:43:44 +0000
159+++ debian/landscape-client-ui-install.install 1970-01-01 00:00:00 +0000
160@@ -1,4 +0,0 @@
161-usr/bin/landscape-client-ui-install
162-usr/share/applications/landscape-client-settings.desktop
163-usr/share/icons/hicolor/scalable/apps/preferences-management-service.svg
164-usr/share/locale
165
166=== removed file 'debian/landscape-client-ui.install'
167--- debian/landscape-client-ui.install 2013-05-16 09:15:13 +0000
168+++ debian/landscape-client-ui.install 1970-01-01 00:00:00 +0000
169@@ -1,10 +0,0 @@
170-usr/bin/landscape-client-settings-mechanism
171-usr/bin/landscape-client-registration-mechanism
172-usr/bin/landscape-client-settings-ui
173-usr/share/dbus-1/system-services/com.canonical.LandscapeClientSettings.service
174-usr/share/dbus-1/system-services/com.canonical.LandscapeClientRegistration.service
175-usr/share/polkit-1/actions/com.canonical.LandscapeClientSettings.policy
176-etc/dbus-1/system.d/com.canonical.LandscapeClientSettings.conf
177-etc/dbus-1/system.d/com.canonical.LandscapeClientRegistration.conf
178-etc/dbus-1/system.d/landscape.conf
179-usr/share/glib-2.0/schemas/com.canonical.landscape-client-settings.gschema.xml
180
181=== modified file 'debian/landscape-client.install'
182--- debian/landscape-client.install 2014-07-17 18:54:12 +0000
183+++ debian/landscape-client.install 2016-03-10 16:35:24 +0000
184@@ -9,3 +9,4 @@
185 usr/bin/landscape-release-upgrader
186 usr/bin/landscape-dbus-proxy
187 usr/lib/landscape
188+etc/dbus-1/system.d/landscape.conf
189
190=== modified file 'debian/rules'
191--- debian/rules 2014-07-17 18:54:12 +0000
192+++ debian/rules 2016-03-10 16:35:24 +0000
193@@ -9,10 +9,6 @@
194 endif
195
196 dh_extra_flags = -plandscape-common -plandscape-client
197-ifeq (,$(filter $(dist_release),hardy lucid natty oneiric))
198- # We want landscape-client-ui only from precise onward
199- dh_extra_flags += -plandscape-client-ui -plandscape-client-ui-install
200-endif
201
202 -include /usr/share/python/python.mk
203 ifeq (,$(py_sitename))
204@@ -49,7 +45,6 @@
205 rm -rf build
206 make -C apt-update clean
207 dh_clean
208- debconf-updatepo
209 sed -i -e "s/^DEBIAN_REVISION = .*/DEBIAN_REVISION = \"\"/g" landscape/__init__.py
210
211 install: build
212
213=== removed directory 'glib-2.0'
214=== removed directory 'glib-2.0/schemas'
215=== removed file 'glib-2.0/schemas/com.canonical.landscape-client-settings.gschema.xml'
216--- glib-2.0/schemas/com.canonical.landscape-client-settings.gschema.xml 2012-03-20 14:39:42 +0000
217+++ glib-2.0/schemas/com.canonical.landscape-client-settings.gschema.xml 1970-01-01 00:00:00 +0000
218@@ -1,37 +0,0 @@
219-<?xml version="1.0" encoding="utf-8"?>
220-<schemalist>
221- <schema id="com.canonical.landscape-client-settings" path="/com/canonical/landscape-client-settings/">
222- <key type="s" name="management-type">
223- <default>"not"</default>
224- <summary>Whether the client settings UI currently set to a hosted client configuration, an LDS instance or no management service.</summary>
225- </key>
226- <key type="s" name="computer-title">
227- <default>""</default>
228- <summary>The title to register the machine with.</summary>
229- </key>
230- <key type="s" name="hosted-landscape-host">
231- <default>"landscape.canonical.com"</default>
232- <summary>The hostname of the Canonical hosted landscape system.</summary>
233- </key>
234- <key type="s" name="hosted-account-name">
235- <default>""</default>
236- <summary>An account name for use with the Canonical hosted landscape system.</summary>
237- </key>
238- <key type="s" name="hosted-password">
239- <default>""</default>
240- <summary>A password for use with the Canonical hosted landscape system</summary>
241- </key>
242- <key type="s" name="local-landscape-host">
243- <default>""</default>
244- <summary>The hostname of the local landscape system.</summary>
245- </key>
246- <key type="s" name="local-account-name">
247- <default>""</default>
248- <summary>An account name for use with the local landscape system.</summary>
249- </key>
250- <key type="s" name="local-password">
251- <default>""</default>
252- <summary>A password for use with the local landscape system</summary>
253- </key>
254- </schema>
255-</schemalist>
256
257=== removed directory 'icons'
258=== removed file 'icons/preferences-management-service.svg'
259--- icons/preferences-management-service.svg 2014-06-13 15:00:01 +0000
260+++ icons/preferences-management-service.svg 1970-01-01 00:00:00 +0000
261@@ -1,54 +0,0 @@
262-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
263-<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
264-
265-<svg
266- xmlns:dc="http://purl.org/dc/elements/1.1/"
267- xmlns:cc="http://creativecommons.org/ns#"
268- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
269- xmlns:svg="http://www.w3.org/2000/svg"
270- xmlns="http://www.w3.org/2000/svg"
271- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
272- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
273- version="1.1"
274- id="artwork"
275- x="0px"
276- y="0px"
277- width="34px"
278- height="34px"
279- viewBox="0 0 34 34"
280- enable-background="new 0 0 34 34"
281- xml:space="preserve"
282- inkscape:version="0.48.4 r9939"
283- sodipodi:docname="landscape_favicon_32px.svg"><metadata
284- id="metadata3887"><rdf:RDF><cc:Work
285- rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
286- rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
287- id="defs3885" /><sodipodi:namedview
288- pagecolor="#ffffff"
289- bordercolor="#666666"
290- borderopacity="1"
291- objecttolerance="10"
292- gridtolerance="10"
293- guidetolerance="10"
294- inkscape:pageopacity="0"
295- inkscape:pageshadow="2"
296- inkscape:window-width="640"
297- inkscape:window-height="480"
298- id="namedview3883"
299- showgrid="false"
300- inkscape:zoom="6.9411765"
301- inkscape:cx="17"
302- inkscape:cy="17"
303- inkscape:window-x="0"
304- inkscape:window-y="24"
305- inkscape:window-maximized="0"
306- inkscape:current-layer="artwork" /><circle
307- fill="#DD4814"
308- cx="17"
309- cy="17.001"
310- r="16"
311- id="circle3877" /><g
312- id="g3879"><polygon
313- fill="#FFFFFF"
314- points="24.5,26.5 10.5,26.5 10.5,6.5 11.5,6.5 11.5,25.5 23.5,25.5 23.5,22.5 14.5,22.5 14.5,7.5 13.5,7.5 13.5,23.5 22.5,23.5 22.5,24.5 12.5,24.5 12.5,6.5 15.5,6.5 15.5,21.5 24.5,21.5 "
315- id="polygon3881" /></g></svg>
316\ No newline at end of file
317
318=== modified file 'landscape/package/facade.py'
319--- landscape/package/facade.py 2015-04-15 13:16:20 +0000
320+++ landscape/package/facade.py 2016-03-10 16:35:24 +0000
321@@ -23,7 +23,6 @@
322 from apt.progress.base import InstallProgress
323
324 from landscape.lib.fs import append_file, create_file, read_file, touch_file
325-from landscape.constants import UBUNTU_PATH
326 from landscape.package.skeleton import build_skeleton_apt
327
328
329@@ -592,23 +591,11 @@
330 os.environ["APT_LISTCHANGES_FRONTEND"] = "none"
331 os.environ["APT_LISTBUGS_FRONTEND"] = "none"
332
333- def _default_path_when_missing(self):
334- """
335- If no PATH is set in the environment, use the Ubuntu default PATH.
336-
337- When the client is launched from the landscape-client-settings-ui the
338- PATH variable is incorrectly set, this method rectifies that.
339- """
340- # dpkg will fail if no path is set.
341- if "PATH" not in os.environ:
342- os.environ["PATH"] = UBUNTU_PATH
343-
344 def _setup_dpkg_for_changes(self):
345 """
346 Setup environment and apt options for successful package operations.
347 """
348 self._set_frontend_noninteractive()
349- self._default_path_when_missing()
350 apt_pkg.config.clear("DPkg::options")
351 apt_pkg.config.set("DPkg::options::", "--force-confold")
352
353
354=== modified file 'landscape/package/tests/test_facade.py'
355--- landscape/package/tests/test_facade.py 2015-04-15 13:16:20 +0000
356+++ landscape/package/tests/test_facade.py 2016-03-10 16:35:24 +0000
357@@ -8,7 +8,6 @@
358 from aptsources.sourceslist import SourcesList
359 from apt.cache import LockFailedException
360
361-from landscape.constants import UBUNTU_PATH
362 from landscape.lib.fs import read_file, create_file
363 from landscape.package.facade import (
364 TransactionError, DependencyError, ChannelError, AptFacade,
365@@ -960,16 +959,6 @@
366 self.assertEqual(["--force-confold"],
367 apt_pkg.config.value_list("DPkg::options"))
368
369- def test_perform_changes_with_no_path(self):
370- """
371- perform_changes() sets C{PATH} if it's not set already, since
372- dpkg requires it to be set.
373- """
374- del os.environ["PATH"]
375- self.facade.reload_channels()
376- self.assertEqual(self.facade.perform_changes(), None)
377- self.assertEqual(UBUNTU_PATH, os.environ["PATH"])
378-
379 def test_perform_changes_with_path(self):
380 """
381 perform_changes() doesn't set C{PATH} if it's set already.
382
383=== removed directory 'landscape/ui'
384=== removed file 'landscape/ui/__init__.py'
385=== removed file 'landscape/ui/constants.py'
386--- landscape/ui/constants.py 2012-02-28 11:52:56 +0000
387+++ landscape/ui/constants.py 1970-01-01 00:00:00 +0000
388@@ -1,3 +0,0 @@
389-CANONICAL_MANAGED = "canonical"
390-LOCAL_MANAGED = "LDS"
391-NOT_MANAGED = "not"
392
393=== removed directory 'landscape/ui/controller'
394=== removed file 'landscape/ui/controller/__init__.py'
395=== removed file 'landscape/ui/controller/app.py'
396--- landscape/ui/controller/app.py 2012-03-23 10:12:34 +0000
397+++ landscape/ui/controller/app.py 1970-01-01 00:00:00 +0000
398@@ -1,91 +0,0 @@
399-import sys
400-
401-from gettext import gettext as _
402-
403-from gi.repository import Gio, Gtk, Notify
404-
405-from landscape.ui.model.configuration.proxy import ConfigurationProxy
406-from landscape.ui.model.configuration.state import ConfigurationModel
407-from landscape.ui.model.configuration.uisettings import UISettings
408-from landscape.ui.view.configuration import ClientSettingsDialog
409-from landscape.ui.controller.configuration import ConfigController
410-
411-
412-APPLICATION_ID = "com.canonical.landscape-client.settings.ui"
413-NOTIFY_ID = "Landscape management service"
414-
415-
416-class SettingsApplicationController(Gtk.Application):
417- """
418- Core application controller for the landscape settings application.
419- """
420-
421- def __init__(self, args=[]):
422- super(SettingsApplicationController, self).__init__(
423- application_id=APPLICATION_ID)
424- self._args = args
425- self.connect("activate", self.setup_ui)
426-
427- def get_config(self):
428- return ConfigurationProxy()
429-
430- def get_uisettings(self):
431- return UISettings(Gio.Settings)
432-
433- def on_notify(self, message):
434- notification = Notify.Notification.new(NOTIFY_ID, message,
435- "dialog-information")
436- notification.show()
437-
438- def on_error(self, message):
439- notification = Notify.Notification.new(NOTIFY_ID, message,
440- "dialog-information")
441- notification.show()
442-
443- def on_succeed(self, action=None):
444- if action:
445- message = action
446- else:
447- message = _("Success.")
448- notification = Notify.Notification.new(NOTIFY_ID, message,
449- "dialog-information")
450- notification.show()
451-
452- def on_fail(self, action=None):
453- if action:
454- message = action
455- else:
456- message = _("Failure.")
457- notification = Notify.Notification.new(NOTIFY_ID, message,
458- "dialog-information")
459- notification.show()
460-
461- def setup_ui(self, data=None, asynchronous=True):
462- """
463- L{setup_ui} wires the model to the L{ConfigurationController} and then
464- invokes the view with the controller. When the dialog exits
465- appropriate termination is triggered.
466-
467- @param data: the Gtk callback could pass this, but it is always None in
468- practice.
469- @param asynchronous: a parameter passed through to
470- L{ConfigurationController.exit}, it indicates whether the exit method
471- should be called asynchronously. Is makes testing easier to use it
472- synchronously.
473- """
474- Notify.init(NOTIFY_ID)
475- config = self.get_config()
476- uisettings = self.get_uisettings()
477- model = ConfigurationModel(proxy=config, proxy_loadargs=self._args,
478- uisettings=uisettings)
479- controller = ConfigController(model)
480- if controller.load():
481- self.settings_dialog = ClientSettingsDialog(controller)
482- if self.settings_dialog.run() == Gtk.ResponseType.OK:
483- controller.persist(self.on_notify, self.on_error,
484- self.on_succeed, self.on_fail)
485- controller.exit(asynchronous=asynchronous)
486- self.settings_dialog.destroy()
487- else:
488- self.on_fail(action=_("Authentication failed"))
489- sys.stderr.write("Authentication failed.\n")
490
491=== removed file 'landscape/ui/controller/configuration.py'
492--- landscape/ui/controller/configuration.py 2012-03-23 09:39:56 +0000
493+++ landscape/ui/controller/configuration.py 1970-01-01 00:00:00 +0000
494@@ -1,122 +0,0 @@
495-import logging
496-
497-from gettext import gettext as _
498-
499-from landscape.ui.constants import NOT_MANAGED, CANONICAL_MANAGED
500-
501-from landscape.ui.model.registration.proxy import RegistrationProxy
502-from landscape.ui.model.configuration.state import StateError
503-
504-
505-class ConfigControllerLockError(Exception):
506- pass
507-
508-
509-class ConfigController(object):
510- """
511- L{ConfigContoller} defines actions to take against a configuration object,
512- providing starting values from the file, allowing them to be changed
513- transiently, reverted or committed.
514- """
515-
516- DEFAULT_DEDICATED_ACCOUNT_NAME = "standalone"
517-
518- def __init__(self, configuration):
519- self._observers = []
520- self._configuration = configuration
521- self._initialised = True
522-
523- def __getattr__(self, name):
524- if name in self.__dict__:
525- return self.__dict__[name]
526- else:
527- return getattr(self._configuration, name)
528-
529- def __setattr__(self, name, value):
530- # this test allows attributes to be set in the __init__ method
531- if not '_initialised' in self.__dict__:
532- return object.__setattr__(self, name, value)
533- if name in ConfigController.__dict__:
534- return object.__setattr__(self, name, value)
535- else:
536- try:
537- setattr(self._configuration, name, value)
538- self._configuration.modify()
539- except AttributeError:
540- return object.__setattr__(self, name, value)
541- else:
542- self._configuration.modify()
543-
544- def load(self):
545- """
546- Load the initial data from the configuration.
547- """
548- return self._configuration.load_data()
549-
550- def revert(self):
551- """
552- Revert settings to those the configuration object originally found.
553- """
554- try:
555- self._configuration.revert()
556- except StateError:
557- # We probably don't care.
558- logging.info("landscape-client-settings-ui reverted with no "
559- "changes to revert.")
560-
561- def persist(self, on_notify, on_error, on_succeed, on_fail):
562- """Persist settings via the configuration object."""
563- try:
564- self._configuration.persist()
565- except StateError:
566- # We probably don't care.
567- logging.info("landscape-client-settings-ui committed with no "
568- "changes to commit.")
569- if self._configuration.management_type == NOT_MANAGED:
570- self.disable(on_notify, on_succeed, on_fail)
571- else:
572- self.register(on_notify, on_error, on_succeed, on_fail)
573-
574- def register(self, notify_method, error_method, succeed_method,
575- fail_method):
576- """
577- Perform registration using the L{RegistrationProxy}.
578- """
579-
580- def registration_fail_wrapper():
581- fail_method(action=_("Registering client failed"))
582-
583- def registration_succeed_wrapper():
584- succeed_method(action=_("Registering client was successful"))
585-
586- registration = RegistrationProxy(
587- on_register_notify=notify_method,
588- on_register_error=error_method,
589- on_register_succeed=registration_succeed_wrapper,
590- on_register_fail=registration_fail_wrapper)
591- if self._configuration.management_type == CANONICAL_MANAGED:
592- notify_method(_("Attempting to register at %s") %
593- self._configuration.hosted_landscape_host)
594- else:
595- notify_method(_("Attempting to register at %s") %
596- self._configuration.local_landscape_host)
597- registration.register(self._configuration.get_config_filename())
598- registration.exit()
599-
600- def disable(self, notify_method, succeed_method, fail_method):
601- """
602- Disable landscape client via the L{RegistrationProxy}.
603- """
604-
605- def disabling_fail_wrapper():
606- fail_method(action=_("Disabling client failed"))
607-
608- def disabling_succeed_wrapper():
609- succeed_method(action=_("Disabling client was successful"))
610-
611- registration = RegistrationProxy(
612- on_disable_succeed=disabling_succeed_wrapper,
613- on_disable_fail=disabling_fail_wrapper)
614- notify_method(_("Attempting to disable landscape client."))
615- registration.disable()
616- registration.exit()
617
618=== removed directory 'landscape/ui/controller/tests'
619=== removed file 'landscape/ui/controller/tests/__init__.py'
620=== removed file 'landscape/ui/controller/tests/test_app.py'
621--- landscape/ui/controller/tests/test_app.py 2013-02-14 10:32:46 +0000
622+++ landscape/ui/controller/tests/test_app.py 1970-01-01 00:00:00 +0000
623@@ -1,135 +0,0 @@
624-import sys
625-
626-from landscape.ui.tests.helpers import (
627- ConfigurationProxyHelper, dbus_test_should_skip, dbus_skip_message,
628- FakeGSettings)
629-
630-if not dbus_test_should_skip:
631- from gi.repository import Gtk
632- from landscape.ui.controller.app import SettingsApplicationController
633- from landscape.ui.controller.configuration import ConfigController
634- from landscape.ui.view.configuration import ClientSettingsDialog
635- from landscape.ui.model.configuration.uisettings import UISettings
636-else:
637- SettingsApplicationController = object
638-
639-from landscape.tests.helpers import LandscapeTest
640-
641-
642-class ConnectionRecordingSettingsApplicationController(
643- SettingsApplicationController):
644- _connections = set()
645- _connection_args = {}
646- _connection_kwargs = {}
647-
648- def __init__(self, get_config=None, get_uisettings=None):
649- super(ConnectionRecordingSettingsApplicationController,
650- self).__init__()
651- if get_config:
652- self.get_config = get_config
653- if get_uisettings:
654- self.get_uisettings = get_uisettings
655-
656- def _make_connection_name(self, signal, func):
657- return signal + ">" + func.__name__
658-
659- def _record_connection(self, signal, func, *args, **kwargs):
660- connection_name = self._make_connection_name(signal, func)
661- self._connections.add(connection_name)
662- signal_connection_args = self._connection_args.get(
663- connection_name, [])
664- signal_connection_args.append(repr(args))
665- self._connection_args = signal_connection_args
666- signal_connection_kwargs = self._connection_kwargs.get(
667- connection_name, [])
668- signal_connection_kwargs.append(repr(kwargs))
669- self._connection_kwargs = signal_connection_kwargs
670-
671- def is_connected(self, signal, func):
672- connection_name = self._make_connection_name(signal, func)
673- return self._connections.issuperset(set([connection_name]))
674-
675- def connect(self, signal, func, *args, **kwargs):
676- self._record_connection(signal, func)
677-
678-
679-class SettingsApplicationControllerInitTest(LandscapeTest):
680-
681- def setUp(self):
682- super(SettingsApplicationControllerInitTest, self).setUp()
683-
684- def test_init(self):
685- """
686- Test we connect activate to something useful on application
687- initialisation.
688- """
689- app = ConnectionRecordingSettingsApplicationController()
690- self.assertTrue(app.is_connected("activate", app.setup_ui))
691-
692- if dbus_test_should_skip:
693- skip = dbus_skip_message
694-
695-
696-class SettingsApplicationControllerUISetupTest(LandscapeTest):
697-
698- helpers = [ConfigurationProxyHelper]
699-
700- def setUp(self):
701- self.config_string = "\n".join(
702- ["[client]",
703- "data_path = %s" % sys.path[0],
704- "http_proxy = http://proxy.localdomain:3192",
705- "tags = a_tag",
706- "url = https://landscape.canonical.com/message-system",
707- "account_name = foo",
708- "registration_key = bar",
709- "computer_title = baz",
710- "https_proxy = https://proxy.localdomain:6192",
711- "ping_url = http://landscape.canonical.com/ping"])
712- self.default_data = {"management-type": "not",
713- "computer-title": "",
714- "hosted-landscape-host": "",
715- "hosted-account-name": "",
716- "hosted-password": "",
717- "local-landscape-host": "",
718- "local-account-name": "",
719- "local-password": ""}
720- super(SettingsApplicationControllerUISetupTest, self).setUp()
721-
722- def fake_run(obj):
723- """
724- Retard X11 mapping.
725- """
726- pass
727-
728- self._real_run = Gtk.Dialog.run
729- Gtk.Dialog.run = fake_run
730-
731- def get_config():
732- return self.proxy
733-
734- def get_uisettings():
735- settings = FakeGSettings(data=self.default_data)
736- return UISettings(settings)
737-
738- self.app = ConnectionRecordingSettingsApplicationController(
739- get_config=get_config, get_uisettings=get_uisettings)
740-
741- def tearDown(self):
742- Gtk.Dialog.run = self._real_run
743- super(
744- SettingsApplicationControllerUISetupTest, self).tearDown()
745-
746- def test_setup_ui(self):
747- """
748- Test that we correctly setup the L{ClientSettingsDialog} with
749- the config object and correct data
750- """
751- self.assertRaises(SystemExit, self.app.setup_ui, data=None,
752- asynchronous=False)
753- self.assertIsInstance(self.app.settings_dialog, ClientSettingsDialog)
754- self.assertIsInstance(self.app.settings_dialog.controller,
755- ConfigController)
756-
757- if dbus_test_should_skip:
758- skip = dbus_skip_message
759
760=== removed file 'landscape/ui/controller/tests/test_configuration.py'
761--- landscape/ui/controller/tests/test_configuration.py 2013-02-14 10:32:46 +0000
762+++ landscape/ui/controller/tests/test_configuration.py 1970-01-01 00:00:00 +0000
763@@ -1,208 +0,0 @@
764-from landscape.ui.tests.helpers import (
765- ConfigurationProxyHelper, dbus_test_should_skip, dbus_skip_message,
766- FakeGSettings)
767-
768-if not dbus_test_should_skip:
769- from landscape.ui.controller.configuration import ConfigController
770- import landscape.ui.model.configuration.state
771- from landscape.ui.model.configuration.state import (
772- ConfigurationModel, COMPUTER_TITLE)
773- from landscape.ui.model.configuration.uisettings import UISettings
774-
775-from landscape.tests.helpers import LandscapeTest
776-
777-
778-class ConfigControllerTest(LandscapeTest):
779-
780- helpers = [ConfigurationProxyHelper]
781-
782- def setUp(self):
783- self.config_string = "\n".join(
784- ["[client]",
785- "data_path = /var/lib/landscape/client/",
786- "http_proxy = http://proxy.localdomain:3192",
787- "tags = a_tag",
788- "url = https://landscape.canonical.com/message-system",
789- "account_name = foo",
790- "registration_key = bar",
791- "computer_title = baz",
792- "https_proxy = https://proxy.localdomain:6192",
793- "ping_url = http://landscape.canonical.com/ping"])
794-
795- self.default_data = {"management-type": "canonical",
796- "computer-title": "",
797- "hosted-landscape-host": "",
798- "hosted-account-name": "",
799- "hosted-password": "",
800- "local-landscape-host": "",
801- "local-account-name": "",
802- "local-password": ""}
803-
804- super(ConfigControllerTest, self).setUp()
805- landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
806- = "me.here.com"
807- settings = FakeGSettings(data=self.default_data)
808- uisettings = UISettings(settings)
809- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
810-
811- def disable(on_suceed, on_fail):
812- pass
813-
814- def register(on_notify, on_error, on_succeed, on_fail):
815- pass
816-
817- self.controller = ConfigController(model)
818- self.controller.disable = disable
819- self.controller.register = register
820- self.controller.load()
821-
822- def test_init(self):
823- """
824- Test that when we create a controller it has initial state read in
825- directly from the configuration file.
826- """
827- self.controller.load()
828- self.assertEqual("baz", self.controller.computer_title)
829- self.assertTrue(self.controller.management_type)
830- self.assertEqual("landscape.canonical.com",
831- self.controller.hosted_landscape_host)
832- self.assertEqual("foo", self.controller.hosted_account_name)
833- self.assertEqual("bar", self.controller.hosted_password)
834- self.assertEqual("", self.controller.local_landscape_host)
835- self.assertEqual("standalone", self.controller.local_account_name)
836- self.assertEqual("", self.controller.local_password)
837-
838- def test_set_hosted_account_name(self):
839- """
840- Test that we can set the L{hosted_account_name} property.
841- """
842- self.controller.load()
843- self.assertEqual(self.controller.hosted_account_name, "foo")
844- self.controller.hosted_account_name = "shoe"
845- self.assertEqual(self.controller.hosted_account_name, "shoe")
846-
847- def test_set_local_account_name(self):
848- """
849- Test that we can set the L{local_account_name} property.
850- """
851- self.controller.load()
852- self.assertEqual("standalone", self.controller.local_account_name)
853- self.controller.local_account_name = "shoe"
854- self.assertEqual(self.controller.local_account_name, "shoe")
855-
856- def test_set_hosted_password(self):
857- """
858- Test that we can set the L{hosted_password} property.
859- """
860- self.controller.load()
861- self.assertEqual(self.controller.hosted_password, "bar")
862- self.controller.hosted_password = "nucker"
863- self.assertEqual(self.controller.hosted_password, "nucker")
864-
865- def test_set_local_password(self):
866- """
867- Test that we can set the L{local_password} property.
868- """
869- self.controller.load()
870- self.assertEqual(self.controller.local_password, "")
871- self.controller.local_password = "nucker"
872- self.assertEqual(self.controller.local_password, "nucker")
873-
874- def test_set_local_landscape_host(self):
875- """
876- Test that we can set the L{local_landscape_host} property.
877- """
878- self.controller.load()
879- self.assertEqual("", self.controller.local_landscape_host)
880- self.controller.local_landscape_host = "smelly.pants"
881- self.assertEqual(self.controller.local_landscape_host, "smelly.pants")
882-
883- def test_revert(self):
884- """
885- Test that we can revert the controller to it's initial state.
886- """
887- self.controller.load()
888- self.assertEqual(self.controller.hosted_account_name, "foo")
889- self.controller.hosted_account_name = "Hildaborg"
890- self.assertEqual(self.controller.hosted_account_name, "Hildaborg")
891- self.controller.revert()
892- self.assertEqual(self.controller.hosted_account_name, "foo")
893-
894- def test_is_modified(self):
895- """
896- Test that we can determine when something has been modified.
897- """
898- self.controller.load()
899- self.assertFalse(self.controller.is_modified)
900- self.controller.local_landscape_host = "bing.bang.a.bang"
901- self.assertTrue(self.controller.is_modified)
902- self.controller.revert()
903- self.assertFalse(self.controller.is_modified)
904- self.controller.account_name = "soldierBlue"
905- self.assertTrue(self.controller.is_modified)
906- self.controller.revert()
907- self.assertFalse(self.controller.is_modified)
908- self.controller.registration_key = "HesAnIndianCowboyInTheRodeo"
909- self.assertTrue(self.controller.is_modified)
910-
911- def test_persist(self):
912- """
913- Test that we can write configuration settings back to the config file.
914- """
915- self.controller.load()
916- self.assertEqual("", self.controller.local_landscape_host)
917- self.controller.local_landscape_host = "landscape.localdomain"
918- self.assertEqual("landscape.localdomain",
919- self.controller.local_landscape_host)
920- self.controller.persist(None, None, None, None)
921- self.assertEqual("landscape.localdomain",
922- self.controller.local_landscape_host)
923- self.controller.local_landscape_host = "boo"
924- self.controller.revert()
925- self.assertEqual("landscape.localdomain",
926- self.controller.local_landscape_host)
927-
928- if dbus_test_should_skip:
929- skip = dbus_skip_message
930-
931-
932-class EmptyConfigControllerTest(LandscapeTest):
933-
934- helpers = [ConfigurationProxyHelper]
935-
936- def setUp(self):
937- self.config_string = ""
938- self.default_data = {"management-type": "not",
939- "computer-title": "",
940- "hosted-landscape-host": "",
941- "hosted-account-name": "",
942- "hosted-password": "",
943- "local-landscape-host": "",
944- "local-account-name": "",
945- "local-password": ""}
946-
947- super(EmptyConfigControllerTest, self).setUp()
948- landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
949- = "me.here.com"
950- settings = FakeGSettings(data=self.default_data)
951- uisettings = UISettings(settings)
952- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
953- self.controller = ConfigController(model)
954- self.controller.load()
955-
956- def test_defaulting(self):
957- """
958- Test we set the correct values when loading a blank configuration.
959- """
960- self.controller.load()
961- self.assertEqual("not", self.controller.management_type)
962- self.assertEqual("", self.controller.hosted_account_name)
963- self.assertEqual("", self.controller.hosted_password)
964- self.assertEqual("landscape.canonical.com",
965- self.controller.hosted_landscape_host)
966- self.assertEqual("standalone", self.controller.local_account_name)
967- self.assertEqual("", self.controller.local_password)
968- self.assertEqual("me.here.com", self.controller.computer_title)
969-
970- if dbus_test_should_skip:
971- skip = dbus_skip_message
972
973=== removed directory 'landscape/ui/lib'
974=== removed file 'landscape/ui/lib/__init__.py'
975=== removed file 'landscape/ui/lib/polkit.py'
976--- landscape/ui/lib/polkit.py 2012-03-13 14:58:54 +0000
977+++ landscape/ui/lib/polkit.py 1970-01-01 00:00:00 +0000
978@@ -1,102 +0,0 @@
979-import dbus
980-import dbus.service
981-import dbus.glib
982-
983-from gi.repository import GObject
984-
985-
986-POLICY_NAME = "com.canonical.LandscapeClientSettings.configure"
987-
988-
989-class PolicyKitMechanism(dbus.service.Object):
990- """
991- L{PolicyKitMechanism} is a specialised L{dbus.service.Object} which
992- provides PolicyKit authorization checks for a provided DBus bus name and
993- object path. Subclasses must therefore call l{__init__} here with their
994- object path, bus name and an error class to be raised when permission
995- escalation fails.
996-
997- @type object_path: string
998- @param object_path: The object path to register the subclass with.
999- @type bus_name: dbus.service.BusName
1000- @param bus_name: The L{BusName} to the register the subclass with.
1001- @type permission_error: dbus.DBusException
1002- @param permission_error: A L{dbus.DBusException} to be raised when
1003- PolicyKit authorisation fails for the client.
1004- """
1005-
1006- def __init__(self, object_path, bus_name, permission_error,
1007- bypass=False, conn=None):
1008- super(PolicyKitMechanism, self).__init__(
1009- conn, object_path, bus_name)
1010- self.permission_error = permission_error
1011- self.dbus_info = None
1012- self.polkit = None
1013- self.bypass = bypass
1014-
1015- def _get_polkit_authorization(self, pid, privilege):
1016- """
1017- Check that the process with id L{pid} is allowed, by policy to utilise
1018- the L{privilege }. If the class was initialised with L{bypass}=True
1019- then just say it was authorised without checking (useful for testing).
1020- """
1021- if self.bypass:
1022- return (True, None, "Bypass")
1023- polkit = dbus.Interface(dbus.SystemBus().get_object(
1024- 'org.freedesktop.PolicyKit1',
1025- '/org/freedesktop/PolicyKit1/Authority', False),
1026- 'org.freedesktop.PolicyKit1.Authority')
1027- subject = ('unix-process',
1028- {'pid': dbus.UInt32(pid, variant_level=1),
1029- 'start-time': dbus.UInt64(0, variant_level=1)})
1030- action_id = privilege
1031- details = {"": ""} # <- empty strings allow type inference
1032- flags = dbus.UInt32(1)
1033- cancellation_id = ""
1034- return polkit.CheckAuthorization(
1035- subject,
1036- action_id,
1037- details,
1038- flags,
1039- cancellation_id,
1040- timeout=15)
1041-
1042- def _get_peer_pid(self, sender, conn):
1043- """
1044- Get the process ID of the L{sender}.
1045- """
1046- if self.dbus_info is None:
1047- self.dbus_info = dbus.Interface(
1048- conn.get_object('org.freedesktop.DBus',
1049- '/org/freedesktop/DBus/Bus', False), 'org.freedesktop.DBus')
1050- return self.dbus_info.GetConnectionUnixProcessID(sender)
1051-
1052- def _is_local_call(self, sender, conn):
1053- """
1054- Check if this is a local call, implying it is within a secure context.
1055- """
1056- return (sender is None and conn is None)
1057-
1058- def _is_allowed_by_policy(self, sender, conn, privilege):
1059- """
1060- Check if we are already in a secure context, and if not check if the
1061- policy associated with L{privilege} both exists and allows the peer to
1062- utilise it. As a side effect, if escalation of privileges is required
1063- then this will occur and a challenge will be generated if needs be.
1064- """
1065- if self._is_local_call(sender, conn):
1066- return True
1067- peer_pid = self._get_peer_pid(sender, conn)
1068- (is_auth, _, details) = self._get_polkit_authorization(peer_pid,
1069- privilege)
1070- if not is_auth:
1071- raise self.permission_error(privilege)
1072- return True
1073-
1074-
1075-def listen():
1076- """
1077- Invoke a L{gobject.MainLoop} to process incoming DBus events.
1078- """
1079- mainloop = GObject.MainLoop()
1080- mainloop.run()
1081
1082=== removed directory 'landscape/ui/model'
1083=== removed file 'landscape/ui/model/__init__.py'
1084=== removed directory 'landscape/ui/model/configuration'
1085=== removed file 'landscape/ui/model/configuration/__init__.py'
1086=== removed file 'landscape/ui/model/configuration/mechanism.py'
1087--- landscape/ui/model/configuration/mechanism.py 2012-03-15 17:07:33 +0000
1088+++ landscape/ui/model/configuration/mechanism.py 1970-01-01 00:00:00 +0000
1089@@ -1,113 +0,0 @@
1090-import sys
1091-
1092-import dbus
1093-import dbus.service
1094-
1095-from landscape.ui.lib.polkit import PolicyKitMechanism, POLICY_NAME
1096-
1097-
1098-SERVICE_NAME = "com.canonical.LandscapeClientSettings"
1099-INTERFACE_NAME = "com.canonical.LandscapeClientSettings.ConfigurationInterface"
1100-OBJECT_PATH = "/com/canonical/LandscapeClientSettings/ConfigurationInterface"
1101-
1102-
1103-class PermissionDeniedByPolicy(dbus.DBusException):
1104- _dbus_error_name = \
1105- "com.canonical.LandscapeClientSettings.PermissionDeniedByPolicy"
1106-
1107-
1108-class ConfigurationMechanism(PolicyKitMechanism):
1109- """
1110- L{ConfigurationMechanism} provides access to the
1111- L{LandscapeSetupConfiguration} object via DBus with access control
1112- implemented via PolicyKit policy. The use of DBus results from the use of
1113- PolicyKit, not the other way around, and is done that way because that is
1114- considered to be the Right Thing for Ubuntu Desktop circa January 2012.
1115- """
1116-
1117- def __init__(self, config, bus_name, bypass=False, conn=None):
1118- super(ConfigurationMechanism, self).__init__(
1119- OBJECT_PATH, bus_name, PermissionDeniedByPolicy,
1120- bypass=bypass, conn=conn)
1121- self._config = config
1122-
1123- @dbus.service.method(INTERFACE_NAME,
1124- in_signature="as",
1125- out_signature="",
1126- sender_keyword="sender",
1127- connection_keyword="conn")
1128- def load(self, arglist, sender=None, conn=None):
1129- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
1130- if len(arglist) > 0:
1131- self._config.load(arglist.split(chr(0x1e)))
1132- else:
1133- self._config.load([])
1134- return
1135-
1136- @dbus.service.method(INTERFACE_NAME,
1137- in_signature="", out_signature="",
1138- sender_keyword="sender", connection_keyword="conn")
1139- def reload(self, sender=None, conn=None):
1140- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
1141- self._config.reload()
1142-
1143- @dbus.service.method(INTERFACE_NAME,
1144- in_signature="", out_signature="",
1145- sender_keyword="sender", connection_keyword="conn")
1146- def write(self, sender=None, conn=None):
1147- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
1148- self._config.write()
1149-
1150- @dbus.service.method(INTERFACE_NAME,
1151- in_signature="",
1152- out_signature="s",
1153- sender_keyword="sender",
1154- connection_keyword="conn")
1155- def get_config_filename(self, sender=None, conn=None):
1156- return self._config.get_config_filename()
1157-
1158- @dbus.service.method(INTERFACE_NAME,
1159- in_signature="s",
1160- out_signature="s",
1161- sender_keyword="sender",
1162- connection_keyword="conn")
1163- def get(self, name, sender=None, conn=None):
1164- """
1165- Return the configuration option value associated with L{name} from the
1166- L{LandscapeSetupConfiguration}.
1167- """
1168- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
1169- try:
1170- value = self._config.get(name)
1171- except AttributeError:
1172- return ""
1173- if value is None:
1174- return ""
1175- return str(value)
1176- return ""
1177-
1178- @dbus.service.method(INTERFACE_NAME,
1179- in_signature="ss",
1180- out_signature="",
1181- sender_keyword="sender",
1182- connection_keyword="conn")
1183- def set(self, name, value, sender=None, conn=None):
1184- """
1185- Set the configuration option associated with L{name} to L{value} in the
1186- L{LandscapeSetupConfiguration}.
1187- """
1188- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
1189- # Underlying _config does not support unicode so convert to ascii
1190- value = unicode(value).encode("ascii", errors="replace")
1191- setattr(self._config, name, value)
1192-
1193- @dbus.service.method(INTERFACE_NAME,
1194- in_signature="",
1195- out_signature="",
1196- sender_keyword="sender",
1197- connection_keyword="conn")
1198- def exit(self, sender=None, conn=None):
1199- """
1200- Exit this process.
1201- """
1202- sys.exit(0)
1203
1204=== removed file 'landscape/ui/model/configuration/proxy.py'
1205--- landscape/ui/model/configuration/proxy.py 2012-05-15 17:30:38 +0000
1206+++ landscape/ui/model/configuration/proxy.py 1970-01-01 00:00:00 +0000
1207@@ -1,110 +0,0 @@
1208-"""
1209-This module contains a class, L{ConfigurationProxy} which pretends to be a
1210-L{landscape.configuration.LandscapeSetupConfiguration} but actually directs
1211-its calls via DBus to the L{ConfigurationMechanism}.
1212-"""
1213-
1214-import dbus
1215-
1216-from landscape.ui.model.configuration.mechanism import (
1217- SERVICE_NAME, INTERFACE_NAME, OBJECT_PATH)
1218-from landscape.configuration import LandscapeSetupConfiguration
1219-
1220-
1221-class ConfigurationProxy(object):
1222- """
1223- L{ConfigurationProxy} attempts to be a drop-in replacement for
1224- L{LandscapeSetupConfiguration} allowing applications run by user accounts
1225- with the correct rights (as defined by a PolicyKit policy file) to interact
1226- with the landscape client configuration via a DBus service. This is the
1227- RightThing(TM) for PolicyKit and therefore for GNOME/Unity.
1228-
1229- The canonical case for this is L{landscape-client-settings-ui}.
1230- """
1231-
1232- def __init__(self, bus=None, interface=None, loadargs=[]):
1233- self._loadargs = loadargs
1234- if bus is None:
1235- self._bus = dbus.SystemBus()
1236- else:
1237- self._bus = bus
1238- if interface is None:
1239- remote_object = self._bus.get_object(SERVICE_NAME, OBJECT_PATH)
1240- self._interface = dbus.Interface(remote_object, INTERFACE_NAME)
1241- else:
1242- self._interface = interface
1243-
1244- def load(self, arglist):
1245- if arglist is None:
1246- arglist = self._loadargs
1247- if len(arglist) == 0:
1248- al = ""
1249- else:
1250- al = chr(0x1e).join(arglist)
1251- try:
1252- self._interface.load(al)
1253- except dbus.DBusException, e:
1254- error_name = e.get_dbus_name()
1255- if error_name not in ("com.canonical.LandscapeClientSettings."
1256- "PermissionDeniedByPolicy",
1257- "org.freedesktop.DBus.Error.NoReply"):
1258- raise
1259- return False
1260- return True
1261- load.__doc__ = LandscapeSetupConfiguration.load.__doc__
1262-
1263- def reload(self):
1264- self._interface.reload()
1265- reload.__doc__ = LandscapeSetupConfiguration.reload.__doc__
1266-
1267- def write(self):
1268- self._interface.write()
1269- write.__doc__ = LandscapeSetupConfiguration.write.__doc__
1270-
1271- def get_config_filename(self):
1272- return self._interface.get_config_filename()
1273- get_config_filename.__doc__ = \
1274- LandscapeSetupConfiguration.get_config_filename.__doc__
1275-
1276- def exit(self, asynchronous=True):
1277- """
1278- Cause the mechanism to exit.
1279- """
1280- def on_reply():
1281- """
1282- This will never get called because we call L{sys.exit} inside the
1283- mechanism.
1284- """
1285-
1286- def on_error():
1287- """
1288- This will always be called, this allows us to supress the
1289- L{NoReply} error from DBus when we terminate the mechanism.
1290- """
1291-
1292- if asynchronous:
1293- self._interface.exit(reply_handler=on_reply,
1294- error_handler=on_error)
1295- else:
1296- self._interface.exit()
1297-
1298- def _delegate_to_interface(field):
1299-
1300- def get(self):
1301- return self._interface.get(field)
1302-
1303- def set(self, value):
1304- self._interface.set(field, value)
1305-
1306- return get, set
1307-
1308- account_name = property(*_delegate_to_interface("account_name"))
1309- computer_title = property(*_delegate_to_interface("computer_title"))
1310- data_path = property(*_delegate_to_interface("data_path"))
1311- http_proxy = property(*_delegate_to_interface("http_proxy"))
1312- https_proxy = property(*_delegate_to_interface("https_proxy"))
1313- ping_url = property(*_delegate_to_interface("ping_url"))
1314- registration_key = property(
1315- *_delegate_to_interface("registration_key"))
1316- tags = property(*_delegate_to_interface("tags"))
1317- url = property(*_delegate_to_interface("url"))
1318
1319=== removed file 'landscape/ui/model/configuration/state.py'
1320--- landscape/ui/model/configuration/state.py 2012-05-15 17:30:38 +0000
1321+++ landscape/ui/model/configuration/state.py 1970-01-01 00:00:00 +0000
1322@@ -1,586 +0,0 @@
1323-import copy
1324-
1325-from landscape.lib.network import get_fqdn
1326-
1327-from landscape.ui.constants import CANONICAL_MANAGED, NOT_MANAGED
1328-from landscape.ui.model.configuration.proxy import ConfigurationProxy
1329-
1330-
1331-HOSTED_LANDSCAPE_HOST = "landscape.canonical.com"
1332-LOCAL_LANDSCAPE_HOST = ""
1333-
1334-HOSTED_ACCOUNT_NAME = ""
1335-LOCAL_ACCOUNT_NAME = "standalone"
1336-
1337-HOSTED_PASSWORD = ""
1338-LOCAL_PASSWORD = ""
1339-
1340-HOSTED = "hosted"
1341-LOCAL = "local"
1342-MANAGEMENT_TYPE = "management-type"
1343-COMPUTER_TITLE = "computer-title"
1344-LANDSCAPE_HOST = "landscape-host"
1345-ACCOUNT_NAME = "account-name"
1346-PASSWORD = "password"
1347-
1348-
1349-DEFAULT_DATA = {
1350- MANAGEMENT_TYPE: NOT_MANAGED,
1351- COMPUTER_TITLE: get_fqdn(),
1352- HOSTED: {
1353- LANDSCAPE_HOST: HOSTED_LANDSCAPE_HOST,
1354- ACCOUNT_NAME: HOSTED_ACCOUNT_NAME,
1355- PASSWORD: HOSTED_PASSWORD},
1356- LOCAL: {
1357- LANDSCAPE_HOST: LOCAL_LANDSCAPE_HOST,
1358- ACCOUNT_NAME: LOCAL_ACCOUNT_NAME,
1359- PASSWORD: LOCAL_PASSWORD}}
1360-
1361-
1362-def derive_server_host_name_from_url(url):
1363- """
1364- Extract the hostname part from a URL.
1365- """
1366- try:
1367- without_protocol = url[url.index("://") + 3:]
1368- except ValueError:
1369- without_protocol = url
1370- try:
1371- return without_protocol[:without_protocol.index("/")]
1372- except ValueError:
1373- return without_protocol
1374-
1375-
1376-def derive_url_from_host_name(host_name):
1377- """
1378- Extrapolate a url from a host name.
1379- """
1380- #Reuse this code to make sure it's a proper host name
1381- host_name = derive_server_host_name_from_url(host_name)
1382- return "https://" + host_name + "/message-system"
1383-
1384-
1385-def derive_ping_url_from_host_name(host_name):
1386- """
1387- Extrapolate a ping_url from a host name.
1388- """
1389- #Reuse this code to make sure it's a proper host name
1390- host_name = derive_server_host_name_from_url(host_name)
1391- return "http://" + host_name + "/ping"
1392-
1393-
1394-class StateError(Exception):
1395- """
1396- An exception that is raised when there is an error relating to the current
1397- state.
1398- """
1399-
1400-
1401-class TransitionError(Exception):
1402- """
1403- An L{Exception} that is raised when a valid transition between states fails
1404- for some non state related reason. For example, this error is raised when
1405- the user does not have the privilege of reading the configuration file,
1406- this causes the transition from L{VirginState} to L{InitialisedState} to
1407- fail but not because that transition from one state to another was not
1408- permitted, but rather the transition encountered an error.
1409- """
1410-
1411-
1412-class ConfigurationState(object):
1413- """
1414- Base class for states used in the L{ConfigurationModel}.
1415- """
1416- def __init__(self, data, proxy, uisettings):
1417- self._data = copy.deepcopy(data)
1418- self._proxy = proxy
1419- self._uisettings = uisettings
1420-
1421- def get_config_filename(self):
1422- return self._proxy.get_config_filename()
1423-
1424- def get(self, *args):
1425- """
1426- Retrieve only valid values from two level dictionary based tree.
1427-
1428- This mainly served to pick up programming errors and could easily be
1429- replaced with a simpler scheme.
1430- """
1431- arglen = len(args)
1432- if arglen > 2 or arglen == 0:
1433- raise TypeError(
1434- "get() takes either 1 or 2 keys (%d given)" % arglen)
1435- if arglen == 2: # We're looking for a leaf on a branch
1436- sub_dict = None
1437- if args[0] in [HOSTED, LOCAL]:
1438- sub_dict = self._data.get(args[0], {})
1439- sub_dict = self._data[args[0]]
1440- if not isinstance(sub_dict, dict):
1441- raise KeyError(
1442- "Compound key [%s][%s] is invalid. The data type " +
1443- "returned from the first index was %s." %
1444- sub_dict.__class__.__name__)
1445- return sub_dict.get(args[1], None)
1446- else:
1447- if args[0] in (MANAGEMENT_TYPE, COMPUTER_TITLE):
1448- return self._data.get(args[0], None)
1449- else:
1450- raise KeyError("Key [%s] is invalid. " % args[0])
1451-
1452- def set(self, *args):
1453- """
1454- Set only valid values from two level dictionary based tree.
1455-
1456- This mainly served to pick up programming errors and could easily be
1457- replaced with a simpler scheme.
1458- """
1459- arglen = len(args)
1460- if arglen < 2 or arglen > 3:
1461- raise TypeError("set() takes either 1 or 2 keys and exactly 1 " +
1462- "value (%d arguments given)" % arglen)
1463- if arglen == 2: # We're setting a leaf attached to the root
1464- self._data[args[0]] = args[1]
1465- else: # We're setting a leaf on a branch
1466- sub_dict = None
1467- if args[0] in [HOSTED, LOCAL]:
1468- sub_dict = self._data.get(args[0], {})
1469- if not isinstance(sub_dict, dict):
1470- raise KeyError("Compound key [%s][%s] is invalid. The data " +
1471- "type returned from the first index was %s."
1472- % sub_dict.__class__.__name__)
1473- sub_dict[args[1]] = args[2]
1474- self._data[args[0]] = sub_dict
1475-
1476- def load_data(self, asynchronous=True, exit_method=None):
1477- raise NotImplementedError
1478-
1479- def modify(self):
1480- raise NotImplementedError
1481-
1482- def revert(self):
1483- raise NotImplementedError
1484-
1485- def persist(self):
1486- raise NotImplementedError
1487-
1488- def exit(self, asynchronous=True, exit_method=None):
1489- return ExitedState(self._data, self._proxy, self._uisettings,
1490- asynchronous=asynchronous, exit_method=exit_method)
1491-
1492-
1493-class Helper(object):
1494- """
1495- Base class for all state transition helpers.
1496-
1497- It is assumed that the Helper classes are "friends" of the
1498- L{ConfigurationState} classes and can have some knowledge of their
1499- internals. They shouldn't be visible to users of the
1500- L{ConfigurationState}s and in general we should avoid seeing the
1501- L{ConfigurationState}'s _data attribute outside this module.
1502- """
1503-
1504- def __init__(self, state):
1505- self._state = state
1506-
1507-
1508-class ModifiableHelper(Helper):
1509- """
1510- Allow a L{ConfigurationState}s to be modified.
1511- """
1512-
1513- def modify(self):
1514- return ModifiedState(self._state._data, self._state._proxy,
1515- self._state._uisettings)
1516-
1517-
1518-class UnloadableHelper(Helper):
1519- """
1520- Disallow loading of data into a L{ConfigurationModel}.
1521- """
1522-
1523- def load_data(self, asynchronous=True, exit_method=None):
1524- raise StateError("A ConfiguratiomModel in a " +
1525- self.__class__.__name__ +
1526- " cannot be transitioned via load_data()")
1527-
1528-
1529-class UnmodifiableHelper(Helper):
1530- """
1531- Disallow modification of a L{ConfigurationState}.
1532- """
1533-
1534- def modify(self):
1535- raise StateError("A ConfigurationModel in " +
1536- self.__class__.__name__ +
1537- " cannot transition via modify()")
1538-
1539-
1540-class RevertableHelper(Helper):
1541- """
1542- Allow reverting of a L{ConfigurationModel}.
1543- """
1544-
1545- def revert(self):
1546- return InitialisedState(self._state._data, self._state._proxy,
1547- self._state._uisettings)
1548-
1549-
1550-class UnrevertableHelper(Helper):
1551- """
1552- Disallow reverting of a L{ConfigurationModel}.
1553- """
1554-
1555- def revert(self):
1556- raise StateError("A ConfigurationModel in " +
1557- self.__class__.__name__ +
1558- " cannot transition via revert()")
1559-
1560-
1561-class PersistableHelper(Helper):
1562- """
1563- Allow a L{ConfigurationModel} to persist.
1564- """
1565-
1566- def _save_to_uisettings(self):
1567- """
1568- Persist full content to the L{UISettings} object.
1569- """
1570- self._state._uisettings.set_management_type(
1571- self._state.get(MANAGEMENT_TYPE))
1572- self._state._uisettings.set_computer_title(
1573- self._state.get(COMPUTER_TITLE))
1574- self._state._uisettings.set_hosted_account_name(
1575- self._state.get(HOSTED, ACCOUNT_NAME))
1576- self._state._uisettings.set_hosted_password(
1577- self._state.get(HOSTED, PASSWORD))
1578- self._state._uisettings.set_local_landscape_host(
1579- self._state.get(LOCAL, LANDSCAPE_HOST))
1580- self._state._uisettings.set_local_account_name(
1581- self._state.get(LOCAL, ACCOUNT_NAME))
1582- self._state._uisettings.set_local_password(
1583- self._state.get(LOCAL, PASSWORD))
1584-
1585- def _save_to_config(self):
1586- """
1587- Persist the subset of the data we want to make live to the actual
1588- configuration file.
1589- """
1590- hosted = self._state.get(MANAGEMENT_TYPE)
1591- if hosted is NOT_MANAGED:
1592- pass
1593- else:
1594- if hosted == CANONICAL_MANAGED:
1595- first_key = HOSTED
1596- else:
1597- first_key = LOCAL
1598- self._state._proxy.url = derive_url_from_host_name(
1599- self._state.get(first_key, LANDSCAPE_HOST))
1600- self._state._proxy.ping_url = derive_ping_url_from_host_name(
1601- self._state.get(first_key, LANDSCAPE_HOST))
1602- self._state._proxy.account_name = self._state.get(
1603- first_key, ACCOUNT_NAME)
1604- self._state._proxy.registration_key = self._state.get(
1605- first_key, PASSWORD)
1606- self._state._proxy.computer_title = self._state.get(COMPUTER_TITLE)
1607- self._state._proxy.write()
1608-
1609- def persist(self):
1610- self._save_to_uisettings()
1611- self._save_to_config()
1612- return InitialisedState(self._state._data, self._state._proxy,
1613- self._state._uisettings)
1614-
1615-
1616-class UnpersistableHelper(Helper):
1617- """
1618- Disallow persistence of a L{ConfigurationModel}.
1619- """
1620-
1621- def persist(self):
1622- raise StateError("A ConfiguratonModel in " +
1623- self.__class__.__name__ +
1624- " cannot be transitioned via persist().")
1625-
1626-
1627-class ExitedState(ConfigurationState):
1628- """
1629- The terminal state of L{ConfigurationModel}, you can't do anything further
1630- once this state is reached.
1631- """
1632- def __init__(self, data, proxy, uisettings, exit_method=None,
1633- asynchronous=True):
1634- super(ExitedState, self).__init__(None, None, None)
1635- if callable(exit_method):
1636- exit_method()
1637- else:
1638- proxy.exit(asynchronous=asynchronous)
1639- self._unloadable_helper = UnloadableHelper(self)
1640- self._unmodifiable_helper = UnmodifiableHelper(self)
1641- self._unrevertable_helper = UnrevertableHelper(self)
1642- self._unpersistable_helper = UnpersistableHelper(self)
1643-
1644- def load_data(self, asynchronous=True, exit_method=None):
1645- return self._unloadable_helper.load_data(asynchronous=asynchronous,
1646- exit_method=exit_method)
1647-
1648- def modify(self):
1649- return self._unmodifiable_helper.modify()
1650-
1651- def revert(self):
1652- return self._unrevertable_helper.revert()
1653-
1654- def persist(self):
1655- return self._unpersistable_helper.persist()
1656-
1657- def exit(self, asynchronous=True):
1658- return self
1659-
1660-
1661-class ModifiedState(ConfigurationState):
1662- """
1663- The state of a L{ConfigurationModel} whenever the user has modified some
1664- data but hasn't yet L{persist}ed or L{revert}ed.
1665- """
1666-
1667- def __init__(self, data, proxy, uisettings):
1668- super(ModifiedState, self).__init__(data, proxy, uisettings)
1669- self._modifiable_helper = ModifiableHelper(self)
1670- self._revertable_helper = RevertableHelper(self)
1671- self._persistable_helper = PersistableHelper(self)
1672-
1673- def modify(self):
1674- return self._modifiable_helper.modify()
1675-
1676- def revert(self):
1677- return self._revertable_helper.revert()
1678-
1679- def persist(self):
1680- return self._persistable_helper.persist()
1681-
1682-
1683-class InitialisedState(ConfigurationState):
1684- """
1685- The state of the L{ConfigurationModel} as initially presented to the
1686- user. Baseline data should have been loaded from the real configuration
1687- data, any persisted user data should be loaded into blank values and
1688- finally defaults should be applied where necessary.
1689- """
1690-
1691- def __init__(self, data, proxy, uisettings):
1692- super(InitialisedState, self).__init__(data, proxy, uisettings)
1693- self._modifiable_helper = ModifiableHelper(self)
1694- self._unrevertable_helper = UnrevertableHelper(self)
1695- self._unpersistable_helper = UnpersistableHelper(self)
1696- self._load_uisettings_data()
1697- if not self._load_live_data():
1698- raise TransitionError("Authentication Failure")
1699-
1700- def _load_uisettings_data(self):
1701- """
1702- Load the complete set of dialog data from L{UISettings}.
1703- """
1704- hosted = self._uisettings.get_management_type()
1705- self.set(MANAGEMENT_TYPE, hosted)
1706- computer_title = self._uisettings.get_computer_title()
1707- if computer_title:
1708- self.set(COMPUTER_TITLE, computer_title)
1709- self.set(HOSTED, ACCOUNT_NAME,
1710- self._uisettings.get_hosted_account_name())
1711- self.set(HOSTED, PASSWORD, self._uisettings.get_hosted_password())
1712- self.set(LOCAL, LANDSCAPE_HOST,
1713- self._uisettings.get_local_landscape_host())
1714- local_account_name = self._uisettings.get_local_account_name()
1715- if local_account_name:
1716- self.set(LOCAL, ACCOUNT_NAME, local_account_name)
1717- self.set(LOCAL, PASSWORD, self._uisettings.get_local_password())
1718-
1719- def _load_live_data(self):
1720- """
1721- Load the current live subset of data from the configuration file.
1722- """
1723- if self._proxy.load(None):
1724- computer_title = self._proxy.computer_title
1725- if computer_title:
1726- self.set(COMPUTER_TITLE, computer_title)
1727- url = self._proxy.url
1728- if url.find(HOSTED_LANDSCAPE_HOST) > -1:
1729- self.set(HOSTED, ACCOUNT_NAME, self._proxy.account_name)
1730- self.set(HOSTED, PASSWORD, self._proxy.registration_key)
1731- else:
1732- self.set(LOCAL, LANDSCAPE_HOST,
1733- derive_server_host_name_from_url(url))
1734- if self._proxy.account_name != "":
1735- self.set(LOCAL, ACCOUNT_NAME, self._proxy.account_name)
1736- return True
1737- else:
1738- return False
1739-
1740- def load_data(self, asynchronous=True, exit_method=None):
1741- return self
1742-
1743- def modify(self):
1744- return self._modifiable_helper.modify()
1745-
1746- def revert(self):
1747- return self._unrevertable_helper.revert()
1748-
1749- def persist(self):
1750- return self._unpersistable_helper.persist()
1751-
1752-
1753-class VirginState(ConfigurationState):
1754- """
1755- The state of the L{ConfigurationModel} before any actions have been taken
1756- upon it.
1757- """
1758-
1759- def __init__(self, proxy, uisettings):
1760- super(VirginState, self).__init__(DEFAULT_DATA, proxy, uisettings)
1761- self._unmodifiable_helper = UnmodifiableHelper(self)
1762- self._unrevertable_helper = UnrevertableHelper(self)
1763- self._unpersistable_helper = UnpersistableHelper(self)
1764-
1765- def load_data(self, asynchronous=True, exit_method=None):
1766- try:
1767- return InitialisedState(self._data, self._proxy, self._uisettings)
1768- except TransitionError:
1769- return ExitedState(self._data, self._proxy, self._uisettings,
1770- asynchronous=asynchronous,
1771- exit_method=exit_method)
1772-
1773- def modify(self):
1774- return self._unmodifiable_helper.modify()
1775-
1776- def revert(self):
1777- return self._unrevertable_helper.revert()
1778-
1779- def persist(self):
1780- return self._unpersistable_helper.persist()
1781-
1782-
1783-class ConfigurationModel(object):
1784- """
1785- L{ConfigurationModel} presents a model of configuration as the UI
1786- requirements describe it (separate values for the Hosted and Local
1787- configurations) as opposed to the real structure of the configuration
1788- file. This is intended to achieve the following:
1789-
1790- 1. Allow the expected behaviour in the UI without changing the live
1791- config file.
1792- 2. Supersede the overly complex logic in the controller layer with a
1793- cleaner state pattern.
1794-
1795- The allowable state transitions are:
1796-
1797- VirginState --(load_data)--> InitialisedState
1798- VirginState --(load_data)--> ExitedState
1799- VirginState --(exit)-------> ExitedState
1800- InitialisedState --(modify)-----> ModifiedState
1801- InitialisedState --(exit)-------> ExitedState
1802- ModifiedState --(revert)-----> InitialisedState
1803- ModifiedState --(modify)-----> ModifiedState
1804- ModifiedState --(persist)----> InitialisedState
1805- ModifiedState --(exit)-------> ExitedState
1806- """
1807-
1808- def __init__(self, proxy=None, proxy_loadargs=[], uisettings=None):
1809- if not proxy:
1810- proxy = ConfigurationProxy(loadargs=proxy_loadargs)
1811- self._current_state = VirginState(proxy, uisettings)
1812-
1813- def get_state(self):
1814- """
1815- Expose the underlying L{ConfigurationState}, for testing purposes.
1816- """
1817- return self._current_state
1818-
1819- def load_data(self, asynchronous=True, exit_method=None):
1820- self._current_state = self._current_state.load_data(
1821- asynchronous=asynchronous, exit_method=exit_method)
1822- return isinstance(self._current_state, InitialisedState)
1823-
1824- def modify(self):
1825- self._current_state = self._current_state.modify()
1826-
1827- def revert(self):
1828- self._current_state = self._current_state.revert()
1829-
1830- def persist(self):
1831- self._current_state = self._current_state.persist()
1832-
1833- def _get_management_type(self):
1834- return self._current_state.get(MANAGEMENT_TYPE)
1835-
1836- def _set_management_type(self, value):
1837- self._current_state.set(MANAGEMENT_TYPE, value)
1838-
1839- management_type = property(_get_management_type, _set_management_type)
1840-
1841- def _get_computer_title(self):
1842- return self._current_state.get(COMPUTER_TITLE)
1843-
1844- def _set_computer_title(self, value):
1845- self._current_state.set(COMPUTER_TITLE, value)
1846-
1847- computer_title = property(_get_computer_title, _set_computer_title)
1848-
1849- def _get_hosted_landscape_host(self):
1850- return self._current_state.get(HOSTED, LANDSCAPE_HOST)
1851-
1852- hosted_landscape_host = property(_get_hosted_landscape_host)
1853-
1854- def _get_local_landscape_host(self):
1855- return self._current_state.get(LOCAL, LANDSCAPE_HOST)
1856-
1857- def _set_local_landscape_host(self, value):
1858- self._current_state.set(LOCAL, LANDSCAPE_HOST, value)
1859-
1860- local_landscape_host = property(_get_local_landscape_host,
1861- _set_local_landscape_host)
1862-
1863- def _get_hosted_account_name(self):
1864- return self._current_state.get(HOSTED, ACCOUNT_NAME)
1865-
1866- def _set_hosted_account_name(self, value):
1867- self._current_state.set(HOSTED, ACCOUNT_NAME, value)
1868-
1869- hosted_account_name = property(_get_hosted_account_name,
1870- _set_hosted_account_name)
1871-
1872- def _get_local_account_name(self):
1873- return self._current_state.get(LOCAL, ACCOUNT_NAME)
1874-
1875- def _set_local_account_name(self, value):
1876- self._current_state.set(LOCAL, ACCOUNT_NAME, value)
1877-
1878- local_account_name = property(_get_local_account_name,
1879- _set_local_account_name)
1880-
1881- def _get_hosted_password(self):
1882- return self._current_state.get(HOSTED, PASSWORD)
1883-
1884- def _set_hosted_password(self, value):
1885- self._current_state.set(HOSTED, PASSWORD, value)
1886-
1887- hosted_password = property(_get_hosted_password,
1888- _set_hosted_password)
1889-
1890- def _get_local_password(self):
1891- return self._current_state.get(LOCAL, PASSWORD)
1892-
1893- def _set_local_password(self, value):
1894- self._current_state.set(LOCAL, PASSWORD, value)
1895-
1896- local_password = property(_get_local_password,
1897- _set_local_password)
1898-
1899- def _get_is_modified(self):
1900- return isinstance(self.get_state(), ModifiedState)
1901-
1902- is_modified = property(_get_is_modified)
1903-
1904- def get_config_filename(self):
1905- return self._current_state.get_config_filename()
1906-
1907- def exit(self, asynchronous=True):
1908- self._current_state.exit(asynchronous=asynchronous)
1909
1910=== removed directory 'landscape/ui/model/configuration/tests'
1911=== removed file 'landscape/ui/model/configuration/tests/__init__.py'
1912=== removed file 'landscape/ui/model/configuration/tests/test_mechanism.py'
1913--- landscape/ui/model/configuration/tests/test_mechanism.py 2013-09-16 14:39:23 +0000
1914+++ landscape/ui/model/configuration/tests/test_mechanism.py 1970-01-01 00:00:00 +0000
1915@@ -1,201 +0,0 @@
1916-from landscape.configuration import LandscapeSetupConfiguration
1917-from landscape.tests.helpers import LandscapeTest
1918-from landscape.ui.tests.helpers import (
1919- dbus_test_should_skip, dbus_skip_message)
1920-if not dbus_test_should_skip:
1921- import dbus
1922- from landscape.ui.model.configuration.mechanism import (
1923- ConfigurationMechanism, INTERFACE_NAME)
1924-
1925-
1926-class MechanismTest(LandscapeTest):
1927- """
1928- Test that we can use mechanism calls successfully from within a secure
1929- context (the easiest to achieve is in-process calls.
1930- """
1931-
1932- def setUp(self):
1933- super(MechanismTest, self).setUp()
1934- config = "[client]\n"
1935- config += "data_path = /var/lib/landscape/client/\n"
1936- config += "http_proxy = http://proxy.localdomain:3192\n"
1937- config += "tags = a_tag\n"
1938- config += "url = https://landscape.canonical.com/message-system\n"
1939- config += "account_name = foo\n"
1940- config += "registration_key = boink\n"
1941- config += "computer_title = baz\n"
1942- config += "https_proxy = https://proxy.localdomain:6192\n"
1943- config += "ping_url = http://landscape.canonical.com/ping\n"
1944- self.config_filename = self.makeFile(config)
1945- self.config = LandscapeSetupConfiguration()
1946- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
1947- bus = dbus.SessionBus(private=True)
1948- bus_name = dbus.service.BusName(INTERFACE_NAME, bus)
1949- self.mechanism = ConfigurationMechanism(self.config, bus_name)
1950- self.config.load(["-c", self.config_filename])
1951-
1952- def tearDown(self):
1953- self.mechanism.remove_from_connection()
1954- super(MechanismTest, self).tearDown()
1955-
1956- def test_is_local_call(self):
1957- """
1958- Test simple mechanism for checking if a call is local does the right
1959- thing. Anything passed to this function that is not L{None} will
1960- result in is returning False - this in turn means that bypassing
1961- security will not happen, which is the right thing in failure cases
1962- too.
1963- """
1964- self.assertTrue(self.mechanism._is_local_call(None, None))
1965- self.assertFalse(self.mechanism._is_local_call(True, True))
1966-
1967- def test_get_account_name(self):
1968- """
1969- Test we can get account name from the mechanism.
1970- """
1971- self.assertEqual("foo", self.mechanism.get("account_name"))
1972-
1973- def test_set_account_name(self):
1974- """
1975- Test we can set the account name via the mechanism.
1976- """
1977- self.mechanism.set("account_name", "bar")
1978- self.assertEqual("bar", self.mechanism.get("account_name"))
1979-
1980- def test_set_account_name_unicode(self):
1981- """
1982- Non-ascii characters are replaced before passing to underlying config.
1983- """
1984- self.mechanism.set("account_name", u"unicode\u00a3unicode")
1985- self.assertEqual("unicode?unicode", self.mechanism.get("account_name"))
1986-
1987- def test_no_unicode_to_underlying_config(self):
1988- """
1989- Non-ascii characters are replaced before passing to underlying config.
1990- """
1991- class FakeConfig(object):
1992- def __init__(self):
1993- self.account_name = None
1994-
1995- fake_config = FakeConfig()
1996- self.mechanism._config = fake_config
1997- self.mechanism.set("account_name", u"unicode\u00a3unicode")
1998- self.assertEqual("unicode?unicode", fake_config.account_name)
1999-
2000- def test_get_data_path(self):
2001- """
2002- Test we can get the data path from the mechanism.
2003- """
2004- self.assertEqual("/var/lib/landscape/client/",
2005- self.mechanism.get("data_path"))
2006-
2007- def set_data_path(self):
2008- """
2009- Test we can set the data path via the mechanism.
2010- """
2011- self.mechanism.set("data_path", "bar")
2012- self.assertEqual("bar", self.mechanism.get("data_path"))
2013-
2014- def test_get_http_proxy(self):
2015- """
2016- Test that we can get the HTTP proxy from the mechanism.
2017- """
2018- self.assertEqual("http://proxy.localdomain:3192",
2019- self.mechanism.get("http_proxy"))
2020-
2021- def test_set_http_proxy(self):
2022- """
2023- Test that we can set the HTTP proxy via the mechanism.
2024- """
2025- self.mechanism.set("http_proxy", "bar")
2026- self.assertEqual("bar", self.mechanism.get("http_proxy"))
2027-
2028- def test_get_tags(self):
2029- """
2030- Test that we can get Tags from the mechanism.
2031- """
2032- self.assertEqual("a_tag", self.mechanism.get("tags"))
2033-
2034- def test_set_tags(self):
2035- """
2036- Test that we can set Tags via the mechanism.
2037- """
2038- self.mechanism.set("tags", "bar")
2039- self.assertEqual("bar", self.mechanism.get("tags"))
2040-
2041- def test_get_url(self):
2042- """
2043- Test that we can get URL from the mechanism.
2044- """
2045- self.assertEqual("https://landscape.canonical.com/message-system",
2046- self.mechanism.get("url"))
2047-
2048- def test_set_url(self):
2049- """
2050- Test that we can set the URL via the mechanisms.
2051- """
2052- self.mechanism.set("url", "bar")
2053- self.assertEqual(self.mechanism.get("url"), "bar")
2054-
2055- def test_get_ping_url(self):
2056- """
2057- Test that we can get the Ping URL from the mechanism.
2058- """
2059- self.assertEqual("http://landscape.canonical.com/ping",
2060- self.mechanism.get("ping_url"))
2061-
2062- def test_set_ping_url(self):
2063- """
2064- Test that we can set the Ping URL via the mechanism.
2065- """
2066- self.mechanism.set("ping_url", "bar")
2067- self.assertEqual("bar", self.mechanism.get("ping_url"))
2068-
2069- def test_get_registration_key(self):
2070- """
2071- Test that we can get the registration key from the mechanism.
2072- """
2073- self.assertEqual("boink", self.mechanism.get("registration_key"))
2074-
2075- def test_set_registration_key(self):
2076- """
2077- Test that we can set the registration key via the mechanism.
2078- """
2079- self.mechanism.set("registration_key", "bar")
2080- self.assertEqual("bar", self.mechanism.get("registration_key"))
2081-
2082- def test_get_computer_title(self):
2083- """
2084- Test that we can get the computer title from the mechanism.
2085- """
2086- self.assertEqual("baz", self.mechanism.get("computer_title"))
2087-
2088- def test_set_computer_title(self):
2089- """
2090- Test that we can set the computer title via the mechanism.
2091- """
2092- self.mechanism.set("computer_title", "bar")
2093- self.assertEqual("bar", self.mechanism.get("computer_title"))
2094-
2095- def test_get_https_proxy(self):
2096- """
2097- Test that we can get the HTTPS Proxy from the mechanism.
2098- """
2099- self.assertEqual("https://proxy.localdomain:6192",
2100- self.mechanism.get("https_proxy"))
2101-
2102- def test_set_https_proxy(self):
2103- """
2104- Test that we can set the HTTPS Proxy via the mechanism.
2105- """
2106- self.mechanism.set("https_proxy", "bar")
2107- self.assertEqual("bar", self.mechanism.get("https_proxy"))
2108-
2109- def test_exit(self):
2110- """
2111- Test that we cause the mechanism to exit.
2112- """
2113- self.assertRaises(SystemExit, self.mechanism.exit)
2114-
2115- if dbus_test_should_skip:
2116- skip = dbus_skip_message
2117
2118=== removed file 'landscape/ui/model/configuration/tests/test_proxy.py'
2119--- landscape/ui/model/configuration/tests/test_proxy.py 2013-02-14 10:32:46 +0000
2120+++ landscape/ui/model/configuration/tests/test_proxy.py 1970-01-01 00:00:00 +0000
2121@@ -1,187 +0,0 @@
2122-from landscape.configuration import LandscapeSetupConfiguration
2123-from landscape.ui.tests.helpers import (
2124- ConfigurationProxyHelper, dbus_test_should_skip, dbus_skip_message)
2125-if not dbus_test_should_skip:
2126- from landscape.ui.model.configuration.mechanism import (
2127- PermissionDeniedByPolicy)
2128- import dbus
2129-from landscape.tests.helpers import LandscapeTest
2130-
2131-
2132-class AuthenticationFailureTest(LandscapeTest):
2133- """
2134- Test that an authentication failure is handled correctly.
2135- """
2136- helpers = [ConfigurationProxyHelper]
2137-
2138- def setUp(self):
2139- self.config_string = ""
2140-
2141- super(AuthenticationFailureTest, self).setUp()
2142-
2143- def test_failed_authentication(self):
2144- """
2145- Test that load returns False when authentication fails.
2146- """
2147-
2148- def fake_policy_failure_load(arglist):
2149- """
2150- This simulates what you see if you click "Cancel" or give the wrong
2151- credentials 3 times when L{PolicyKit} challenges you.
2152- """
2153- raise PermissionDeniedByPolicy()
2154-
2155- def fake_timeout_failure_load(arglist):
2156- """
2157- This simulates what you see if you take no action when L{PolicyKit}
2158- challenges you.
2159- """
2160-
2161- class FakeNoReply(dbus.DBusException):
2162- """
2163- Simulate a L{DBus} L{NoReply} exception.
2164- """
2165- _dbus_error_name = "org.freedesktop.DBus.Error.NoReply"
2166-
2167- raise FakeNoReply()
2168-
2169- self.mechanism.load = fake_policy_failure_load
2170- self.assertFalse(self.proxy.load([]))
2171- self.mechanism.load = fake_timeout_failure_load
2172- self.assertFalse(self.proxy.load([]))
2173-
2174- if dbus_test_should_skip:
2175- skip = dbus_skip_message
2176-
2177-
2178-class ConfigurationProxyInterfaceTest(LandscapeTest):
2179- """
2180- Test that we define the correct interface to a
2181- L{LandscapeSetupConfiguration} by really using one as the interface.
2182- """
2183-
2184- helpers = [ConfigurationProxyHelper]
2185-
2186- def setUp(self):
2187- self.config_string = "[client]\n" \
2188- "data_path = /var/lib/landscape/client/\n" \
2189- "http_proxy = http://proxy.localdomain:3192\n" \
2190- "tags = a_tag\n" \
2191- "url = https://landscape.canonical.com/message-system\n" \
2192- "account_name = foo\n" \
2193- "registration_key = boink\n" \
2194- "computer_title = baz\n" \
2195- "https_proxy = https://proxy.localdomain:6192\n" \
2196- "ping_url = http://landscape.canonical.com/ping\n"
2197-
2198- super(ConfigurationProxyInterfaceTest, self).setUp()
2199-
2200- def test_method_docstrings(self):
2201- """
2202- Test that we pass through the docstrings for methods.
2203- """
2204- self.assertEqual(self.proxy.load.__doc__,
2205- LandscapeSetupConfiguration.load.__doc__)
2206- self.assertEqual(self.proxy.reload.__doc__,
2207- LandscapeSetupConfiguration.reload.__doc__)
2208- self.assertEqual(self.proxy.write.__doc__,
2209- LandscapeSetupConfiguration.write.__doc__)
2210-
2211- def test_account_name(self):
2212- """
2213- Test that we can get and set an account name via the configuration
2214- proxy.
2215- """
2216- self.assertEqual("foo", self.proxy.account_name)
2217- self.proxy.account_name = "bar"
2218- self.assertEqual("bar", self.proxy.account_name)
2219- self.assertEqual("bar", self.config.account_name)
2220-
2221- def test_computer_title(self):
2222- """
2223- Test that we can get and set a computer title via the configuration
2224- proxy.
2225- """
2226- self.assertEqual("baz", self.proxy.computer_title)
2227- self.proxy.computer_title = "bar"
2228- self.assertEqual("bar", self.proxy.computer_title)
2229- self.assertEqual("bar", self.config.computer_title)
2230-
2231- def test_data_path(self):
2232- """
2233- Test that we can get and set the data path via the configuration proxy.
2234- """
2235- self.assertEqual("/var/lib/landscape/client/", self.proxy.data_path)
2236- self.proxy.data_path = "bar"
2237- self.assertEqual("bar", self.proxy.data_path)
2238- self.assertEqual("bar", self.config.data_path)
2239-
2240- def test_http_proxy(self):
2241- """
2242- Test that we can get and set the HTTP proxy via the configuration
2243- proxy.
2244- """
2245- self.assertEqual("http://proxy.localdomain:3192",
2246- self.proxy.http_proxy)
2247- self.proxy.http_proxy = "bar"
2248- self.assertEqual("bar", self.proxy.http_proxy)
2249- self.assertEqual("bar", self.config.http_proxy)
2250-
2251- def test_https_proxy(self):
2252- """
2253- Test that we can get and set the HTTPS proxy via the configuration
2254- proxy.
2255- """
2256- self.assertEqual("https://proxy.localdomain:6192",
2257- self.proxy.https_proxy)
2258- self.proxy.https_proxy = "bar"
2259- self.assertEqual("bar", self.proxy.https_proxy)
2260- self.assertEqual("bar", self.config.https_proxy)
2261-
2262- def test_ping_url(self):
2263- """
2264- Test that we can get and set the ping URL via the configuration proxy.
2265- """
2266- self.assertEqual("http://landscape.canonical.com/ping",
2267- self.proxy.ping_url)
2268- self.proxy.ping_url = "bar"
2269- self.assertEqual("bar", self.proxy.ping_url)
2270- self.assertEqual("bar", self.config.ping_url)
2271-
2272- def test_registration_key(self):
2273- """
2274- Test that we can get and set the registration key via the
2275- configuration proxy.
2276- """
2277- self.assertEqual("boink", self.proxy.registration_key)
2278- self.proxy.registration_key = "bar"
2279- self.assertEqual("bar", self.proxy.registration_key)
2280- self.assertEqual("bar", self.config.registration_key)
2281-
2282- def test_tags(self):
2283- """
2284- Test that we can get and set the tags via the configuration proxy.
2285- """
2286- self.assertEqual("a_tag", self.proxy.tags)
2287- self.proxy.tags = "bar"
2288- self.assertEqual("bar", self.proxy.tags)
2289- self.assertEqual("bar", self.config.tags)
2290-
2291- def test_url(self):
2292- """
2293- Test that we can get and set the URL via the configuration proxy.
2294- """
2295- self.assertEqual("https://landscape.canonical.com/message-system",
2296- self.proxy.url)
2297- self.proxy.url = "bar"
2298- self.assertEqual("bar", self.proxy.url)
2299- self.assertEqual("bar", self.config.url)
2300-
2301- def test_exit(self):
2302- """
2303- Test that we can cause the mechanism to exit.
2304- """
2305- self.assertRaises(SystemExit, self.proxy.exit, asynchronous=False)
2306-
2307- if dbus_test_should_skip:
2308- skip = dbus_skip_message
2309
2310=== removed file 'landscape/ui/model/configuration/tests/test_state.py'
2311--- landscape/ui/model/configuration/tests/test_state.py 2013-02-14 10:32:46 +0000
2312+++ landscape/ui/model/configuration/tests/test_state.py 1970-01-01 00:00:00 +0000
2313@@ -1,635 +0,0 @@
2314-from landscape.ui.tests.helpers import (
2315- ConfigurationProxyHelper, FakeGSettings, dbus_test_should_skip,
2316- dbus_skip_message)
2317-
2318-if not dbus_test_should_skip:
2319- from landscape.ui.model.configuration.uisettings import UISettings
2320- import landscape.ui.model.configuration.state
2321- from landscape.ui.model.configuration.state import (
2322- ConfigurationModel, StateError, VirginState, InitialisedState,
2323- ModifiedState, MANAGEMENT_TYPE, HOSTED, LOCAL, HOSTED_LANDSCAPE_HOST,
2324- LANDSCAPE_HOST, COMPUTER_TITLE, ExitedState)
2325- from landscape.ui.model.configuration.mechanism import (
2326- PermissionDeniedByPolicy)
2327- from landscape.ui.constants import (
2328- CANONICAL_MANAGED, LOCAL_MANAGED, NOT_MANAGED)
2329-
2330-
2331-from landscape.tests.helpers import LandscapeTest
2332-
2333-
2334-class AuthenticationFailureTest(LandscapeTest):
2335- """
2336- Test that an authentication failure is handled correctly in the
2337- L{ConfigurationModel}.
2338- """
2339- helpers = [ConfigurationProxyHelper]
2340-
2341- def setUp(self):
2342- self.config_string = ""
2343- self.default_data = {"management-type": "canonical",
2344- "computer-title": "",
2345- "hosted-landscape-host": "",
2346- "hosted-account-name": "",
2347- "hosted-password": "",
2348- "local-landscape-host": "",
2349- "local-account-name": "",
2350- "local-password": ""}
2351- landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
2352- = "bound.to.lose"
2353- super(AuthenticationFailureTest, self).setUp()
2354-
2355- def test_failed_authentication(self):
2356- """
2357- Test that load returns False when authentication fails.
2358- """
2359-
2360- def fake_faily_load(arglist):
2361- """
2362- This simulates what you see if you click "Cancel" or give the wrong
2363- credentials 3 times when L{PolicyKit} challenges you.
2364- """
2365- raise PermissionDeniedByPolicy()
2366-
2367- def fake_exit_method():
2368- """
2369- Avoid raising a L{SystemExit} exception.
2370- """
2371-
2372- self.mechanism.load = fake_faily_load
2373- settings = FakeGSettings(data=self.default_data)
2374- uisettings = UISettings(settings)
2375- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2376- self.assertFalse(model.load_data(asynchronous=False,
2377- exit_method=fake_exit_method))
2378- self.assertTrue(isinstance(model.get_state(), ExitedState))
2379-
2380- if dbus_test_should_skip:
2381- skip = dbus_skip_message
2382-
2383-
2384-class ConfigurationModelTest(LandscapeTest):
2385- """
2386- Test the internal data handling of the L{ConfigurationModel} without
2387- loading external data.
2388- """
2389-
2390- helpers = [ConfigurationProxyHelper]
2391-
2392- def setUp(self):
2393- self.config_string = ""
2394- self.default_data = {"management-type": "canonical",
2395- "computer-title": "",
2396- "hosted-landscape-host": "",
2397- "hosted-account-name": "",
2398- "hosted-password": "",
2399- "local-landscape-host": "",
2400- "local-account-name": "",
2401- "local-password": ""}
2402- landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
2403- = "bound.to.lose"
2404- super(ConfigurationModelTest, self).setUp()
2405-
2406- def test_get(self):
2407- """
2408- Test that L{get} correctly extracts data from the internal data storage
2409- of the L{ConfigurationState}s associated with a L{ConfigurationModel}.
2410- """
2411- settings = FakeGSettings(data=self.default_data)
2412- uisettings = UISettings(settings)
2413- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2414- state = model.get_state()
2415- self.assertEqual(NOT_MANAGED, state.get(MANAGEMENT_TYPE))
2416- self.assertEqual(HOSTED_LANDSCAPE_HOST,
2417- state.get(HOSTED, LANDSCAPE_HOST))
2418- self.assertRaises(TypeError, state.get, MANAGEMENT_TYPE, HOSTED,
2419- LANDSCAPE_HOST)
2420- self.assertRaises(KeyError, state.get, LANDSCAPE_HOST)
2421- self.assertRaises(KeyError, state.get, MANAGEMENT_TYPE, LANDSCAPE_HOST)
2422-
2423- def test_set(self):
2424- """
2425- Test that L{set} correctly sets data in the internal data storage of
2426- the L{ConfigurationState}s associated with a L{ConfigurationModel}.
2427- """
2428- settings = FakeGSettings(data=self.default_data)
2429- uisettings = UISettings(settings)
2430- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2431- state = model.get_state()
2432- state.set(MANAGEMENT_TYPE, NOT_MANAGED)
2433- self.assertEqual(NOT_MANAGED, state.get(MANAGEMENT_TYPE))
2434- state.set(MANAGEMENT_TYPE, CANONICAL_MANAGED)
2435- self.assertEqual(CANONICAL_MANAGED, state.get(MANAGEMENT_TYPE))
2436- state.set(MANAGEMENT_TYPE, LOCAL_MANAGED)
2437- self.assertEqual(LOCAL_MANAGED, state.get(MANAGEMENT_TYPE))
2438- self.assertEqual("", state.get(LOCAL, LANDSCAPE_HOST))
2439- state.set(LOCAL, LANDSCAPE_HOST, "goodison.park")
2440- self.assertEqual("goodison.park", state.get(LOCAL, LANDSCAPE_HOST))
2441-
2442- def test_virginal(self):
2443- """
2444- Test that the L{ConfigurationModel} is created with default data. This
2445- should be managed via L{VirginState} (hence the name), but this should
2446- not be exposed and is not explicitly tested here (see
2447- L{StateTransitionTest}).
2448- """
2449- settings = FakeGSettings(data=self.default_data)
2450- uisettings = UISettings(settings)
2451- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2452- self.assertEqual(NOT_MANAGED, model.management_type)
2453- self.assertEqual(HOSTED_LANDSCAPE_HOST, model.hosted_landscape_host)
2454- self.assertEqual("bound.to.lose", model.computer_title)
2455- self.assertEqual("", model.local_landscape_host)
2456- self.assertEqual("", model.hosted_account_name)
2457- self.assertEqual("standalone", model.local_account_name)
2458- self.assertEqual("", model.hosted_password)
2459-
2460- def test_is_hosted_property(self):
2461- """
2462- Test we can use the L{is_hosted} property to set and get that data on
2463- the current L{ConfigurationState}.
2464- """
2465- settings = FakeGSettings(data=self.default_data)
2466- uisettings = UISettings(settings)
2467- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2468- model.load_data()
2469- self.assertEqual(CANONICAL_MANAGED, model.management_type)
2470- model.management_type = LOCAL_MANAGED
2471- self.assertEqual(LOCAL_MANAGED, model.management_type)
2472- model.management_type = NOT_MANAGED
2473- self.assertEqual(NOT_MANAGED, model.management_type)
2474-
2475- def test_computer_title_property(self):
2476- """
2477- Test that we can use the L{computer_title} property to set and get that
2478- data on the current L{ConfigurationState}.
2479- """
2480- settings = FakeGSettings(data=self.default_data)
2481- uisettings = UISettings(settings)
2482- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2483- model.load_data()
2484- self.assertEqual("bound.to.lose", model.computer_title)
2485- model.computer_title = "bound.to.win"
2486- self.assertEqual("bound.to.win", model.computer_title)
2487-
2488- def test_hosted_landscape_host_property(self):
2489- """
2490- Test we can use the L{hosted_landscape_host} property to set and get
2491- that data on the current L{ConfigurationState}.
2492- """
2493- settings = FakeGSettings(data=self.default_data)
2494- uisettings = UISettings(settings)
2495- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2496- self.assertEqual(HOSTED_LANDSCAPE_HOST, model.hosted_landscape_host)
2497- self.assertRaises(AttributeError, setattr, model,
2498- "hosted_landscape_host", "foo")
2499-
2500- def test_hosted_account_name_property(self):
2501- """
2502- Test we can use the L{hosted_account_name} property to set and get
2503- that data on the current L{ConfigurationState}.
2504- """
2505- settings = FakeGSettings(data=self.default_data)
2506- uisettings = UISettings(settings)
2507- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2508- self.assertEqual("", model.hosted_account_name)
2509- model.hosted_account_name = "foo"
2510- self.assertEqual("foo", model.hosted_account_name)
2511-
2512- def test_hosted_password_property(self):
2513- """
2514- Test we can use the L{hosted_password} property to set and get
2515- that data on the current L{ConfigurationState}.
2516- """
2517- settings = FakeGSettings(data=self.default_data)
2518- uisettings = UISettings(settings)
2519- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2520- self.assertEqual("", model.hosted_password)
2521- model.hosted_password = "foo"
2522- self.assertEqual("foo", model.hosted_password)
2523-
2524- def test_local_landscape_host_property(self):
2525- """
2526- Test we can use the L{local_landscape_host} property to set and get
2527- that data on the current L{ConfigurationState}.
2528- """
2529- settings = FakeGSettings(data=self.default_data)
2530- uisettings = UISettings(settings)
2531- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2532- self.assertEqual("", model.local_landscape_host)
2533- model.local_landscape_host = "foo"
2534- self.assertEqual("foo", model.local_landscape_host)
2535-
2536- def test_local_account_name_property(self):
2537- """
2538- Test we can use the L{local_account_name} property to set and get
2539- that data on the current L{ConfigurationState}.
2540- """
2541- settings = FakeGSettings(data=self.default_data)
2542- uisettings = UISettings(settings)
2543- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2544- self.assertEqual("standalone", model.local_account_name)
2545- model.local_account_name = "foo"
2546- self.assertEqual("foo", model.local_account_name)
2547-
2548- def test_local_password_property(self):
2549- """
2550- Test we can use the L{local_password} property to set and get
2551- that data on the current L{ConfigurationState}.
2552- """
2553- settings = FakeGSettings(data=self.default_data)
2554- uisettings = UISettings(settings)
2555- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2556- self.assertEqual("", model.local_password)
2557- model.local_password = "foo"
2558- self.assertEqual("foo", model.local_password)
2559-
2560- def test_exit(self):
2561- """
2562- Test that we can cause the mechanism to exit.
2563- """
2564- settings = FakeGSettings(data=self.default_data)
2565- uisettings = UISettings(settings)
2566- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2567- self.assertRaises(SystemExit, model.exit, asynchronous=False)
2568-
2569- if dbus_test_should_skip:
2570- skip = dbus_skip_message
2571-
2572-
2573-class ConfigurationModelHostedTest(LandscapeTest):
2574- """
2575- Test the L{ConfigurationModel} is correctly initialised when the live
2576- configuration is set for a hosted account.
2577-
2578- Note the multilayer data loading:
2579-
2580- 1. Internal state is defaulted.
2581- 2. UISettings data is loaded.
2582- 3. Live configuration is loaded.
2583- """
2584-
2585- helpers = [ConfigurationProxyHelper]
2586-
2587- default_data = {"management-type": "canonical",
2588- "computer-title": "bound.to.lose",
2589- "hosted-landscape-host": "landscape.canonical.com",
2590- "hosted-account-name": "Sparklehorse",
2591- "hosted-password": "Vivadixiesubmarinetransmissionplot",
2592- "local-landscape-host": "the.local.machine",
2593- "local-account-name": "CrazyHorse",
2594- "local-password": "RustNeverSleeps"}
2595-
2596- def setUp(self):
2597- self.config_string = "[client]\n" \
2598- "data_path = /var/lib/landscape/client/\n" \
2599- "http_proxy = http://proxy.localdomain:3192\n" \
2600- "tags = a_tag\n" \
2601- "url = https://landscape.canonical.com/message-system\n" \
2602- "account_name = foo\n" \
2603- "registration_key = boink\n" \
2604- "computer_title = baz\n" \
2605- "https_proxy = https://proxy.localdomain:6192\n" \
2606- "ping_url = http://landscape.canonical.com/ping\n"
2607-
2608- super(ConfigurationModelHostedTest, self).setUp()
2609-
2610- def test_initialised_hosted(self):
2611- """
2612- Test the L{ConfigurationModel} is correctly initialised from a proxy
2613- and defaults with hosted data.
2614- """
2615- settings = FakeGSettings(data=self.default_data)
2616- uisettings = UISettings(settings)
2617- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2618- model.load_data()
2619- self.assertEqual(CANONICAL_MANAGED, model.management_type)
2620- self.assertEqual("landscape.canonical.com",
2621- model.hosted_landscape_host)
2622- self.assertEqual("the.local.machine", model.local_landscape_host)
2623- self.assertEqual("foo", model.hosted_account_name)
2624- self.assertEqual("CrazyHorse", model.local_account_name)
2625- self.assertEqual("boink", model.hosted_password)
2626-
2627- if dbus_test_should_skip:
2628- skip = dbus_skip_message
2629-
2630-
2631-class ConfigurationModelLocalTest(LandscapeTest):
2632-
2633- helpers = [ConfigurationProxyHelper]
2634-
2635- default_data = {"management-type": "LDS",
2636- "computer-title": "bound.to.lose",
2637- "hosted-landscape-host": "landscape.canonical.com",
2638- "hosted-account-name": "Sparklehorse",
2639- "hosted-password": "Vivadixiesubmarinetransmissionplot",
2640- "local-landscape-host": "the.local.machine",
2641- "local-account-name": "CrazyHorse",
2642- "local-password": "RustNeverSleeps"}
2643-
2644- def setUp(self):
2645- self.config_string = "[client]\n" \
2646- "data_path = /var/lib/landscape/client/\n" \
2647- "http_proxy = http://proxy.localdomain:3192\n" \
2648- "tags = a_tag\n" \
2649- "url = https://landscape.localdomain/message-system\n" \
2650- "account_name = foo\n" \
2651- "registration_key = boink\n" \
2652- "computer_title = baz\n" \
2653- "https_proxy = \n" \
2654- "ping_url = http://landscape.localdomain/ping\n"
2655-
2656- super(ConfigurationModelLocalTest, self).setUp()
2657-
2658- def test_initialised_local(self):
2659- """
2660- Test the L{ConfigurationModel} is correctly initialised from a proxy
2661- and defaults with local data.
2662- """
2663- settings = FakeGSettings(data=self.default_data)
2664- uisettings = UISettings(settings)
2665- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2666- model.load_data()
2667- self.assertEqual(LOCAL_MANAGED, model.management_type)
2668- self.assertEqual("landscape.canonical.com",
2669- model.hosted_landscape_host)
2670- self.assertEqual("landscape.localdomain", model.local_landscape_host)
2671- self.assertEqual("Sparklehorse", model.hosted_account_name)
2672- self.assertEqual("foo", model.local_account_name)
2673- self.assertEqual("Vivadixiesubmarinetransmissionplot",
2674- model.hosted_password)
2675-
2676- if dbus_test_should_skip:
2677- skip = dbus_skip_message
2678-
2679-
2680-class StateTransitionTest(LandscapeTest):
2681- """
2682- Test that we make the correct state transitions when taking actions on the
2683- L{ConfigurationModel}.
2684- """
2685-
2686- helpers = [ConfigurationProxyHelper]
2687-
2688- def setUp(self):
2689- self.config_string = ""
2690- self.default_data = {
2691- "management-type": "canonical",
2692- "computer-title": "bound.to.lose",
2693- "hosted-landscape-host": "landscape.canonical.com",
2694- "hosted-account-name": "Sparklehorse",
2695- "hosted-password": "Vivadixiesubmarinetransmissionplot",
2696- "local-landscape-host": "the.local.machine",
2697- "local-account-name": "CrazyHorse",
2698- "local-password": "RustNeverSleeps"}
2699- super(StateTransitionTest, self).setUp()
2700-
2701- def test_load_data_transitions(self):
2702- """
2703- Test that the L{ConfigurationModel} correctly changes state as we call
2704- L{load_data}.
2705- """
2706- settings = FakeGSettings(data=self.default_data)
2707- uisettings = UISettings(settings)
2708- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2709- self.assertTrue(isinstance(model.get_state(), VirginState))
2710- model.load_data()
2711- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2712- initialised = model.get_state()
2713- model.load_data()
2714- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2715- self.assertIs(initialised, model.get_state())
2716-
2717- def test_modifying_a_virgin_raises(self):
2718- """
2719- Test that attempting a L{modify} a L{ConfigurationModel} in
2720- L{VirginState} raises a L{StateError}.
2721- """
2722- settings = FakeGSettings(data=self.default_data)
2723- uisettings = UISettings(settings)
2724- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2725- self.assertRaises(StateError, model.modify)
2726-
2727- def test_initialised_state_is_modifiable(self):
2728- """
2729- Test that the L{ConfigurationModel} transitions to L{ModifiedState}
2730- whenever L{modify} is called on it in L{InitialisedState}.
2731- """
2732- settings = FakeGSettings(data=self.default_data)
2733- uisettings = UISettings(settings)
2734- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2735- model.load_data()
2736- self.assertEqual(CANONICAL_MANAGED, model.management_type)
2737- model.management_type = LOCAL_MANAGED
2738- self.assertEqual(LOCAL_MANAGED, model.management_type)
2739- model.modify()
2740- self.assertTrue(isinstance(model.get_state(), ModifiedState))
2741- self.assertEqual(LOCAL_MANAGED, model.management_type)
2742-
2743- def test_modified_state_is_modifiable(self):
2744- """
2745- Test that the L{ConfigurationModel} transitions to L{ModifiedState}
2746- whenever L{modify} is called on it in L{ModifiedState}.
2747- """
2748- settings = FakeGSettings(data=self.default_data)
2749- uisettings = UISettings(settings)
2750- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2751- model.load_data()
2752- model.modify()
2753- self.assertTrue(isinstance(model.get_state(), ModifiedState))
2754- model.modify()
2755- self.assertTrue(isinstance(model.get_state(), ModifiedState))
2756-
2757- def test_reverting_a_virgin_raises(self):
2758- """
2759- Test that calling L{revert} on a L{ConfigurationModel} in
2760- L{VirginState} raises a L{StateError}.
2761- """
2762- settings = FakeGSettings(data=self.default_data)
2763- uisettings = UISettings(settings)
2764- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2765- self.assertRaises(StateError, model.revert)
2766-
2767- def test_initialiased_state_is_unrevertable(self):
2768- """
2769- Test that calling L{revert} on a L{ConfigurationModel} in
2770- L{InitialisedState} raises a L{StateError}.
2771- """
2772- settings = FakeGSettings(data=self.default_data)
2773- uisettings = UISettings(settings)
2774- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2775- model.load_data()
2776- self.assertRaises(StateError, model.revert)
2777-
2778- def test_modified_state_is_revertable(self):
2779- """
2780- Test that a L{ConfigurationModel} in L{ModifiedState} can be
2781- transitioned via L{revert} to L{InitialisedState}.
2782- """
2783- settings = FakeGSettings(data=self.default_data)
2784- uisettings = UISettings(settings)
2785- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2786- model.load_data()
2787- model.modify()
2788- model.revert()
2789- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2790-
2791- def test_reverting_reverts_data(self):
2792- """
2793- Test that transitioning via L{revert} causes the original
2794- L{InitialisedState} to be restored.
2795- """
2796- settings = FakeGSettings(data=self.default_data)
2797- uisettings = UISettings(settings)
2798- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2799- model.load_data()
2800- self.assertEqual(HOSTED_LANDSCAPE_HOST, model.hosted_landscape_host)
2801- self.assertEqual("CrazyHorse", model.local_account_name)
2802- model.local_account_name = "bar"
2803- model.modify()
2804- self.assertEqual("bar", model.local_account_name)
2805- model.revert()
2806- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2807- self.assertEqual("CrazyHorse", model.local_account_name)
2808-
2809- def test_persisting_a_virgin_raises(self):
2810- """
2811- Test that a L{ConfigurationModel} in L{VirginState} will raise a
2812- L{StateError} when you attempt to transition it with L{persist}.
2813- """
2814- settings = FakeGSettings(data=self.default_data)
2815- uisettings = UISettings(settings)
2816- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2817- self.assertRaises(StateError, model.persist)
2818-
2819- def test_persisting_initialised_state_raises(self):
2820- """
2821- Test that a L{ConfigurationModel} in L{IntialisedState} will raise a
2822- L{StateError} when you attempt to transition it with L{persist}.
2823- """
2824- settings = FakeGSettings(data=self.default_data)
2825- uisettings = UISettings(settings)
2826- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2827- model.load_data()
2828- self.assertRaises(StateError, model.persist)
2829-
2830- def test_persisting_modified_is_allowed(self):
2831- """
2832- Test that a L{ConfigurationModel} in L{ModifiedState} will allow itself
2833- to be transitioned with L{persist}.
2834- """
2835- settings = FakeGSettings(data=self.default_data)
2836- uisettings = UISettings(settings)
2837- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2838- model.load_data()
2839- model.modify()
2840- model.persist()
2841- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2842-
2843- def test_persisting_saves_data_to_uisettings(self):
2844- settings = FakeGSettings(data=self.default_data)
2845- uisettings = UISettings(settings)
2846- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2847- model.load_data()
2848- self.assertEqual(CANONICAL_MANAGED, uisettings.get_management_type())
2849- self.assertEqual("Sparklehorse", uisettings.get_hosted_account_name())
2850- self.assertEqual("Vivadixiesubmarinetransmissionplot",
2851- uisettings.get_hosted_password())
2852- self.assertEqual("the.local.machine",
2853- uisettings.get_local_landscape_host())
2854- self.assertEqual("CrazyHorse", uisettings.get_local_account_name())
2855- self.assertEqual("RustNeverSleeps", uisettings.get_local_password())
2856- model.management_type = LOCAL_MANAGED
2857- model.hosted_account_name = "ThomasPaine"
2858- model.hosted_password = "TheAgeOfReason"
2859- model.local_landscape_host = "another.local.machine"
2860- model.local_account_name = "ThomasHobbes"
2861- model.local_password = "TheLeviathan"
2862- model.modify()
2863- self.assertTrue(isinstance(model.get_state(), ModifiedState))
2864- model.persist()
2865- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2866- self.assertEqual(LOCAL_MANAGED, uisettings.get_management_type())
2867- self.assertEqual("ThomasPaine", uisettings.get_hosted_account_name())
2868- self.assertEqual("TheAgeOfReason", uisettings.get_hosted_password())
2869- self.assertEqual("another.local.machine",
2870- uisettings.get_local_landscape_host())
2871- self.assertEqual("ThomasHobbes", uisettings.get_local_account_name())
2872- self.assertEqual("TheLeviathan", uisettings.get_local_password())
2873-
2874- def test_any_transition_on_exited_state_raises(self):
2875- """
2876- Test that we cannot transition the L{ExitedState} at all.
2877- """
2878-
2879- def fake_exit():
2880- """
2881- This just avoids raising L{exceptions.SysExit} during __init__.
2882- """
2883-
2884- state = ExitedState(None, None, None, exit_method=fake_exit)
2885- self.assertRaises(StateError, state.load_data)
2886- self.assertRaises(StateError, state.modify)
2887- self.assertRaises(StateError, state.persist)
2888- self.assertRaises(StateError, state.revert)
2889-
2890- if dbus_test_should_skip:
2891- skip = dbus_skip_message
2892-
2893-
2894-class StateTransitionWithExistingConfigTest(LandscapeTest):
2895- """
2896- Test that we handle existing configuration data correctly when
2897- transitioning through L{ConfigurationModel} states.
2898- """
2899-
2900- helpers = [ConfigurationProxyHelper]
2901-
2902- def setUp(self):
2903- self.config_string = (
2904- "[client]\n"
2905- "data_path = /var/lib/landscape/client/\n"
2906- "http_proxy = http://proxy.localdomain:3192\n"
2907- "tags = a_tag\n"
2908- "url = https://landscape.canonical.com/message-system\n"
2909- "account_name = Sparklehorse\n"
2910- "registration_key = Vivadixiesubmarinetransmissionplot\n"
2911- "computer_title = baz\n"
2912- "https_proxy = https://proxy.localdomain:6192\n"
2913- "ping_url = http://landscape.canonical.com/ping\n")
2914- self.default_data = {
2915- "management-type": "canonical",
2916- "computer-title": "bound.to.lose",
2917- "hosted-landscape-host": "landscape.canonical.com",
2918- "hosted-account-name": "Sparklehorse",
2919- "hosted-password": "Vivadixiesubmarinetransmissionplot",
2920- "local-landscape-host": "the.local.machine",
2921- "local-account-name": "CrazyHorse",
2922- "local-password": "RustNeverSleeps"}
2923- super(StateTransitionWithExistingConfigTest, self).setUp()
2924-
2925- def test_persisting_saves_data_to_proxy(self):
2926- settings = FakeGSettings(data=self.default_data)
2927- uisettings = UISettings(settings)
2928- model = ConfigurationModel(proxy=self.proxy, uisettings=uisettings)
2929- model.load_data()
2930- self.assertEqual("Sparklehorse", self.proxy.account_name)
2931- self.assertEqual("Vivadixiesubmarinetransmissionplot",
2932- self.proxy.registration_key)
2933- model.management_type = LOCAL_MANAGED
2934- model.local_account_name = "ThomasPaine"
2935- model.local_password = "TheAgeOfReason"
2936- model.modify()
2937- self.assertTrue(isinstance(model.get_state(), ModifiedState))
2938- model.persist()
2939- self.assertTrue(isinstance(model.get_state(), InitialisedState))
2940- self.assertEqual(LOCAL_MANAGED, model.management_type)
2941- self.assertEqual("https://the.local.machine/message-system",
2942- self.proxy.url)
2943- self.assertEqual("http://the.local.machine/ping", self.proxy.ping_url)
2944- self.assertEqual("ThomasPaine", self.proxy.account_name)
2945- self.assertEqual("TheAgeOfReason", self.proxy.registration_key)
2946-
2947- if dbus_test_should_skip:
2948- skip = dbus_skip_message
2949
2950=== removed file 'landscape/ui/model/configuration/tests/test_uisettings.py'
2951--- landscape/ui/model/configuration/tests/test_uisettings.py 2013-02-14 10:32:46 +0000
2952+++ landscape/ui/model/configuration/tests/test_uisettings.py 1970-01-01 00:00:00 +0000
2953@@ -1,167 +0,0 @@
2954-
2955-from landscape.tests.helpers import LandscapeTest
2956-from landscape.ui.model.configuration.uisettings import UISettings
2957-from landscape.ui.tests.helpers import (
2958- FakeGSettings, dbus_test_should_skip, dbus_skip_message)
2959-
2960-
2961-class UISettingsTest(LandscapeTest):
2962-
2963- default_data = {"management-type": "LDS",
2964- "computer-title": "bound.to.lose",
2965- "hosted-landscape-host": "landscape.canonical.com",
2966- "hosted-account-name": "Sparklehorse",
2967- "hosted-password": "Vivadixiesubmarinetransmissionplot",
2968- "local-landscape-host": "the.local.machine",
2969- "local-account-name": "CrazyHorse",
2970- "local-password": "RustNeverSleeps"}
2971-
2972- def setUp(self):
2973- super(UISettingsTest, self).setUp()
2974- self.settings = FakeGSettings(data=self.default_data)
2975- self.uisettings = UISettings(self.settings)
2976-
2977- def test_setup(self):
2978- """
2979- Test that the L{GSettings.Client} is correctly initialised.
2980- """
2981- self.assertTrue(self.settings.was_called_with_args(
2982- "new", UISettings.BASE_KEY))
2983-
2984- def test_get_management_type(self):
2985- """
2986- Test that the L{get_management_type} value is correctly fetched from
2987- the L{GSettings.Client}.
2988- """
2989- self.assertEqual("LDS", self.uisettings.get_management_type())
2990-
2991- def test_set_management_type(self):
2992- """
2993- Test that we can correctly use L{set_management_type} to write the
2994- L{management_type} value to the L{GSettings.Client}.
2995- """
2996- self.assertEqual("LDS", self.uisettings.get_management_type())
2997- self.uisettings.set_management_type("canonical")
2998- self.assertEqual("canonical", self.uisettings.get_management_type())
2999- self.assertTrue(self.settings.was_called_with_args(
3000- "set_string", "management-type", "canonical"))
3001-
3002- def test_get_computer_title(self):
3003- """
3004- Test that the L{get_computer_title} value is correctly fetched
3005- from the L{GSettings.Client}.
3006- """
3007- self.assertEqual("bound.to.lose",
3008- self.uisettings.get_computer_title())
3009-
3010- def test_set_computer_title(self):
3011- """
3012- Test that L{set_computer_title} correctly sets the value of
3013- L{computer_title} in the L{GSettings.Client}.
3014- """
3015- self.assertEqual("bound.to.lose", self.uisettings.get_computer_title())
3016- self.uisettings.set_computer_title("Bang")
3017- self.assertEqual("Bang", self.uisettings.get_computer_title())
3018-
3019- def test_get_hosted_landscape_host(self):
3020- """
3021- Test that the L{get_hosted_landscape_host} value is correctly fetched
3022- from the L{GSettings.Client}.
3023- """
3024- self.assertEqual("landscape.canonical.com",
3025- self.uisettings.get_hosted_landscape_host())
3026-
3027- # NOTE: There is no facility to set the hosted-landscape-host
3028-
3029- def test_get_hosted_account_name(self):
3030- """
3031- Test that the L{get_hosted_account_name} value is correctly fetched
3032- from the L{GSettings.Client}.
3033- """
3034- self.assertEqual("Sparklehorse",
3035- self.uisettings.get_hosted_account_name())
3036-
3037- def test_set_hosted_account_name(self):
3038- """
3039- Test that L{set_hosted_account_name} correctly sets the value of
3040- L{hosted_account_name} in the L{GSettings.Client}.
3041- """
3042- self.assertEqual("Sparklehorse",
3043- self.uisettings.get_hosted_account_name())
3044- self.uisettings.set_hosted_account_name("Bang")
3045- self.assertEqual("Bang", self.uisettings.get_hosted_account_name())
3046-
3047- def test_get_hosted_password(self):
3048- """
3049- Test that the L{get_hosted_password} value is correctly fetched
3050- from the L{GSettings.Client}.
3051- """
3052- self.assertEqual("Vivadixiesubmarinetransmissionplot",
3053- self.uisettings.get_hosted_password())
3054-
3055- def test_set_hosted_password(self):
3056- """
3057- Test that L{set_hosted_password} correctly sets the value of
3058- L{hosted_password} in the L{GSettings.Client}.
3059- """
3060- self.assertEqual("Vivadixiesubmarinetransmissionplot",
3061- self.uisettings.get_hosted_password())
3062- self.uisettings.set_hosted_password("Bang")
3063- self.assertEqual("Bang", self.uisettings.get_hosted_password())
3064-
3065- def test_get_local_landscape_host(self):
3066- """
3067- Test that the L{get_local_landscape_host} value is correctly fetched
3068- from the L{GSettings.Client}.
3069- """
3070- self.assertEqual("the.local.machine",
3071- self.uisettings.get_local_landscape_host())
3072-
3073- def test_set_local_landscape_host(self):
3074- """
3075- Test that L{set_local_landscape_host} correctly sets the value of
3076- L{local_landscape_host} in the L{GSettings.Client}.
3077- """
3078- self.assertEqual("the.local.machine",
3079- self.uisettings.get_local_landscape_host())
3080- self.uisettings.set_local_landscape_host("Bang")
3081- self.assertEqual("Bang", self.uisettings.get_local_landscape_host())
3082-
3083- def test_get_local_account_name(self):
3084- """
3085- Test that the L{get_local_account_name} value is correctly fetched
3086- from the L{GSettings.Client}.
3087- """
3088- self.assertEqual("CrazyHorse",
3089- self.uisettings.get_local_account_name())
3090-
3091- def test_set_local_account_name(self):
3092- """
3093- Test that L{set_local_account_name} correctly sets the value of
3094- L{local_account_name} in the L{GSettings.Client}.
3095- """
3096- self.assertEqual("CrazyHorse",
3097- self.uisettings.get_local_account_name())
3098- self.uisettings.set_local_account_name("Bang")
3099- self.assertEqual("Bang", self.uisettings.get_local_account_name())
3100-
3101- def test_get_local_password(self):
3102- """
3103- Test that the L{get_local_password} value is correctly fetched
3104- from the L{GSettings.Client}.
3105- """
3106- self.assertEqual("RustNeverSleeps",
3107- self.uisettings.get_local_password())
3108-
3109- def test_set_local_password(self):
3110- """
3111- Test that L{set_local_password} correctly sets the value of
3112- L{local_password} in the L{GSettings.Client}.
3113- """
3114- self.assertEqual("RustNeverSleeps",
3115- self.uisettings.get_local_password())
3116- self.uisettings.set_local_password("Bang")
3117- self.assertEqual("Bang", self.uisettings.get_local_password())
3118-
3119- if dbus_test_should_skip:
3120- skip = dbus_skip_message
3121
3122=== removed file 'landscape/ui/model/configuration/uisettings.py'
3123--- landscape/ui/model/configuration/uisettings.py 2012-02-29 17:02:37 +0000
3124+++ landscape/ui/model/configuration/uisettings.py 1970-01-01 00:00:00 +0000
3125@@ -1,57 +0,0 @@
3126-class UISettings(object):
3127- """
3128- A very thin wrapper around L{GSettings} to avoid having to know the
3129- L{BaseKey} and type information elsewhere. In some future version it would
3130- be right to bind to change events here so we can react to people changing
3131- the settings in dconf, for now that is overkill.
3132- """
3133-
3134- BASE_KEY = "com.canonical.landscape-client-settings"
3135-
3136- def __init__(self, settings):
3137- self.settings = settings.new(self.BASE_KEY)
3138-
3139- def get_management_type(self):
3140- return self.settings.get_string("management-type")
3141-
3142- def set_management_type(self, value):
3143- self.settings.set_string("management-type", value)
3144-
3145- def get_computer_title(self):
3146- return self.settings.get_string("computer-title")
3147-
3148- def set_computer_title(self, value):
3149- self.settings.set_string("computer-title", value)
3150-
3151- def get_hosted_landscape_host(self):
3152- return self.settings.get_string("hosted-landscape-host")
3153-
3154- def get_hosted_account_name(self):
3155- return self.settings.get_string("hosted-account-name")
3156-
3157- def set_hosted_account_name(self, value):
3158- self.settings.set_string("hosted-account-name", value)
3159-
3160- def get_hosted_password(self):
3161- return self.settings.get_string("hosted-password")
3162-
3163- def set_hosted_password(self, value):
3164- self.settings.set_string("hosted-password", value)
3165-
3166- def get_local_landscape_host(self):
3167- return self.settings.get_string("local-landscape-host")
3168-
3169- def set_local_landscape_host(self, value):
3170- self.settings.set_string("local-landscape-host", value)
3171-
3172- def get_local_account_name(self):
3173- return self.settings.get_string("local-account-name")
3174-
3175- def set_local_account_name(self, value):
3176- self.settings.set_string("local-account-name", value)
3177-
3178- def get_local_password(self):
3179- return self.settings.get_string("local-password")
3180-
3181- def set_local_password(self, value):
3182- self.settings.set_string("local-password", value)
3183
3184=== removed directory 'landscape/ui/model/registration'
3185=== removed file 'landscape/ui/model/registration/__init__.py'
3186=== removed file 'landscape/ui/model/registration/mechanism.py'
3187--- landscape/ui/model/registration/mechanism.py 2012-03-16 14:58:50 +0000
3188+++ landscape/ui/model/registration/mechanism.py 1970-01-01 00:00:00 +0000
3189@@ -1,177 +0,0 @@
3190-import subprocess
3191-import sys
3192-import os
3193-
3194-import dbus
3195-import dbus.service
3196-import dbus.glib
3197-
3198-from landscape.ui.lib.polkit import PolicyKitMechanism, POLICY_NAME
3199-
3200-
3201-SERVICE_NAME = "com.canonical.LandscapeClientRegistration"
3202-INTERFACE_NAME = \
3203- "com.canonical.LandscapeClientRegistration.RegistrationInterface"
3204-OBJECT_PATH = \
3205- "/com/canonical/LandscapeClientRegistration/RegistrationInterface"
3206-
3207-
3208-class PermissionDeniedByPolicy(dbus.DBusException):
3209- _dbus_error_name = \
3210- "com.canonical.LandscapeClientRegistration.PermissionDeniedByPolicy"
3211-
3212-
3213-class RegistrationError(dbus.DBusException):
3214- _dbus_error_name = \
3215- "com.canonical.LandscapeClientRegistration.RegistrationError"
3216-
3217-
3218-class RegistrationMechanism(PolicyKitMechanism):
3219- """
3220- L{RegistrationMechanism} is a mechanism for invoking and observing client
3221- registration over DBus. It utilises PolicyKit to ensure that only
3222- administrative users may use it.
3223- """
3224-
3225- def __init__(self, bus_name, bypass=False, conn=None):
3226- super(RegistrationMechanism, self).__init__(
3227- OBJECT_PATH, bus_name, PermissionDeniedByPolicy,
3228- bypass=bypass, conn=conn)
3229- self.process = None
3230- self.message_queue = []
3231- self.error_queue = []
3232-
3233- def _do_registration(self, config_path):
3234- self.register_notify("Trying to register ...\n")
3235- cmd = ["landscape-config", "--silent", "-c",
3236- os.path.abspath(config_path)]
3237- try:
3238- message = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
3239- self.register_notify(message)
3240- return True, message
3241- except subprocess.CalledProcessError, error:
3242- wait_phrase = "Please wait... "
3243- wait_phrase_index = error.output.find(wait_phrase)
3244- if wait_phrase_index > -1:
3245- message = error.output[wait_phrase_index + len(wait_phrase):]
3246- else:
3247- message = "Landscape configuration failed.\n%s" % error.output
3248- self.register_error(message)
3249- return False, message
3250-
3251- @dbus.service.signal(dbus_interface=INTERFACE_NAME,
3252- signature='s')
3253- def register_notify(self, message):
3254- """
3255- L{register_notify} is a signal sent to subscribers. It is not
3256- necessary for any actual work to occur in the method as it is called
3257- for the effect of invoking its decorator.
3258- """
3259-
3260- @dbus.service.signal(dbus_interface=INTERFACE_NAME,
3261- signature='s')
3262- def register_error(self, message):
3263- """
3264- L{register_error} is a signal sent to subscribers. It is not
3265- necessary for any actual work to occur in the method as it is called
3266- for the effect of invoking its decorator.
3267- """
3268-
3269- @dbus.service.signal(dbus_interface=INTERFACE_NAME,
3270- signature='s')
3271- def register_succeed(self, message):
3272- """
3273- L{register_succeed} is a signal sent to subscribers. It is not
3274- necessary for any actual work to occur in the method as it is called
3275- for the effect of invoking its decorator.
3276- """
3277-
3278- @dbus.service.signal(dbus_interface=INTERFACE_NAME,
3279- signature='s')
3280- def register_fail(self, message):
3281- """
3282- L{register_fail} is a signal sent to subscribers. It is not
3283- necessary for any actual work to occur in the method as it is called
3284- for the effect of invoking its decorator.
3285- """
3286-
3287- @dbus.service.method(INTERFACE_NAME,
3288- in_signature="",
3289- out_signature="b",
3290- sender_keyword="sender",
3291- connection_keyword="conn")
3292- def challenge(self, sender=None, conn=None):
3293- """
3294- Safely check if we can escalate permissions.
3295- """
3296- try:
3297- return self._is_allowed_by_policy(sender, conn, POLICY_NAME)
3298- except PermissionDeniedByPolicy:
3299- return False
3300-
3301- @dbus.service.method(INTERFACE_NAME,
3302- in_signature="s",
3303- out_signature="(bs)",
3304- sender_keyword="sender",
3305- connection_keyword="conn")
3306- def register(self, config_path, sender=None, conn=None):
3307- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
3308- succeed, message = self._do_registration(config_path)
3309- if succeed:
3310- message = "Registration message sent to Landscape server.\n"
3311- self.register_succeed(message)
3312- return (True, message)
3313- else:
3314- self.register_fail(message)
3315- return (False, message)
3316-
3317- def _do_disabling(self):
3318- cmd = ["landscape-config", "--disable"]
3319- try:
3320- subprocess.check_output(cmd, stderr=subprocess.STDOUT)
3321- return True
3322- except subprocess.CalledProcessError:
3323- return False
3324-
3325- @dbus.service.signal(dbus_interface=INTERFACE_NAME,
3326- signature='')
3327- def disable_succeed(self):
3328- """
3329- L{disable_succeed} is a signal sent to subscribers. It is not
3330- necessary for any actual work to occur in the method as it is called
3331- for the effect of invoking its decorator.
3332- """
3333-
3334- @dbus.service.signal(dbus_interface=INTERFACE_NAME,
3335- signature='')
3336- def disable_fail(self):
3337- """
3338- L{disable_fail} is a signal sent to subscribers. It is not
3339- necessary for any actual work to occur in the method as it is called
3340- for the effect of invoking its decorator.
3341- """
3342-
3343- @dbus.service.method(INTERFACE_NAME,
3344- in_signature="",
3345- out_signature="b",
3346- sender_keyword="sender",
3347- connection_keyword="conn")
3348- def disable(self, sender=None, conn=None):
3349- if self._is_allowed_by_policy(sender, conn, POLICY_NAME):
3350- if self._do_disabling():
3351- self.disable_succeed()
3352- return True
3353- else:
3354- self.disable_fail()
3355- return False
3356-
3357- @dbus.service.method(INTERFACE_NAME,
3358- in_signature="",
3359- out_signature="",
3360- sender_keyword="sender",
3361- connection_keyword="conn")
3362- def exit(self, sender=None, conn=None):
3363- """
3364- Exit this process.
3365- """
3366- sys.exit(0)
3367
3368=== removed file 'landscape/ui/model/registration/proxy.py'
3369--- landscape/ui/model/registration/proxy.py 2012-03-20 16:21:39 +0000
3370+++ landscape/ui/model/registration/proxy.py 1970-01-01 00:00:00 +0000
3371@@ -1,139 +0,0 @@
3372-import dbus
3373-
3374-import landscape.ui.model.registration.mechanism as mechanism
3375-
3376-
3377-class RegistrationProxy(object):
3378- """
3379- L{RegistrationProxy} allows the use of the L{RegistrationMechanism} via
3380- DBus without having to know about DBus. This in turn allows controller
3381- code to remain agnostic to the implementation of registration.
3382- """
3383-
3384- def __init__(self, on_register_notify=None, on_register_error=None,
3385- on_register_succeed=None, on_register_fail=None,
3386- on_disable_succeed=None, on_disable_fail=None, bus=None):
3387- self._bus = None
3388- self._interface = None
3389- self._on_register_notify = on_register_notify
3390- self._on_register_error = on_register_error
3391- self._on_register_succeed = on_register_succeed
3392- self._on_register_fail = on_register_fail
3393- self._on_disable_succeed = on_disable_succeed
3394- self._on_disable_fail = on_disable_fail
3395- self._setup_interface(bus)
3396-
3397- def _setup_interface(self, bus):
3398- """
3399- Redefining L{_setup_interface} allows us to bypass DBus for more
3400- convenient testing in some instances.
3401- """
3402- if bus is None:
3403- self._bus = dbus.SystemBus()
3404- else:
3405- self._bus = bus
3406- self._remote_object = self._bus.get_object(mechanism.SERVICE_NAME,
3407- mechanism.OBJECT_PATH)
3408- self._interface = dbus.Interface(self._remote_object,
3409- mechanism.INTERFACE_NAME)
3410-
3411- def _exit_handler_wrapper(self, exit_handler):
3412-
3413- def wrapped_exit_handler(message):
3414- self._remove_handlers()
3415- exit_handler(message)
3416-
3417- return wrapped_exit_handler
3418-
3419- def _register_handlers(self):
3420- self._handlers = []
3421- if self._on_register_notify:
3422- self._handlers.append(
3423- self._bus.add_signal_receiver(
3424- self._on_register_notify,
3425- signal_name="register_notify",
3426- dbus_interface=mechanism.INTERFACE_NAME,
3427- bus_name=None,
3428- path=mechanism.OBJECT_PATH))
3429- if self._on_register_error:
3430- self._handlers.append(
3431- self._bus.add_signal_receiver(
3432- self._on_register_error,
3433- signal_name="register_error",
3434- dbus_interface=mechanism.INTERFACE_NAME,
3435- bus_name=None,
3436- path=mechanism.OBJECT_PATH))
3437- if self._on_register_succeed:
3438- self._handlers.append(
3439- self._bus.add_signal_receiver(
3440- self._exit_handler_wrapper(self._on_register_succeed),
3441- signal_name="register_succeed",
3442- dbus_interface=mechanism.INTERFACE_NAME,
3443- bus_name=None,
3444- path=mechanism.OBJECT_PATH))
3445- if self._on_register_fail:
3446- self._handlers.append(
3447- self._bus.add_signal_receiver(
3448- self._exit_handler_wrapper(self._on_register_fail),
3449- signal_name="register_fail",
3450- dbus_interface=mechanism.INTERFACE_NAME,
3451- bus_name=None,
3452- path=mechanism.OBJECT_PATH))
3453- if self._on_disable_succeed:
3454- self._handlers.append(
3455- self._bus.add_signal_receiver(
3456- self._exit_handler_wrapper(self._on_disable_succeed),
3457- signal_name="disable_succeed",
3458- dbus_interface=mechanism.INTERFACE_NAME,
3459- bus_name=None,
3460- path=mechanism.OBJECT_PATH))
3461- if self._on_disable_fail:
3462- self._handlers.append(
3463- self._bus.add_signal_receiver(
3464- self._exit_handler_wrapper(self._on_disable_fail),
3465- signal_name="disable_fail",
3466- dbus_interface=mechanism.INTERFACE_NAME,
3467- bus_name=None,
3468- path=mechanism.OBJECT_PATH))
3469-
3470- def _remove_handlers(self):
3471- for handler in self._handlers:
3472- self._bus.remove_signal_receiver(handler)
3473-
3474- def challenge(self):
3475- return self._interface.challenge()
3476-
3477- def register(self, config_path):
3478- self._register_handlers()
3479- try:
3480- result, message = self._interface.register(config_path)
3481- except dbus.DBusException, e:
3482- if e.get_dbus_name() != "org.freedesktop.DBus.Error.NoReply":
3483- raise
3484- else:
3485- result = False
3486- message = "Registration timed out."
3487- if result:
3488- self._on_register_succeed()
3489- else:
3490- self._on_register_error(message)
3491- return result
3492-
3493- def disable(self):
3494- self._register_handlers()
3495- result = self._interface.disable()
3496- if result:
3497- self._on_disable_succeed()
3498- else:
3499- self._on_disable_fail()
3500- return result
3501-
3502- def exit(self):
3503- """
3504- Cause the mechanism to exit.
3505- """
3506- try:
3507- self._interface.exit()
3508- except dbus.DBusException, e:
3509- if e.get_dbus_name() != "org.freedesktop.DBus.Error.NoReply":
3510- raise
3511
3512=== removed directory 'landscape/ui/model/registration/tests'
3513=== removed file 'landscape/ui/model/registration/tests/__init__.py'
3514=== removed file 'landscape/ui/model/registration/tests/test_mechanism.py'
3515--- landscape/ui/model/registration/tests/test_mechanism.py 2013-02-18 13:44:51 +0000
3516+++ landscape/ui/model/registration/tests/test_mechanism.py 1970-01-01 00:00:00 +0000
3517@@ -1,100 +0,0 @@
3518-import dbus
3519-
3520-from landscape.tests.helpers import LandscapeTest
3521-from landscape.ui.tests.helpers import dbus_test_should_skip, dbus_skip_message
3522-if not dbus_test_should_skip:
3523- from landscape.ui.model.registration.mechanism import (
3524- RegistrationMechanism, INTERFACE_NAME)
3525-
3526-
3527-class MechanismTest(LandscapeTest):
3528- """
3529- L{MechanismTest} mocks out the actual registration process and allows us to
3530- simply and quickly check the outputs of registration that are relied on
3531- elsewhere.
3532- """
3533-
3534- def setUp(self):
3535- super(MechanismTest, self).setUp()
3536- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
3537- bus = dbus.SessionBus(private=True)
3538- self.bus_name = dbus.service.BusName(INTERFACE_NAME, bus)
3539- self.mechanism = None
3540-
3541- def tearDown(self):
3542- if not self.mechanism is None:
3543- self.mechanism.remove_from_connection()
3544- super(MechanismTest, self).tearDown()
3545-
3546- def make_fake_registration(self, succeed, message=""):
3547- """
3548- Return a fake registration method that will fail or succeed by
3549- returning L{succeed} (a boolean).
3550- """
3551-
3552- def _do_registration(this, config_path):
3553- return succeed, message
3554-
3555- return _do_registration
3556-
3557- def make_fake_disabling(self, succeed):
3558- """
3559- Return a fake disabling method that will fail or succeed by
3560- returning L{succeed} (a boolean).
3561- """
3562-
3563- def _do_disabling(this):
3564- return succeed
3565-
3566- return _do_disabling
3567-
3568- def test_registration_succeed(self):
3569- """
3570- Test we get appropriate feedback from a successful connection when we
3571- call L{register} synchronously.
3572- """
3573- RegistrationMechanism._do_registration = self.make_fake_registration(
3574- True)
3575- self.mechanism = RegistrationMechanism(self.bus_name)
3576- self.assertEqual(
3577- (True, "Registration message sent to Landscape server.\n"),
3578- self.mechanism.register("foo"))
3579-
3580- def test_registration_fail(self):
3581- """
3582- Test we get appropriate feedback from a failed connection when we
3583- call L{register} synchronously.
3584- """
3585- RegistrationMechanism._do_registration = self.make_fake_registration(
3586- False, "boom")
3587- self.mechanism = RegistrationMechanism(self.bus_name)
3588- self.assertEqual((False, "boom"),
3589- self.mechanism.register("foo"))
3590-
3591- def test_disabling_succeed(self):
3592- """
3593- Test we get True from a failed disabling when we call L{disable}
3594- synchronously.
3595- """
3596- RegistrationMechanism._do_disabling = self.make_fake_disabling(True)
3597- self.mechanism = RegistrationMechanism(self.bus_name)
3598- self.assertTrue(self.mechanism.disable())
3599-
3600- def test_disabling_fail(self):
3601- """
3602- Test we get False from a failed disabling when we call L{disable}
3603- synchronously.
3604- """
3605- RegistrationMechanism._do_disabling = self.make_fake_disabling(False)
3606- self.mechanism = RegistrationMechanism(self.bus_name)
3607- self.assertFalse(self.mechanism.disable())
3608-
3609- def test_exit(self):
3610- """
3611- Test that we cause the mechanism to exit.
3612- """
3613- self.mechanism = RegistrationMechanism(self.bus_name)
3614- self.assertRaises(SystemExit, self.mechanism.exit)
3615-
3616- if dbus_test_should_skip:
3617- skip = dbus_skip_message
3618
3619=== removed file 'landscape/ui/model/registration/tests/test_proxy.py'
3620--- landscape/ui/model/registration/tests/test_proxy.py 2013-02-18 13:44:51 +0000
3621+++ landscape/ui/model/registration/tests/test_proxy.py 1970-01-01 00:00:00 +0000
3622@@ -1,141 +0,0 @@
3623-import dbus
3624-
3625-from landscape.tests.helpers import LandscapeTest
3626-from landscape.ui.tests.helpers import dbus_test_should_skip, dbus_skip_message
3627-if not dbus_test_should_skip:
3628- from landscape.ui.model.registration.mechanism import (
3629- RegistrationMechanism, INTERFACE_NAME)
3630- from landscape.ui.model.registration.proxy import RegistrationProxy
3631-
3632-
3633-class TimeoutTest(LandscapeTest):
3634- """
3635- L{TimeoutTest} bypasses DBus and tests with a faked method that raises a
3636- timeout exception.
3637- """
3638-
3639- def setUp(self):
3640- super(TimeoutTest, self).setUp()
3641- self.error_handler_messages = []
3642-
3643- class FakeBus(object):
3644- """
3645- Hello, I will be your fake DBus for this flight.
3646- """
3647-
3648- class FakeTimeoutException(dbus.DBusException):
3649- _dbus_error_name = "org.freedesktop.DBus.Error.NoReply"
3650-
3651- class FakeFailyMechanism(object):
3652-
3653- def register(this, config_path, reply_handler=None,
3654- error_handler=None):
3655- raise FakeTimeoutException()
3656-
3657- def fake_setup_interface(this, bus):
3658- this._interface = FakeFailyMechanism()
3659- this._bus = bus
3660-
3661- def fake_register_handlers(this):
3662- pass
3663-
3664- def fake_remove_handlers(this):
3665- pass
3666-
3667- def fake_error_handler(message):
3668- self.error_handler_messages.append(message)
3669-
3670- RegistrationProxy._setup_interface = fake_setup_interface
3671- RegistrationProxy._register_handlers = fake_register_handlers
3672- RegistrationProxy._remove_handlers = fake_remove_handlers
3673- self.proxy = RegistrationProxy(bus=FakeBus(),
3674- on_register_error=fake_error_handler)
3675-
3676- def tearDown(self):
3677- self.error_handler_messages = []
3678- super(TimeoutTest, self).tearDown()
3679-
3680- def test_register(self):
3681- """
3682- Test that the proxy calls through to the underlying interface and
3683- correctly performs registration.
3684- """
3685- self.proxy.register("foo")
3686- self.assertEqual(1, len(self.error_handler_messages))
3687- [message] = self.error_handler_messages
3688- self.assertEqual("Registration timed out.", message)
3689-
3690- if dbus_test_should_skip:
3691- skip = dbus_skip_message
3692-
3693-
3694-class RegistrationProxyTest(LandscapeTest):
3695- """
3696- L{RegistrationProxyTest} bypasses DBus to simply check the interface
3697- between the proxy and the mechanism it would usually contact via DBus.
3698- """
3699-
3700- def setUp(self):
3701- super(RegistrationProxyTest, self).setUp()
3702- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
3703- bus = dbus.SessionBus(private=True)
3704- bus_name = dbus.service.BusName(INTERFACE_NAME, bus)
3705-
3706- def fake_do__registration(this, config_path):
3707- return True, ""
3708-
3709- def fake_do__disabling(this):
3710- return True
3711-
3712- RegistrationMechanism._do_registration = fake_do__registration
3713- RegistrationMechanism._do_disabling = fake_do__disabling
3714- self.mechanism = RegistrationMechanism(bus_name)
3715-
3716- def fake_setup_interface(this, bus):
3717- """
3718- This just allows us to test without actually relying on dbus.
3719- """
3720- this._interface = self.mechanism
3721-
3722- def fake_register_handlers(this):
3723- pass
3724-
3725- def fake_remove_handlers(this):
3726- pass
3727-
3728- def fake_callback(message=None):
3729- pass
3730-
3731- RegistrationProxy._setup_interface = fake_setup_interface
3732- RegistrationProxy._register_handlers = fake_register_handlers
3733- RegistrationProxy._remove_handlers = fake_remove_handlers
3734- self.proxy = RegistrationProxy(fake_callback, fake_callback,
3735- fake_callback, fake_callback,
3736- fake_callback, fake_callback)
3737-
3738- def tearDown(self):
3739- self.mechanism.remove_from_connection()
3740- super(RegistrationProxyTest, self).tearDown()
3741-
3742- def test_register(self):
3743- """
3744- Test that the proxy calls through to the underlying interface and
3745- correctly performs registration.
3746- """
3747- self.assertEqual(True, self.proxy.register("foo"))
3748-
3749- def test_disable(self):
3750- """
3751- Test that the proxy calls through to the underlying interface and
3752- correctly performs disabling.
3753- """
3754- self.assertEqual(True, self.proxy.disable())
3755-
3756- def test_exit(self):
3757- """
3758- Test that we can cause the mechanism to exit.
3759- """
3760- self.assertRaises(SystemExit, self.proxy.exit)
3761-
3762- if dbus_test_should_skip:
3763- skip = dbus_skip_message
3764
3765=== removed directory 'landscape/ui/model/tests'
3766=== removed file 'landscape/ui/model/tests/__init__.py'
3767=== removed directory 'landscape/ui/tests'
3768=== removed file 'landscape/ui/tests/__init__.py'
3769=== removed file 'landscape/ui/tests/helpers.py'
3770--- landscape/ui/tests/helpers.py 2013-02-14 10:32:46 +0000
3771+++ landscape/ui/tests/helpers.py 1970-01-01 00:00:00 +0000
3772@@ -1,188 +0,0 @@
3773-import os
3774-
3775-from lxml import etree
3776-import dbus
3777-
3778-from landscape.configuration import LandscapeSetupConfiguration
3779-
3780-dbus_test_should_skip = False
3781-dbus_skip_message = "Cannot launch private DBus session without X11"
3782-try:
3783- from gi.repository import GObject, Gtk
3784- got_gobject_introspection = True
3785- # Shut up pyflakes
3786- dbus_skip_message = GObject._version + str(Gtk.MAJOR_VERSION)
3787-except (ImportError, RuntimeError):
3788- got_gobject_introspection = False
3789- dbus_test_should_skip = True
3790- dbus_skip_message = "GObject Introspection module unavailable"
3791- bus = object
3792- bus_name = ""
3793-
3794-
3795-if got_gobject_introspection:
3796- from gi.repository import Gdk
3797- from landscape.ui.model.configuration.mechanism import (
3798- INTERFACE_NAME, ConfigurationMechanism)
3799- from landscape.ui.model.configuration.proxy import ConfigurationProxy
3800- # We have to do these steps because the ConfigurationMechanism inherits
3801- # from dbus.service.Object which throws a fit if it notices you using
3802- # it without a mainloop.
3803- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
3804- try:
3805- bus = dbus.SessionBus(private=True)
3806- bus_name = dbus.service.BusName(INTERFACE_NAME, bus)
3807- except dbus.exceptions.DBusException:
3808- bus = object
3809- bus_name = ""
3810- dbus_test_should_skip = True
3811- dbus_skip_message = "Cannot launch private DBus session without X11"
3812-
3813-
3814-class ConfigurationProxyHelper(object):
3815- """
3816- L{ConfigurationProxyHelper} will provide it's test case with a
3817- L{ConfigurationProxy} setup in such a way that it uses a real
3818- L{ConfigurationMechanism} (which in turn uses a real
3819- L{LandscapeSetupConfiguration}) but which does not make use of DBus for
3820- communication.
3821-
3822- Tests utilising this helper must define a L{test_case.config_string} for
3823- use in L{set_up} below.
3824- """
3825-
3826- def set_up(self, test_case):
3827- if not dbus_test_should_skip:
3828- test_case.config_filename = test_case.makeFile(
3829- test_case.config_string)
3830- test_case.config = LandscapeSetupConfiguration()
3831- test_case.config.default_config_filenames = \
3832- [test_case.config_filename]
3833-
3834- if got_gobject_introspection:
3835- test_case.mechanism = ConfigurationMechanism(test_case.config,
3836- bus_name)
3837-
3838- test_case.proxy = ConfigurationProxy(
3839- interface=test_case.mechanism)
3840- test_case.proxy.load(["-c", test_case.config_filename])
3841-
3842- def tear_down(self, test_case):
3843- if not dbus_test_should_skip and got_gobject_introspection:
3844- test_case.mechanism.remove_from_connection()
3845-
3846-
3847-class FakeGSettings(object):
3848- """
3849- This class impersonates a real L{gi.repostiroy.Gio.GSettings}
3850- object to allow for testing code that utilises it without setting values in
3851- the live DConf.
3852- """
3853-
3854- calls = {}
3855-
3856- def __init__(self, data={}):
3857- self.set_data(data)
3858- tree = etree.parse(
3859- os.path.join(
3860- os.path.dirname(os.path.abspath(__file__)),
3861- "../../../",
3862- "glib-2.0/schemas/",
3863- "com.canonical.landscape-client-settings.gschema.xml"))
3864- root = tree.getroot()
3865- self.schema = root.find("schema")
3866- assert(self.schema.attrib["id"] ==
3867- "com.canonical.landscape-client-settings")
3868- self.keys = {}
3869- for key in self.schema.findall("key"):
3870- self.keys[key.attrib["name"]] = key.attrib["type"]
3871-
3872- def check_key_data(self, name, gstype):
3873- if name in self.keys:
3874- if self.keys[name] == gstype:
3875- return True
3876- else:
3877- raise ValueError("The GSchema file says %s is a %s, " +
3878- "but you asked for a %s" %
3879- (name, self.keys[name], gstype))
3880- else:
3881- raise KeyError("Can't find %s in the GSchema file!" % name)
3882-
3883- def get_value(self, name, gstype):
3884- if self.check_key_data(name, gstype):
3885- return self.data[name]
3886-
3887- def set_value(self, name, gstype, value):
3888- if self.check_key_data(name, gstype):
3889- self.data[name] = value
3890-
3891- def set_data(self, data):
3892- self.data = data
3893-
3894- def _call(self, name, *args):
3895- [count, arglist] = self.calls.get(name, (0, []))
3896- count += 1
3897- arglist.append(self._args_to_string(*args))
3898- self.calls[name] = [count, arglist]
3899-
3900- def _args_to_string(self, *args):
3901- return "|".join([str(arg) for arg in args])
3902-
3903- def new(self, key):
3904- self._call("new", key)
3905- return self
3906-
3907- def connect(self, signal, callback, *args):
3908- self._call("connect", signal, callback, *args)
3909-
3910- def get_boolean(self, name):
3911- self._call("get_boolean", name)
3912- return self.get_value(name, "b")
3913-
3914- def set_boolean(self, name, value):
3915- self._call("set_boolean", name, value)
3916- self.set_value(name, "b", value)
3917-
3918- def get_string(self, name):
3919- self._call("get_string", name)
3920- return self.get_value(name, "s")
3921-
3922- def set_string(self, name, value):
3923- self._call("set_string", name, value)
3924- self.set_value(name, "s", value)
3925-
3926- def was_called(self, name):
3927- return self.calls.haskey(name)
3928-
3929- def was_called_with_args(self, name, *args):
3930- try:
3931- [count, arglist] = self.calls.get(name, (0, []))
3932- except KeyError:
3933- return False
3934-
3935- expected_args = self._args_to_string(*args)
3936- return expected_args in arglist
3937-
3938-
3939-def simulate_gtk_key_release(widget, key):
3940- """
3941- Simulates a keypress in a widget
3942-
3943- @param widget: The widget which should receive the keypress.
3944- @param key: The key to use.
3945- """
3946- widget.insert_text(key, -1)
3947-
3948-
3949-def simulate_gtk_paste(widget, pasted_text):
3950- """
3951- Simulates pasting text into a editable element.
3952-
3953- @param widget: The widget which should receive the paste.
3954- @param pasted_text: The text to paste into the widget.
3955- """
3956- widget.set_text("")
3957- clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
3958- clipboard.set_text(pasted_text, len=-1)
3959- widget.set_position(0)
3960- widget.paste_clipboard()
3961
3962=== removed directory 'landscape/ui/view'
3963=== removed file 'landscape/ui/view/__init__.py'
3964=== removed file 'landscape/ui/view/configuration.py'
3965--- landscape/ui/view/configuration.py 2012-08-27 15:35:05 +0000
3966+++ landscape/ui/view/configuration.py 1970-01-01 00:00:00 +0000
3967@@ -1,356 +0,0 @@
3968-import re
3969-import os
3970-
3971-from gettext import gettext as _
3972-
3973-from gi.repository import GObject, Gtk
3974-
3975-from landscape.ui.constants import (
3976- CANONICAL_MANAGED, LOCAL_MANAGED, NOT_MANAGED)
3977-
3978-# Note, I think this may not be fully compliant with the changes in RFC 1123
3979-HOST_NAME_REGEXP = re.compile("^(([a-zA-Z][a-zA-Z0-9\-]*)?[a-zA-Z0-9][\.]?)*"
3980- "(([A-Za-z][A-Za-z0-9\-]*)?[A-Za-z0-9])$")
3981-
3982-
3983-def sanitise_host_name(host_name):
3984- """
3985- Do some minimal host name sanitation.
3986- """
3987- return host_name.strip()
3988-
3989-
3990-def is_valid_host_name(host_name):
3991- """
3992- Check that the provided host name complies with L{HOST_NAME_REGEXP} and is
3993- therefor valid.
3994- """
3995- return HOST_NAME_REGEXP.match(host_name) is not None
3996-
3997-
3998-def is_ascii(text):
3999- """
4000- Test that the provided string contains only characters from the ASCII set.
4001- """
4002- try:
4003- text.decode("ascii")
4004- return True
4005- except UnicodeDecodeError:
4006- return False
4007-
4008-
4009-class ClientSettingsDialog(Gtk.Dialog):
4010- """
4011- L{ClientSettingsDialog} is a subclass of Gtk.Dialog that loads the UI
4012- components from the associated Glade XML file and wires everything up to
4013- the controller.
4014- """
4015-
4016- GLADE_FILE = "landscape-client-settings.glade"
4017- INVALID_HOST_NAME = 0
4018- UNICODE_IN_ENTRY = 1
4019-
4020- def __init__(self, controller):
4021- super(ClientSettingsDialog, self).__init__(
4022- title=_("Landscape Service"),
4023- flags=Gtk.DialogFlags.MODAL)
4024- self.set_default_icon_name("preferences-management-service")
4025- self.set_resizable(False)
4026- self._initialised = False
4027- self._validation_errors = set()
4028- self._errored_entries = []
4029- self.controller = controller
4030- self.setup_ui()
4031- self.load_data()
4032- # One extra revert to reset after loading data
4033- self.controller.revert()
4034-
4035- def indicate_error_on_entry(self, entry):
4036- """
4037- Show a warning icon on a L{Gtk.Entry} to indicate some associated
4038- error.
4039- """
4040- entry.set_icon_from_stock(
4041- Gtk.EntryIconPosition.PRIMARY, Gtk.STOCK_DIALOG_WARNING)
4042- self._errored_entries.append(entry)
4043-
4044- def check_local_landscape_host_name_entry(self):
4045- host_name = sanitise_host_name(
4046- self.local_landscape_host_entry.get_text())
4047- ascii_ok = is_ascii(host_name)
4048- host_name_ok = is_valid_host_name(host_name)
4049- if ascii_ok and host_name_ok:
4050- self.local_landscape_host_entry.set_text(host_name)
4051- return True
4052- else:
4053- self.indicate_error_on_entry(self.local_landscape_host_entry)
4054- if not host_name_ok:
4055- self._validation_errors.add(self.INVALID_HOST_NAME)
4056- if not ascii_ok:
4057- self._validation_errors.add(self.UNICODE_IN_ENTRY)
4058- return False
4059-
4060- def check_entry(self, entry):
4061- """
4062- Check that the text content of a L{Gtk.Entry} is acceptable.
4063- """
4064- if is_ascii(entry.get_text()):
4065- return True
4066- else:
4067- self.indicate_error_on_entry(entry)
4068- self._validation_errors.add(self.UNICODE_IN_ENTRY)
4069- return False
4070-
4071- def validity_check(self):
4072- self._validation_errors = set()
4073- if self._info_bar_container.get_visible():
4074- self.dismiss_infobar(None)
4075- active_iter = self.liststore.get_iter(
4076- self.use_type_combobox.get_active())
4077- [management_type] = self.liststore.get(active_iter, 0)
4078- if management_type == NOT_MANAGED:
4079- return True
4080- elif management_type == CANONICAL_MANAGED:
4081- account_name_ok = self.check_entry(self.hosted_account_name_entry)
4082- password_ok = self.check_entry(self.hosted_password_entry)
4083- return account_name_ok and password_ok
4084- else:
4085- host_name_ok = self.check_local_landscape_host_name_entry()
4086- password_ok = self.check_entry(self.local_password_entry)
4087- return host_name_ok and password_ok
4088-
4089- @property
4090- def NO_SERVICE_TEXT(self):
4091- return _("None")
4092-
4093- @property
4094- def HOSTED_SERVICE_TEXT(self):
4095- return _("Landscape - hosted by Canonical")
4096-
4097- @property
4098- def LOCAL_SERVICE_TEXT(self):
4099- return _("Landscape - dedicated server")
4100-
4101- @property
4102- def REGISTER_BUTTON_TEXT(self):
4103- return _("Register")
4104-
4105- @property
4106- def DISABLE_BUTTON_TEXT(self):
4107- return _("Disable")
4108-
4109- @property
4110- def INVALID_HOST_NAME_MESSAGE(self):
4111- return _("Invalid host name.")
4112-
4113- @property
4114- def UNICODE_IN_ENTRY_MESSAGE(self):
4115- return _("Only ASCII characters are allowed.")
4116-
4117- def _set_use_type_combobox_from_controller(self):
4118- """
4119- Load the persisted L{management_type} from the controller and set the
4120- combobox appropriately.
4121-
4122- Note that Gtk makes us jump through some hoops by having it's own model
4123- level to deal with here. The conversion between paths and iters makes
4124- more sense if you understand that treeviews use the same model.
4125- """
4126- list_iter = self.liststore.get_iter_first()
4127- while (self.liststore.get(list_iter, 0)[0] !=
4128- self.controller.management_type):
4129- list_iter = self.liststore.iter_next(list_iter)
4130- path = self.liststore.get_path(list_iter)
4131- [index] = path.get_indices()
4132- self.use_type_combobox.set_active(index)
4133-
4134- def _set_hosted_values_from_controller(self):
4135- self.hosted_account_name_entry.set_text(
4136- self.controller.hosted_account_name)
4137- self.hosted_password_entry.set_text(self.controller.hosted_password)
4138-
4139- def _set_local_values_from_controller(self):
4140- self.local_landscape_host_entry.set_text(
4141- self.controller.local_landscape_host)
4142- self.local_password_entry.set_text(self.controller.local_password)
4143-
4144- def load_data(self):
4145- self._initialised = False
4146- self.controller.load()
4147- self._set_hosted_values_from_controller()
4148- self._set_local_values_from_controller()
4149- self._set_use_type_combobox_from_controller()
4150- self._initialised = True
4151-
4152- def make_liststore(self):
4153- """
4154- Construct the correct L{Gtk.ListStore} to drive the L{Gtk.ComboBox} for
4155- use-type. This a table of:
4156-
4157- * Management type (key)
4158- * Text to display in the combobox
4159- * L{Gtk.Frame} to load when this item is selected.
4160- """
4161- liststore = Gtk.ListStore(GObject.TYPE_PYOBJECT,
4162- GObject.TYPE_STRING,
4163- GObject.TYPE_PYOBJECT)
4164- self.active_widget = None
4165- liststore.append([NOT_MANAGED, self.NO_SERVICE_TEXT,
4166- self._builder.get_object("no-service-frame")])
4167- liststore.append([CANONICAL_MANAGED, self.HOSTED_SERVICE_TEXT,
4168- self._builder.get_object("hosted-service-frame")])
4169- liststore.append([LOCAL_MANAGED, self.LOCAL_SERVICE_TEXT,
4170- self._builder.get_object("local-service-frame")])
4171- return liststore
4172-
4173- def link_hosted_service_widgets(self):
4174- self.hosted_account_name_entry = self._builder.get_object(
4175- "hosted-account-name-entry")
4176- self.hosted_account_name_entry.connect(
4177- "changed", self.on_changed_event, "hosted_account_name")
4178-
4179- self.hosted_password_entry = self._builder.get_object(
4180- "hosted-password-entry")
4181- self.hosted_password_entry.connect(
4182- "changed", self.on_changed_event, "hosted_password")
4183-
4184- def link_local_service_widgets(self):
4185- self.local_landscape_host_entry = self._builder.get_object(
4186- "local-landscape-host-entry")
4187- self.local_landscape_host_entry.connect(
4188- "changed", self.on_changed_event, "local_landscape_host")
4189-
4190- self.local_password_entry = self._builder.get_object(
4191- "local-password-entry")
4192- self.local_password_entry.connect(
4193- "changed", self.on_changed_event, "local_password")
4194-
4195- def link_use_type_combobox(self, liststore):
4196- self.use_type_combobox = self._builder.get_object("use-type-combobox")
4197- self.use_type_combobox.connect("changed", self.on_combo_changed)
4198- self.use_type_combobox.set_model(liststore)
4199- cell = Gtk.CellRendererText()
4200- self.use_type_combobox.pack_start(cell, True)
4201- self.use_type_combobox.add_attribute(cell, 'text', 1)
4202-
4203- def cancel_response(self, widget):
4204- self.response(Gtk.ResponseType.CANCEL)
4205-
4206- def register_response(self, widget):
4207- if self.validity_check():
4208- self.response(Gtk.ResponseType.OK)
4209- else:
4210- error_text = []
4211- if self.UNICODE_IN_ENTRY in self._validation_errors:
4212- error_text.append(self.UNICODE_IN_ENTRY_MESSAGE)
4213- if self.INVALID_HOST_NAME in self._validation_errors:
4214- error_text.append(self.INVALID_HOST_NAME_MESSAGE)
4215- self.info_message.set_text("\n".join(error_text))
4216- self._info_bar_container.show()
4217-
4218- def set_button_text(self, management_type):
4219- [alignment] = self.register_button.get_children()
4220- [hbox] = alignment.get_children()
4221- [image, label] = hbox.get_children()
4222- if management_type == NOT_MANAGED:
4223- label.set_text(self.DISABLE_BUTTON_TEXT)
4224- else:
4225- label.set_text(self.REGISTER_BUTTON_TEXT)
4226-
4227- def setup_buttons(self):
4228- self.revert_button = Gtk.Button(stock=Gtk.STOCK_REVERT_TO_SAVED)
4229- self.action_area.pack_start(self.revert_button, True, True, 0)
4230- self.revert_button.connect("clicked", self.revert)
4231- self.revert_button.show()
4232- self.cancel_button = Gtk.Button(stock=Gtk.STOCK_CANCEL)
4233- self.action_area.pack_start(self.cancel_button, True, True, 0)
4234- self.cancel_button.show()
4235- self.cancel_button.connect("clicked", self.cancel_response)
4236- self.register_button = Gtk.Button(stock=Gtk.STOCK_OK)
4237- self.action_area.pack_start(self.register_button, True, True, 0)
4238- self.register_button.show()
4239- self.register_button.connect("clicked", self.register_response)
4240-
4241- def dismiss_infobar(self, widget):
4242- self._info_bar_container.hide()
4243- for entry in self._errored_entries:
4244- entry.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, None)
4245- self._errored_entries = []
4246-
4247- def setup_info_bar(self):
4248- labels_size_group = self._builder.get_object("labels-sizegroup")
4249- entries_size_group = self._builder.get_object("entries-sizegroup")
4250- labels_size_group.set_ignore_hidden(False)
4251- entries_size_group.set_ignore_hidden(False)
4252- self._info_bar_container = Gtk.HBox()
4253- self._info_bar_container.set_spacing(12)
4254- info_bar = Gtk.InfoBar()
4255- entries_size_group.add_widget(info_bar)
4256- info_bar.show()
4257- empty_label = Gtk.Label()
4258- labels_size_group.add_widget(empty_label)
4259- empty_label.show()
4260- self._info_bar_container.pack_start(empty_label, expand=False,
4261- fill=False, padding=0)
4262- self._info_bar_container.pack_start(info_bar, expand=False, fill=False,
4263- padding=0)
4264- content_area = info_bar.get_content_area()
4265- hbox = Gtk.HBox()
4266- self.info_message = Gtk.Label()
4267- self.info_message.set_alignment(0, 0.5)
4268- self.info_message.show()
4269- hbox.pack_start(self.info_message, expand=True, fill=True, padding=6)
4270- ok_button = Gtk.Button("Dismiss")
4271- ok_button.connect("clicked", self.dismiss_infobar)
4272- ok_button.show()
4273- hbox.pack_start(ok_button, expand=True, fill=True, padding=0)
4274- hbox.show()
4275- content_area.pack_start(hbox, expand=True, fill=True, padding=0)
4276-
4277- def setup_ui(self):
4278- self._builder = Gtk.Builder()
4279- self._builder.set_translation_domain("landscape-client")
4280- self._builder.add_from_file(
4281- os.path.join(
4282- os.path.dirname(__file__), "ui", self.GLADE_FILE))
4283- content_area = self.get_content_area()
4284- content_area.set_spacing(12)
4285- self.set_border_width(12)
4286- self.setup_info_bar()
4287- self._vbox = self._builder.get_object("toplevel-vbox")
4288- self._vbox.unparent()
4289- content_area.pack_start(self._vbox, expand=True, fill=True,
4290- padding=12)
4291- self._vbox.pack_start(self._info_bar_container, expand=False,
4292- fill=False, padding=0)
4293- self.liststore = self.make_liststore()
4294- self.link_use_type_combobox(self.liststore)
4295- self.link_hosted_service_widgets()
4296- self.link_local_service_widgets()
4297- self.setup_buttons()
4298-
4299- def on_combo_changed(self, combobox):
4300- list_iter = self.liststore.get_iter(combobox.get_active())
4301- if not self.active_widget is None:
4302- self._vbox.remove(self.active_widget)
4303- [management_type] = self.liststore.get(list_iter, 0)
4304- self.set_button_text(management_type)
4305- if self._initialised:
4306- self.controller.management_type = management_type
4307- self.controller.modify()
4308- [self.active_widget] = self.liststore.get(list_iter, 2)
4309- self.active_widget.unparent()
4310- self._vbox.add(self.active_widget)
4311-
4312- def on_changed_event(self, widget, attribute):
4313- setattr(self.controller, attribute, widget.get_text())
4314- self.controller.modify()
4315-
4316- def quit(self, *args):
4317- self.destroy()
4318-
4319- def revert(self, button):
4320- self.controller.revert()
4321- self.load_data()
4322- # One extra revert to reset after loading data
4323- self.controller.revert()
4324
4325=== removed directory 'landscape/ui/view/tests'
4326=== removed file 'landscape/ui/view/tests/__init__.py'
4327=== removed file 'landscape/ui/view/tests/test_configuration.py'
4328--- landscape/ui/view/tests/test_configuration.py 2013-02-14 10:32:46 +0000
4329+++ landscape/ui/view/tests/test_configuration.py 1970-01-01 00:00:00 +0000
4330@@ -1,608 +0,0 @@
4331-import sys
4332-
4333-from landscape.ui.tests.helpers import (
4334- ConfigurationProxyHelper, FakeGSettings, dbus_test_should_skip,
4335- dbus_skip_message, simulate_gtk_key_release, simulate_gtk_paste)
4336-
4337-if not dbus_test_should_skip:
4338- from gi.repository import Gtk
4339- from landscape.ui.view.configuration import (
4340- ClientSettingsDialog, sanitise_host_name, is_valid_host_name)
4341- from landscape.ui.controller.configuration import ConfigController
4342- import landscape.ui.model.configuration.state
4343- from landscape.ui.model.configuration.state import (
4344- COMPUTER_TITLE, ConfigurationModel)
4345- from landscape.ui.model.configuration.uisettings import UISettings
4346-
4347-from landscape.tests.helpers import LandscapeTest
4348-
4349-
4350-class ViewFunctionsTest(LandscapeTest):
4351-
4352- def test_sanitise_host_name(self):
4353- """
4354- Test UI level host_name sanitation.
4355- """
4356- self.assertEqual("foo.bar", sanitise_host_name(" foo.bar"))
4357- self.assertEqual("foo.bar", sanitise_host_name("foo.bar "))
4358- self.assertEqual("foo.bar", sanitise_host_name(" foo.bar "))
4359-
4360- def test_is_valid_host_name_ok(self):
4361- """
4362- Test that valid host names cause L{is_valid_host_name} to return
4363- L{True}.
4364- """
4365- self.assertTrue(is_valid_host_name("a"))
4366- self.assertTrue(is_valid_host_name("a.b"))
4367- self.assertTrue(is_valid_host_name("a.b.c"))
4368- self.assertTrue(is_valid_host_name("stop-squark"))
4369- self.assertTrue(is_valid_host_name("stop-squark.teale.DE"))
4370- self.assertTrue(is_valid_host_name("a2.b3.c4"))
4371-
4372- def test_is_valid_host_name_bad(self):
4373- """
4374- Test that invalid host names cause L{is_valid_host_name} to return
4375- L{False}.
4376- """
4377- self.assertFalse(is_valid_host_name(".a"))
4378- self.assertFalse(is_valid_host_name("a."))
4379- self.assertFalse(is_valid_host_name("a b"))
4380- self.assertFalse(is_valid_host_name("a .b"))
4381- self.assertFalse(is_valid_host_name("a. b"))
4382-
4383- def test_is_valid_host_name_unicode(self):
4384- """
4385- Test that host names containing Unicode cause L{is_valid_host_name} to
4386- return L{False}.
4387- """
4388- self.assertFalse(is_valid_host_name(u"\xc3a"))
4389-
4390- if dbus_test_should_skip:
4391- skip = dbus_skip_message
4392-
4393-
4394-class ConfigurationViewTest(LandscapeTest):
4395-
4396- helpers = [ConfigurationProxyHelper]
4397-
4398- def setUp(self):
4399- self.default_data = {"management-type": "canonical",
4400- "computer-title": "",
4401- "hosted-landscape-host": "",
4402- "hosted-account-name": "",
4403- "hosted-password": "",
4404- "local-landscape-host": "",
4405- "local-account-name": "",
4406- "local-password": ""}
4407-
4408- self.config_string = (
4409- "[client]\n"
4410- "data_path = %s\n"
4411- "http_proxy = http://proxy.localdomain:3192\n"
4412- "tags = a_tag\n"
4413- "url = https://landscape.canonical.com/message-system\n"
4414- "account_name = foo\n"
4415- "registration_key = bar\n"
4416- "computer_title = baz\n"
4417- "https_proxy = https://proxy.localdomain:6192\n"
4418- "ping_url = http://landscape.canonical.com/ping\n" % sys.path[0])
4419-
4420- super(ConfigurationViewTest, self).setUp()
4421- landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
4422- = "me.here.com"
4423- settings = FakeGSettings(data=self.default_data)
4424- self.uisettings = UISettings(settings)
4425- model = ConfigurationModel(proxy=self.proxy,
4426- uisettings=self.uisettings)
4427- self.controller = ConfigController(model)
4428-
4429- def run_gtk_eventloop(self):
4430- """Run the Gtk event loop until all events have been processed."""
4431- while Gtk.events_pending():
4432- Gtk.main_iteration()
4433-
4434- def assert_paste_data_saved(self, dialog, combo, widget, attribute):
4435- """
4436- Paste text into specified widget then verify data is saved.
4437- """
4438- # Switch to local mode
4439- dialog.use_type_combobox.set_active(combo)
4440- self.run_gtk_eventloop()
4441-
4442- simulate_gtk_paste(widget, "pasted text")
4443- self.run_gtk_eventloop()
4444- self.assertTrue(self.controller.is_modified)
4445- self.assertEqual("pasted text", getattr(self.controller, attribute))
4446-
4447- dialog.revert(None)
4448- self.run_gtk_eventloop()
4449- self.assertFalse(self.controller.is_modified)
4450-
4451- def test_init(self):
4452- """
4453- Test that we correctly initialise the L{ConfigurationView} correctly
4454- from the controller.
4455- """
4456- dialog = ClientSettingsDialog(self.controller)
4457- content_area = dialog.get_content_area()
4458- self.assertEqual("preferences-management-service",
4459- dialog.get_default_icon_name())
4460- children = content_area.get_children()
4461- self.assertEqual(len(children), 2)
4462- box = children[0]
4463- self.assertIsInstance(box, Gtk.Box)
4464- self.assertEqual(1, dialog.use_type_combobox.get_active())
4465-
4466- def test_on_combobox_changed(self):
4467- """
4468- Test that changes to the active selection in L{use_type_combobox}
4469- result in the correct panel becoming active and visible.
4470- """
4471- dialog = ClientSettingsDialog(self.controller)
4472- iter = dialog.liststore.get_iter(0)
4473- no_service_frame = dialog.liststore.get(iter, 2)[0]
4474- iter = dialog.liststore.get_iter(1)
4475- hosted_service_frame = dialog.liststore.get(iter, 2)[0]
4476- iter = dialog.liststore.get_iter(2)
4477- local_service_frame = dialog.liststore.get(iter, 2)[0]
4478-
4479- self.assertEqual(1, dialog.use_type_combobox.get_active())
4480- [alignment] = dialog.register_button.get_children()
4481- [hbox] = alignment.get_children()
4482- [image, label] = hbox.get_children()
4483-
4484- self.run_gtk_eventloop()
4485- self.assertIs(hosted_service_frame, dialog.active_widget)
4486- self.assertEqual(dialog.REGISTER_BUTTON_TEXT, label.get_text())
4487-
4488- dialog.use_type_combobox.set_active(0)
4489- self.run_gtk_eventloop()
4490- self.assertIs(no_service_frame, dialog.active_widget)
4491- self.assertEqual(dialog.DISABLE_BUTTON_TEXT, label.get_text())
4492-
4493- dialog.use_type_combobox.set_active(2)
4494- self.run_gtk_eventloop()
4495- self.assertIs(local_service_frame, dialog.active_widget)
4496- self.assertEqual(dialog.REGISTER_BUTTON_TEXT, label.get_text())
4497-
4498- def test_modify(self):
4499- """
4500- Test that modifications to data in the UI are propagated to the
4501- controller.
4502- """
4503- dialog = ClientSettingsDialog(self.controller)
4504- self.run_gtk_eventloop()
4505- self.assertFalse(self.controller.is_modified)
4506- self.assertEqual(1, dialog.use_type_combobox.get_active())
4507- dialog.use_type_combobox.set_active(2)
4508- self.run_gtk_eventloop()
4509- self.assertTrue(self.controller.is_modified)
4510- dialog.revert(None)
4511- self.run_gtk_eventloop()
4512- self.assertFalse(self.controller.is_modified)
4513- simulate_gtk_key_release(dialog.hosted_account_name_entry, "A")
4514- self.run_gtk_eventloop()
4515- self.assertTrue(self.controller.is_modified)
4516- dialog.revert(None)
4517- self.run_gtk_eventloop()
4518- self.assertFalse(self.controller.is_modified)
4519- simulate_gtk_key_release(dialog.hosted_password_entry, "B")
4520- self.run_gtk_eventloop()
4521- self.assertTrue(self.controller.is_modified)
4522- dialog.revert(None)
4523- self.run_gtk_eventloop()
4524- self.assertFalse(self.controller.is_modified)
4525- simulate_gtk_key_release(dialog.local_landscape_host_entry, "C")
4526- self.run_gtk_eventloop()
4527- self.assertTrue(self.controller.is_modified)
4528-
4529- def test_modify_with_paste(self):
4530- """
4531- Non-keypress modifications to data in the UI are propagated to the
4532- controller.
4533- """
4534- dialog = ClientSettingsDialog(self.controller)
4535- self.run_gtk_eventloop()
4536- self.assertFalse(self.controller.is_modified)
4537- self.assertEqual(1, dialog.use_type_combobox.get_active())
4538- # Test hosted account name
4539- self.assert_paste_data_saved(dialog, 1,
4540- dialog.hosted_account_name_entry,
4541- "hosted_account_name")
4542- # Test hosted password
4543- self.assert_paste_data_saved(dialog, 1,
4544- dialog.hosted_password_entry,
4545- "hosted_password")
4546- # Test local hostname
4547- self.assert_paste_data_saved(dialog, 2,
4548- dialog.local_landscape_host_entry,
4549- "local_landscape_host")
4550- # Test local password
4551- self.assert_paste_data_saved(dialog, 2,
4552- dialog.local_password_entry,
4553- "local_password")
4554-
4555- def test_load_data_from_config(self):
4556- """
4557- Test that we load data into the appropriate entries from the
4558- configuration file.
4559- """
4560- dialog = ClientSettingsDialog(self.controller)
4561- self.assertEqual(1, dialog.use_type_combobox.get_active())
4562- self.assertEqual("foo", dialog.hosted_account_name_entry.get_text())
4563- self.assertEqual("bar", dialog.hosted_password_entry.get_text())
4564- self.assertEqual("", dialog.local_landscape_host_entry.get_text())
4565- self.assertEqual("", dialog.local_password_entry.get_text())
4566-
4567- def test_revert(self):
4568- """
4569- Test that we can revert the UI values using the controller.
4570- """
4571- dialog = ClientSettingsDialog(self.controller)
4572- self.run_gtk_eventloop()
4573- self.assertEqual(1, dialog.use_type_combobox.get_active())
4574- self.assertEqual("foo", dialog.hosted_account_name_entry.get_text())
4575- self.assertEqual("bar", dialog.hosted_password_entry.get_text())
4576- dialog.use_type_combobox.set_active(2)
4577- dialog.local_landscape_host_entry.set_text("more.barn")
4578- self.run_gtk_eventloop()
4579- self.assertEqual("bar", dialog.hosted_password_entry.get_text())
4580- self.assertEqual("more.barn",
4581- dialog.local_landscape_host_entry.get_text())
4582- dialog.revert(None)
4583- self.run_gtk_eventloop()
4584- self.assertEqual(1, dialog.use_type_combobox.get_active())
4585- self.assertEqual("foo", dialog.hosted_account_name_entry.get_text())
4586- self.assertEqual("bar", dialog.hosted_password_entry.get_text())
4587-
4588- def test_check_local_landscape_host_name_entry_ok(self):
4589- """
4590- Test that L{check_local_landscape_host_name_entry} returns L{True} when
4591- the input is a valid host name.
4592- """
4593- dialog = ClientSettingsDialog(self.controller)
4594- dialog.use_type_combobox.set_active(2)
4595- dialog.local_landscape_host_entry.set_text("foo.bar")
4596- self.assertTrue(dialog.check_local_landscape_host_name_entry())
4597-
4598- def test_check_local_landscape_host_name_entry_ok_not_recorded(self):
4599- """
4600- Test that L{check_local_landscape_host_name_entry} does not add the
4601- entry to L{ClientSettingsDialog._errored_entries} when the input is a
4602- valid host name.
4603- """
4604- dialog = ClientSettingsDialog(self.controller)
4605- dialog.use_type_combobox.set_active(2)
4606- dialog.local_landscape_host_entry.set_text("foo.bar")
4607- dialog.check_local_landscape_host_name_entry()
4608- self.assertEqual(0, len(dialog._errored_entries))
4609-
4610- def test_check_local_landscape_host_name_entry_bad_host_name(self):
4611- """
4612- Test that L{check_local_landscape_host_name_entry} returns L{False}
4613- when the input is not a valid host name.
4614- """
4615- dialog = ClientSettingsDialog(self.controller)
4616- dialog.use_type_combobox.set_active(2)
4617- dialog.local_landscape_host_entry.set_text("foo bar")
4618- self.assertFalse(dialog.check_local_landscape_host_name_entry())
4619-
4620- def test_check_local_landscape_host_name_entry_bad_recorded(self):
4621- """
4622- Test that L{check_local_landscape_host_name_entry} does add the
4623- entry to L{ClientSettingsDialog._errored_entries} when the input is not
4624- a valid host name.
4625- """
4626- dialog = ClientSettingsDialog(self.controller)
4627- dialog.use_type_combobox.set_active(2)
4628- dialog.local_landscape_host_entry.set_text("foo bar")
4629- dialog.check_local_landscape_host_name_entry()
4630- self.assertEqual(1, len(dialog._errored_entries))
4631-
4632- def test_check_local_landscape_host_name_entry_bad_error_type(self):
4633- """
4634- Test that L{check_local_landscape_host_name_entry} adds the correct
4635- error type to L{ClientSettingsDialog._validation_errors} when the input
4636- is not a valid host name.
4637- """
4638- dialog = ClientSettingsDialog(self.controller)
4639- dialog.use_type_combobox.set_active(2)
4640- dialog.local_landscape_host_entry.set_text("foo bar")
4641- dialog.check_local_landscape_host_name_entry()
4642- self.assertEqual(set([dialog.INVALID_HOST_NAME]),
4643- dialog._validation_errors)
4644-
4645- def test_check_local_landscape_host_name_entry_unicode_in_host_name(self):
4646- """
4647- Test that L{check_local_landscape_host_name_entry} returns L{False}
4648- when the input contains Unicode.
4649- """
4650- dialog = ClientSettingsDialog(self.controller)
4651- dialog.use_type_combobox.set_active(2)
4652- dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
4653- self.assertFalse(dialog.check_local_landscape_host_name_entry())
4654-
4655- def test_check_local_landscape_host_name_entry_unicode_recorded(self):
4656- """
4657- Test that L{check_local_landscape_host_name_entry} does add the
4658- entry to L{ClientSettingsDialog._errored_entries} when the input
4659- contains Unicode.
4660- """
4661- dialog = ClientSettingsDialog(self.controller)
4662- dialog.use_type_combobox.set_active(2)
4663- dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
4664- dialog.check_local_landscape_host_name_entry()
4665- self.assertEqual(1, len(dialog._errored_entries))
4666-
4667- def test_check_local_landscape_host_name_entry_unicode_error_type(self):
4668- """
4669- Test that L{check_local_landscape_host_name_entry} adds the correct
4670- error type to L{ClientSettingsDialog._validation_errors} when the input
4671- contains Unicode.
4672- """
4673- dialog = ClientSettingsDialog(self.controller)
4674- dialog.use_type_combobox.set_active(2)
4675- dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
4676- dialog.check_local_landscape_host_name_entry()
4677- self.assertEqual(
4678- set([dialog.INVALID_HOST_NAME, dialog.UNICODE_IN_ENTRY]),
4679- dialog._validation_errors)
4680-
4681- def test_check_entry_ok(self):
4682- """
4683- Test that we return L{True} when the text of a L{Gtk.Entry} is valid
4684- input.
4685- """
4686- dialog = ClientSettingsDialog(self.controller)
4687- self.run_gtk_eventloop()
4688- dialog.use_type_combobox.set_active(1)
4689- self.run_gtk_eventloop()
4690- dialog.hosted_account_name_entry.set_text("Toodleoo")
4691- self.assertTrue(dialog.check_entry(dialog.hosted_account_name_entry))
4692-
4693- def test_check_entry_doesnt_record_entry_when_ok(self):
4694- """
4695- Test that, when the text of a L{Gtk.Entry} is valid nothing is added to
4696- L{ClientSettingsDialog._errored_entries}.
4697- """
4698- dialog = ClientSettingsDialog(self.controller)
4699- self.run_gtk_eventloop()
4700- dialog.use_type_combobox.set_active(1)
4701- self.run_gtk_eventloop()
4702- dialog.hosted_account_name_entry.set_text("Toodleoo")
4703- dialog.check_entry(dialog.hosted_account_name_entry)
4704- self.assertEqual(0, len(dialog._errored_entries))
4705-
4706- def test_check_entry_non_ascii(self):
4707- """
4708- Test that we return L{False} when the text of a L{Gtk.Entry} contains
4709- Unicode input.
4710- """
4711- dialog = ClientSettingsDialog(self.controller)
4712- self.run_gtk_eventloop()
4713- dialog.use_type_combobox.set_active(1)
4714- self.run_gtk_eventloop()
4715- dialog.hosted_account_name_entry.set_text(u"T\xc3dle\xc4")
4716- self.assertFalse(dialog.check_entry(dialog.hosted_account_name_entry))
4717-
4718- def test_check_entry_records_entry_when_non_ascii(self):
4719- """
4720- Test that, when the text of a L{Gtk.Entry} contains Unicode it is
4721- added to L{ClientSettingsDialog._errored_entries}.
4722- """
4723- dialog = ClientSettingsDialog(self.controller)
4724- self.run_gtk_eventloop()
4725- dialog.use_type_combobox.set_active(1)
4726- self.run_gtk_eventloop()
4727- dialog.hosted_account_name_entry.set_text(u"T\xc3dle\xc4")
4728- dialog.check_entry(dialog.hosted_account_name_entry)
4729- self.assertEqual(1, len(dialog._errored_entries))
4730-
4731- def test_dismiss_validation_errors_local(self):
4732- """
4733- Test that dismissing the validation errors tidies up indicators that
4734- have been set against local settings.
4735- """
4736- dialog = ClientSettingsDialog(self.controller)
4737- self.run_gtk_eventloop()
4738- dialog.use_type_combobox.set_active(1)
4739- self.run_gtk_eventloop()
4740- dialog.hosted_account_name_entry.set_text(u"T\xc3dle\xc4")
4741- dialog.hosted_password_entry.set_text(u"T\xc3dle\xc4")
4742- self.run_gtk_eventloop()
4743- dialog.validity_check()
4744- self.run_gtk_eventloop()
4745- self.assertEqual(2, len(dialog._errored_entries))
4746- [entry1, entry2] = dialog._errored_entries
4747- self.assertEqual(Gtk.STOCK_DIALOG_WARNING,
4748- entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
4749- self.assertEqual(Gtk.STOCK_DIALOG_WARNING,
4750- entry2.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
4751- dialog.dismiss_infobar(None)
4752- self.run_gtk_eventloop()
4753- self.assertEqual(0, len(dialog._errored_entries))
4754- self.assertNotEqual(
4755- Gtk.STOCK_DIALOG_WARNING,
4756- entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
4757- self.assertNotEqual(
4758- Gtk.STOCK_DIALOG_WARNING,
4759- entry2.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
4760-
4761- def test_dismiss_validation_errors_hosted(self):
4762- """
4763- Test that dismissing the validation errors tidies up indicators that
4764- have been set against hosted fields.
4765- """
4766- dialog = ClientSettingsDialog(self.controller)
4767- self.run_gtk_eventloop()
4768- dialog.use_type_combobox.set_active(2)
4769- self.run_gtk_eventloop()
4770- dialog.local_landscape_host_entry.set_text("dodgy as hell")
4771- self.run_gtk_eventloop()
4772- dialog.validity_check()
4773- self.run_gtk_eventloop()
4774- self.assertEqual(1, len(dialog._errored_entries))
4775- [entry1] = dialog._errored_entries
4776- self.assertEqual(Gtk.STOCK_DIALOG_WARNING,
4777- entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
4778- dialog.dismiss_infobar(None)
4779- self.run_gtk_eventloop()
4780- self.assertEqual(0, len(dialog._errored_entries))
4781- self.assertNotEqual(
4782- Gtk.STOCK_DIALOG_WARNING,
4783- entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
4784-
4785- def test_validity_check_disabled(self):
4786- """
4787- Test that the L{validity_check} returns True when we disable landscape
4788- client.
4789- """
4790- dialog = ClientSettingsDialog(self.controller)
4791- self.run_gtk_eventloop()
4792- dialog.use_type_combobox.set_active(0)
4793- self.run_gtk_eventloop()
4794- self.assertTrue(dialog.validity_check())
4795-
4796- def test_validity_check_hosted(self):
4797- """
4798- Test that the L{validity_check} returns True when the hosted fields are
4799- valid.
4800- """
4801- dialog = ClientSettingsDialog(self.controller)
4802- self.run_gtk_eventloop()
4803- dialog.use_type_combobox.set_active(1)
4804- dialog.hosted_account_name_entry.set_text("Bob")
4805- dialog.hosted_password_entry.set_text("the builder")
4806- self.run_gtk_eventloop()
4807- self.assertTrue(dialog.validity_check())
4808-
4809- def test_validity_check_hosted_unicode(self):
4810- """
4811- Test that the L{validity_check} returns False when the hosted fields
4812- contain Unicode.
4813- """
4814- dialog = ClientSettingsDialog(self.controller)
4815- self.run_gtk_eventloop()
4816- dialog.use_type_combobox.set_active(1)
4817- dialog.hosted_account_name_entry.set_text(u"B\xc3b")
4818- self.run_gtk_eventloop()
4819- self.assertFalse(dialog.validity_check())
4820-
4821- def test_validity_check_local_ok(self):
4822- """
4823- Test that the L{validity_check} returns True when the local fields
4824- are valid.
4825- """
4826- dialog = ClientSettingsDialog(self.controller)
4827- self.run_gtk_eventloop()
4828- dialog.use_type_combobox.set_active(2)
4829- self.run_gtk_eventloop()
4830- dialog.local_landscape_host_entry.set_text("foo.bar")
4831- self.run_gtk_eventloop()
4832- self.assertTrue(dialog.validity_check())
4833-
4834- def test_validity_check_local_sanitisable(self):
4835- """
4836- Test that the L{validity_check} returns True when the local fields
4837- are valid after sanitation.
4838- """
4839- dialog = ClientSettingsDialog(self.controller)
4840- self.run_gtk_eventloop()
4841- dialog.use_type_combobox.set_active(2)
4842- dialog.local_landscape_host_entry.set_text(" foo.bar")
4843- self.run_gtk_eventloop()
4844- self.assertTrue(dialog.validity_check())
4845- dialog.local_landscape_host_entry.set_text("foo.bar ")
4846- self.run_gtk_eventloop()
4847- self.assertTrue(dialog.validity_check())
4848-
4849- def test_validity_check_local_invalid_host_name(self):
4850- """
4851- Test that the L{validity_check} returns False when the host name is
4852- invalid.
4853- """
4854- dialog = ClientSettingsDialog(self.controller)
4855- self.run_gtk_eventloop()
4856- dialog.use_type_combobox.set_active(2)
4857- dialog.local_landscape_host_entry.set_text("foo bar")
4858- self.run_gtk_eventloop()
4859- self.assertFalse(dialog.validity_check())
4860-
4861- def test_validity_check_local_unicode(self):
4862- """
4863- Test that the L{validity_check} returns False when the host name
4864- contains Unicode.
4865- """
4866- dialog = ClientSettingsDialog(self.controller)
4867- self.run_gtk_eventloop()
4868- dialog.use_type_combobox.set_active(2)
4869- dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
4870- self.run_gtk_eventloop()
4871- self.assertFalse(dialog.validity_check())
4872-
4873- if dbus_test_should_skip:
4874- skip = dbus_skip_message
4875-
4876-
4877-class LocalConfigurationViewTest(LandscapeTest):
4878-
4879- helpers = [ConfigurationProxyHelper]
4880-
4881- def setUp(self):
4882- self.default_data = {"management-type": "LDS",
4883- "computer-title": "",
4884- "hosted-landscape-host": "",
4885- "hosted-account-name": "",
4886- "hosted-password": "",
4887- "local-landscape-host": "",
4888- "local-account-name": "",
4889- "local-password": "manky"}
4890-
4891- self.config_string = (
4892- "[client]\n"
4893- "data_path = %s\n"
4894- "url = https://landscape.localdomain/message-system\n"
4895- "computer_title = baz\n"
4896- "ping_url = http://landscape.localdomain/ping\n" % sys.path[0])
4897-
4898- super(LocalConfigurationViewTest, self).setUp()
4899- landscape.ui.model.configuration.state.DEFAULT_DATA[COMPUTER_TITLE] \
4900- = "me.here.com"
4901- settings = FakeGSettings(data=self.default_data)
4902- self.uisettings = UISettings(settings)
4903- model = ConfigurationModel(proxy=self.proxy,
4904- uisettings=self.uisettings)
4905- self.controller = ConfigController(model)
4906-
4907- def test_init(self):
4908- """
4909- Test that we correctly initialise the L{ConfigurationView} correctly
4910- from the controller.
4911- """
4912- dialog = ClientSettingsDialog(self.controller)
4913- while Gtk.events_pending():
4914- Gtk.main_iteration()
4915- content_area = dialog.get_content_area()
4916- children = content_area.get_children()
4917- self.assertEqual(len(children), 2)
4918- box = children[0]
4919- self.assertIsInstance(box, Gtk.Box)
4920- self.assertEqual(2, dialog.use_type_combobox.get_active())
4921-
4922- def test_load_data_from_config(self):
4923- """
4924- Test that we load data into the appropriate entries from the
4925- configuration file.
4926- """
4927- dialog = ClientSettingsDialog(self.controller)
4928- while Gtk.events_pending():
4929- Gtk.main_iteration()
4930- self.assertEqual(2, dialog.use_type_combobox.get_active())
4931- self.assertEqual("", dialog.hosted_account_name_entry.get_text())
4932- self.assertEqual("", dialog.hosted_password_entry.get_text())
4933- self.assertEqual("landscape.localdomain",
4934- dialog.local_landscape_host_entry.get_text())
4935- self.assertEqual("manky", dialog.local_password_entry.get_text())
4936-
4937- if dbus_test_should_skip:
4938- skip = dbus_skip_message
4939
4940=== removed directory 'landscape/ui/view/ui'
4941=== removed file 'landscape/ui/view/ui/landscape-client-settings.glade'
4942--- landscape/ui/view/ui/landscape-client-settings.glade 2014-10-09 09:46:05 +0000
4943+++ landscape/ui/view/ui/landscape-client-settings.glade 1970-01-01 00:00:00 +0000
4944@@ -1,462 +0,0 @@
4945-<?xml version="1.0" encoding="UTF-8"?>
4946-<!-- Generated with glade 3.18.3 -->
4947-<interface>
4948- <requires lib="gtk+" version="3.0"/>
4949- <object class="GtkDialog" id="dialog1">
4950- <property name="can_focus">False</property>
4951- <property name="border_width">5</property>
4952- <property name="type_hint">dialog</property>
4953- <child internal-child="vbox">
4954- <object class="GtkBox" id="dialog-vbox">
4955- <property name="can_focus">False</property>
4956- <property name="orientation">vertical</property>
4957- <property name="spacing">2</property>
4958- <child internal-child="action_area">
4959- <object class="GtkButtonBox" id="dialog-action_area1">
4960- <property name="can_focus">False</property>
4961- <property name="layout_style">end</property>
4962- <child>
4963- <object class="GtkButton" id="revertbutton">
4964- <property name="label">gtk-revert-to-saved</property>
4965- <property name="use_action_appearance">False</property>
4966- <property name="visible">True</property>
4967- <property name="can_focus">True</property>
4968- <property name="receives_default">True</property>
4969- <property name="use_stock">True</property>
4970- </object>
4971- <packing>
4972- <property name="expand">False</property>
4973- <property name="fill">True</property>
4974- <property name="position">0</property>
4975- </packing>
4976- </child>
4977- <child>
4978- <object class="GtkButton" id="cancel-button">
4979- <property name="label">gtk-cancel</property>
4980- <property name="use_action_appearance">False</property>
4981- <property name="visible">True</property>
4982- <property name="can_focus">True</property>
4983- <property name="receives_default">True</property>
4984- <property name="use_stock">True</property>
4985- </object>
4986- <packing>
4987- <property name="expand">False</property>
4988- <property name="fill">True</property>
4989- <property name="position">1</property>
4990- </packing>
4991- </child>
4992- <child>
4993- <object class="GtkButton" id="ok-button">
4994- <property name="label">gtk-ok</property>
4995- <property name="use_action_appearance">False</property>
4996- <property name="visible">True</property>
4997- <property name="can_focus">True</property>
4998- <property name="receives_default">True</property>
4999- <property name="use_stock">True</property>
5000- </object>
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: