Merge lp:~nataliabidart/ubuntu-sso-client/filter-by-app-name into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: John Lenton
Approved revision: 615
Merged at revision: 616
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/filter-by-app-name
Merge into: lp:ubuntu-sso-client
Diff against target: 242 lines (+144/-22)
4 files modified
contrib/testing/testcase.py (+3/-3)
ubuntu_sso/gui.py (+44/-14)
ubuntu_sso/tests/test_gui.py (+95/-3)
ubuntu_sso/tests/test_main.py (+2/-2)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/filter-by-app-name
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Rodrigo Moya (community) Approve
Review via email: mp+34752@code.launchpad.net

Commit message

* Signals from the DBus "UserManagement" service are now filtered by app name (LP: #629025).

Description of the change

Before this branch, the GUI processed every signal emitted by the "UserManagement" DBus service.

To test this, you should open more than one GUI (for different app_names) and proceed to do different things in each one. Each GUI instance should behave properly (ie events from one should not interfere in the other).

To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) :
review: Approve
Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/testing/testcase.py'
2--- contrib/testing/testcase.py 2010-09-03 21:14:00 +0000
3+++ contrib/testing/testcase.py 2010-09-07 14:11:20 +0000
4@@ -90,9 +90,9 @@
5 """Just add the record to self.records."""
6 self.records.append(record)
7
8- def check(self, level, msg):
9- """Check that something is logged."""
10+ def check(self, level, *msgs):
11+ """Verifies that the msgs are logged in the specified level."""
12 for rec in self.records:
13- if rec.levelno == level and str(msg) in rec.message:
14+ if rec.levelno == level and all(m in rec.message for m in msgs):
15 return True
16 return False
17
18=== modified file 'ubuntu_sso/gui.py'
19--- ubuntu_sso/gui.py 2010-09-03 21:14:00 +0000
20+++ ubuntu_sso/gui.py 2010-09-07 14:11:20 +0000
21@@ -341,19 +341,32 @@
22 for label in self.labels:
23 label.set_size_request(*size_req)
24
25- self._signals = [
26- ('CaptchaGenerated', self.on_captcha_generated),
27- ('CaptchaGenerationError', self.on_captcha_generation_error),
28- ('UserRegistered', self.on_user_registered),
29- ('UserRegistrationError', self.on_user_registration_error),
30- ('EmailValidated', self.on_email_validated),
31- ('EmailValidationError', self.on_email_validation_error),
32- ('LoggedIn', self.on_logged_in),
33- ('LoginError', self.on_login_error),
34- ('PasswordResetTokenSent', self.on_password_reset_token_sent),
35- ('PasswordResetError', self.on_password_reset_error),
36- ('PasswordChanged', self.on_password_changed),
37- ('PasswordChangeError', self.on_password_change_error)]
38+ self._signals = {
39+ 'CaptchaGenerated':
40+ self._filter_by_app_name(self.on_captcha_generated),
41+ 'CaptchaGenerationError':
42+ self._filter_by_app_name(self.on_captcha_generation_error),
43+ 'UserRegistered':
44+ self._filter_by_app_name(self.on_user_registered),
45+ 'UserRegistrationError':
46+ self._filter_by_app_name(self.on_user_registration_error),
47+ 'EmailValidated':
48+ self._filter_by_app_name(self.on_email_validated),
49+ 'EmailValidationError':
50+ self._filter_by_app_name(self.on_email_validation_error),
51+ 'LoggedIn':
52+ self._filter_by_app_name(self.on_logged_in),
53+ 'LoginError':
54+ self._filter_by_app_name(self.on_login_error),
55+ 'PasswordResetTokenSent':
56+ self._filter_by_app_name(self.on_password_reset_token_sent),
57+ 'PasswordResetError':
58+ self._filter_by_app_name(self.on_password_reset_error),
59+ 'PasswordChanged':
60+ self._filter_by_app_name(self.on_password_changed),
61+ 'PasswordChangeError':
62+ self._filter_by_app_name(self.on_password_change_error),
63+ }
64 self._setup_signals()
65 self._gtk_signal_log = []
66
67@@ -377,10 +390,27 @@
68
69 self.window.show()
70
71+ def _filter_by_app_name(self, f):
72+ """Excecute the decorated function only for 'self.app_name'."""
73+
74+ @wraps(f)
75+ def inner(app_name, *args, **kwargs):
76+ """Execute 'f' only if 'app_name' matches 'self.app_name'."""
77+ result = None
78+ if app_name == self.app_name:
79+ result = f(app_name, *args, **kwargs)
80+ else:
81+ logger.info('%s: ignoring call since received app_name '\
82+ '"%s" (expected "%s")',
83+ f.__name__, app_name, self.app_name)
84+ return result
85+
86+ return inner
87+
88 def _setup_signals(self):
89 """Bind signals to callbacks to be able to test the pages."""
90 iface = self.iface_name
91- for signal, method in self._signals:
92+ for signal, method in self._signals.iteritems():
93 actual = self._signals_receivers.get((iface, signal))
94 if actual is not None:
95 msg = 'Signal %r is already connected with %r at iface %r.'
96
97=== modified file 'ubuntu_sso/tests/test_gui.py'
98--- ubuntu_sso/tests/test_gui.py 2010-09-03 21:24:47 +0000
99+++ ubuntu_sso/tests/test_gui.py 2010-09-07 14:11:20 +0000
100@@ -1780,26 +1780,118 @@
101
102 def test_all_the_signals_are_listed(self):
103 """All the backend signals are listed to be binded."""
104- names = [sig for (sig, _) in self.ui._signals]
105 for sig in ('CaptchaGenerated', 'CaptchaGenerationError',
106 'UserRegistered', 'UserRegistrationError',
107 'LoggedIn', 'LoginError',
108 'EmailValidated', 'EmailValidationError',
109 'PasswordResetTokenSent', 'PasswordResetError',
110 'PasswordChanged', 'PasswordChangeError'):
111- self.assertIn(sig, names)
112+ self.assertIn(sig, self.ui._signals)
113
114 def test_signal_receivers_are_connected(self):
115 """Callbacks are connected to signals of interest."""
116 msg1 = 'callback %r for signal %r must be added to the internal bus.'
117 msg2 = 'callback %r for signal %r must be added to the ui log.'
118 dbus_iface = self.ui.iface_name
119- for signal, method in self.ui._signals:
120+ for signal, method in self.ui._signals.iteritems():
121 actual = self.ui.bus.callbacks.get((dbus_iface, signal))
122 self.assertEqual(method, actual, msg1 % (method, signal))
123 actual = self.ui._signals_receivers.get((dbus_iface, signal))
124 self.assertEqual(method, actual, msg2 % (method, signal))
125
126+ def test_callbacks_only_log_when_app_name_doesnt_match(self):
127+ """Callbacks do nothing but logging when app_name doesn't match."""
128+ mismatch_app_name = self.ui.app_name * 2
129+ for method in self.ui._signals.itervalues():
130+ msgs = ('ignoring', method.__name__, mismatch_app_name)
131+ method(mismatch_app_name, 'dummy')
132+ self.assertTrue(self.memento.check(logging.INFO, *msgs))
133+ self.memento.records = []
134+
135+ def test_on_captcha_generated_is_not_called(self):
136+ """on_captcha_generated is not called if incorrect app_name."""
137+ self.patch(self.ui, 'on_captcha_generated', self._set_called)
138+ mismatch_app_name = self.ui.app_name * 2
139+ self.ui._signals['CaptchaGenerated'](mismatch_app_name, 'dummy')
140+ self.assertFalse(self._called)
141+
142+ def test_on_captcha_generation_error_is_not_called(self):
143+ """on_captcha_generation_error is not called if incorrect app_name."""
144+ self.patch(self.ui, 'on_captcha_generation_error', self._set_called)
145+ mismatch_app_name = self.ui.app_name * 2
146+ self.ui._signals['CaptchaGenerationError'](mismatch_app_name, 'dummy')
147+ self.assertFalse(self._called)
148+
149+ def test_on_user_registered_is_not_called(self):
150+ """on_user_registered is not called if incorrect app_name."""
151+ self.patch(self.ui, 'on_user_registered', self._set_called)
152+ mismatch_app_name = self.ui.app_name * 2
153+ self.ui._signals['UserRegistered'](mismatch_app_name, 'dummy')
154+ self.assertFalse(self._called)
155+
156+ def test_on_user_registration_error_is_not_called(self):
157+ """on_user_registration_error is not called if incorrect app_name."""
158+ self.patch(self.ui, 'on_user_registration_error', self._set_called)
159+ mismatch_app_name = self.ui.app_name * 2
160+ self.ui._signals['UserRegistrationError'](mismatch_app_name, 'dummy')
161+ self.assertFalse(self._called)
162+
163+ def test_on_email_validated_is_not_called(self):
164+ """on_email_validated is not called if incorrect app_name."""
165+ self.patch(self.ui, 'on_email_validated', self._set_called)
166+ mismatch_app_name = self.ui.app_name * 2
167+ self.ui._signals['EmailValidated'](mismatch_app_name, 'dummy')
168+ self.assertFalse(self._called)
169+
170+ def test_on_email_validation_error_is_not_called(self):
171+ """on_email_validation_error is not called if incorrect app_name."""
172+ self.patch(self.ui, 'on_email_validation_error', self._set_called)
173+ mismatch_app_name = self.ui.app_name * 2
174+ self.ui._signals['EmailValidationError'](mismatch_app_name, 'dummy')
175+ self.assertFalse(self._called)
176+
177+ def test_on_logged_in_is_not_called(self):
178+ """on_logged_in is not called if incorrect app_name."""
179+ self.patch(self.ui, 'on_logged_in', self._set_called)
180+ mismatch_app_name = self.ui.app_name * 2
181+ self.ui._signals['LoggedIn'](mismatch_app_name, 'dummy')
182+ self.assertFalse(self._called)
183+
184+ def test_on_login_error_is_not_called(self):
185+ """on_login_error is not called if incorrect app_name."""
186+ self.patch(self.ui, 'on_login_error', self._set_called)
187+ mismatch_app_name = self.ui.app_name * 2
188+ self.ui._signals['LoginError'](mismatch_app_name, 'dummy')
189+ self.assertFalse(self._called)
190+
191+ def test_on_password_reset_token_sent_is_not_called(self):
192+ """on_password_reset_token_sent is not called if incorrect app_name."""
193+ self.patch(self.ui, 'on_password_reset_token_sent', self._set_called)
194+ mismatch_app_name = self.ui.app_name * 2
195+ self.ui._signals['PasswordResetTokenSent'](mismatch_app_name, 'dummy')
196+ self.assertFalse(self._called)
197+
198+ def test_on_password_reset_error_is_not_called(self):
199+ """on_password_reset_error is not called if incorrect app_name."""
200+ self.patch(self.ui, 'on_password_reset_error', self._set_called)
201+ mismatch_app_name = self.ui.app_name * 2
202+ self.ui._signals['PasswordResetError'](mismatch_app_name, 'dummy')
203+ self.assertFalse(self._called)
204+
205+ def test_on_password_changed_is_not_called(self):
206+ """on_password_changed is not called if incorrect app_name."""
207+ self.patch(self.ui, 'on_password_changed', self._set_called)
208+ mismatch_app_name = self.ui.app_name * 2
209+ self.ui._signals['PasswordChanged'](mismatch_app_name, 'dummy')
210+ self.assertFalse(self._called)
211+
212+ def test_on_password_change_error_is_not_called(self):
213+ """on_password_change_error is not called if incorrect app_name."""
214+ self.patch(self.ui, 'on_password_change_error', self._set_called)
215+ mismatch_app_name = self.ui.app_name * 2
216+ self.ui._signals['PasswordChangeError'](mismatch_app_name, 'dummy')
217+ self.assertFalse(self._called)
218+
219
220 class LoginOnlyTestCase(UbuntuSSOClientTestCase):
221 """Test suite for the login only GUI."""
222
223=== modified file 'ubuntu_sso/tests/test_main.py'
224--- ubuntu_sso/tests/test_main.py 2010-09-07 12:15:46 +0000
225+++ ubuntu_sso/tests/test_main.py 2010-09-07 14:11:20 +0000
226@@ -1181,7 +1181,7 @@
227
228 self.assertTrue(1, len(self.memento.records))
229 self.assertTrue(self.memento.check(logging.ERROR,
230- LOGIN_OR_REGISTER_GUI_ARGS))
231+ str(LOGIN_OR_REGISTER_GUI_ARGS)))
232 exc_info = self.memento.records[0].exc_info
233 self.assertIn(self.args, exc_info)
234
235@@ -1244,7 +1244,7 @@
236
237 self.assertTrue(1, len(self.memento.records))
238 self.assertTrue(self.memento.check(logging.ERROR,
239- LOGIN_ONLY_GUI_ARGS))
240+ str(LOGIN_ONLY_GUI_ARGS)))
241 exc_info = self.memento.records[0].exc_info
242 self.assertIn(self.args, exc_info)
243

Subscribers

People subscribed via source and target branches