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
=== modified file 'contrib/testing/testcase.py'
--- contrib/testing/testcase.py 2010-09-03 21:14:00 +0000
+++ contrib/testing/testcase.py 2010-09-07 14:11:20 +0000
@@ -90,9 +90,9 @@
90 """Just add the record to self.records."""90 """Just add the record to self.records."""
91 self.records.append(record)91 self.records.append(record)
9292
93 def check(self, level, msg):93 def check(self, level, *msgs):
94 """Check that something is logged."""94 """Verifies that the msgs are logged in the specified level."""
95 for rec in self.records:95 for rec in self.records:
96 if rec.levelno == level and str(msg) in rec.message:96 if rec.levelno == level and all(m in rec.message for m in msgs):
97 return True97 return True
98 return False98 return False
9999
=== modified file 'ubuntu_sso/gui.py'
--- ubuntu_sso/gui.py 2010-09-03 21:14:00 +0000
+++ ubuntu_sso/gui.py 2010-09-07 14:11:20 +0000
@@ -341,19 +341,32 @@
341 for label in self.labels:341 for label in self.labels:
342 label.set_size_request(*size_req)342 label.set_size_request(*size_req)
343343
344 self._signals = [344 self._signals = {
345 ('CaptchaGenerated', self.on_captcha_generated),345 'CaptchaGenerated':
346 ('CaptchaGenerationError', self.on_captcha_generation_error),346 self._filter_by_app_name(self.on_captcha_generated),
347 ('UserRegistered', self.on_user_registered),347 'CaptchaGenerationError':
348 ('UserRegistrationError', self.on_user_registration_error),348 self._filter_by_app_name(self.on_captcha_generation_error),
349 ('EmailValidated', self.on_email_validated),349 'UserRegistered':
350 ('EmailValidationError', self.on_email_validation_error),350 self._filter_by_app_name(self.on_user_registered),
351 ('LoggedIn', self.on_logged_in),351 'UserRegistrationError':
352 ('LoginError', self.on_login_error),352 self._filter_by_app_name(self.on_user_registration_error),
353 ('PasswordResetTokenSent', self.on_password_reset_token_sent),353 'EmailValidated':
354 ('PasswordResetError', self.on_password_reset_error),354 self._filter_by_app_name(self.on_email_validated),
355 ('PasswordChanged', self.on_password_changed),355 'EmailValidationError':
356 ('PasswordChangeError', self.on_password_change_error)]356 self._filter_by_app_name(self.on_email_validation_error),
357 'LoggedIn':
358 self._filter_by_app_name(self.on_logged_in),
359 'LoginError':
360 self._filter_by_app_name(self.on_login_error),
361 'PasswordResetTokenSent':
362 self._filter_by_app_name(self.on_password_reset_token_sent),
363 'PasswordResetError':
364 self._filter_by_app_name(self.on_password_reset_error),
365 'PasswordChanged':
366 self._filter_by_app_name(self.on_password_changed),
367 'PasswordChangeError':
368 self._filter_by_app_name(self.on_password_change_error),
369 }
357 self._setup_signals()370 self._setup_signals()
358 self._gtk_signal_log = []371 self._gtk_signal_log = []
359372
@@ -377,10 +390,27 @@
377390
378 self.window.show()391 self.window.show()
379392
393 def _filter_by_app_name(self, f):
394 """Excecute the decorated function only for 'self.app_name'."""
395
396 @wraps(f)
397 def inner(app_name, *args, **kwargs):
398 """Execute 'f' only if 'app_name' matches 'self.app_name'."""
399 result = None
400 if app_name == self.app_name:
401 result = f(app_name, *args, **kwargs)
402 else:
403 logger.info('%s: ignoring call since received app_name '\
404 '"%s" (expected "%s")',
405 f.__name__, app_name, self.app_name)
406 return result
407
408 return inner
409
380 def _setup_signals(self):410 def _setup_signals(self):
381 """Bind signals to callbacks to be able to test the pages."""411 """Bind signals to callbacks to be able to test the pages."""
382 iface = self.iface_name412 iface = self.iface_name
383 for signal, method in self._signals:413 for signal, method in self._signals.iteritems():
384 actual = self._signals_receivers.get((iface, signal))414 actual = self._signals_receivers.get((iface, signal))
385 if actual is not None:415 if actual is not None:
386 msg = 'Signal %r is already connected with %r at iface %r.'416 msg = 'Signal %r is already connected with %r at iface %r.'
387417
=== modified file 'ubuntu_sso/tests/test_gui.py'
--- ubuntu_sso/tests/test_gui.py 2010-09-03 21:24:47 +0000
+++ ubuntu_sso/tests/test_gui.py 2010-09-07 14:11:20 +0000
@@ -1780,26 +1780,118 @@
17801780
1781 def test_all_the_signals_are_listed(self):1781 def test_all_the_signals_are_listed(self):
1782 """All the backend signals are listed to be binded."""1782 """All the backend signals are listed to be binded."""
1783 names = [sig for (sig, _) in self.ui._signals]
1784 for sig in ('CaptchaGenerated', 'CaptchaGenerationError',1783 for sig in ('CaptchaGenerated', 'CaptchaGenerationError',
1785 'UserRegistered', 'UserRegistrationError',1784 'UserRegistered', 'UserRegistrationError',
1786 'LoggedIn', 'LoginError',1785 'LoggedIn', 'LoginError',
1787 'EmailValidated', 'EmailValidationError',1786 'EmailValidated', 'EmailValidationError',
1788 'PasswordResetTokenSent', 'PasswordResetError',1787 'PasswordResetTokenSent', 'PasswordResetError',
1789 'PasswordChanged', 'PasswordChangeError'):1788 'PasswordChanged', 'PasswordChangeError'):
1790 self.assertIn(sig, names)1789 self.assertIn(sig, self.ui._signals)
17911790
1792 def test_signal_receivers_are_connected(self):1791 def test_signal_receivers_are_connected(self):
1793 """Callbacks are connected to signals of interest."""1792 """Callbacks are connected to signals of interest."""
1794 msg1 = 'callback %r for signal %r must be added to the internal bus.'1793 msg1 = 'callback %r for signal %r must be added to the internal bus.'
1795 msg2 = 'callback %r for signal %r must be added to the ui log.'1794 msg2 = 'callback %r for signal %r must be added to the ui log.'
1796 dbus_iface = self.ui.iface_name1795 dbus_iface = self.ui.iface_name
1797 for signal, method in self.ui._signals:1796 for signal, method in self.ui._signals.iteritems():
1798 actual = self.ui.bus.callbacks.get((dbus_iface, signal))1797 actual = self.ui.bus.callbacks.get((dbus_iface, signal))
1799 self.assertEqual(method, actual, msg1 % (method, signal))1798 self.assertEqual(method, actual, msg1 % (method, signal))
1800 actual = self.ui._signals_receivers.get((dbus_iface, signal))1799 actual = self.ui._signals_receivers.get((dbus_iface, signal))
1801 self.assertEqual(method, actual, msg2 % (method, signal))1800 self.assertEqual(method, actual, msg2 % (method, signal))
18021801
1802 def test_callbacks_only_log_when_app_name_doesnt_match(self):
1803 """Callbacks do nothing but logging when app_name doesn't match."""
1804 mismatch_app_name = self.ui.app_name * 2
1805 for method in self.ui._signals.itervalues():
1806 msgs = ('ignoring', method.__name__, mismatch_app_name)
1807 method(mismatch_app_name, 'dummy')
1808 self.assertTrue(self.memento.check(logging.INFO, *msgs))
1809 self.memento.records = []
1810
1811 def test_on_captcha_generated_is_not_called(self):
1812 """on_captcha_generated is not called if incorrect app_name."""
1813 self.patch(self.ui, 'on_captcha_generated', self._set_called)
1814 mismatch_app_name = self.ui.app_name * 2
1815 self.ui._signals['CaptchaGenerated'](mismatch_app_name, 'dummy')
1816 self.assertFalse(self._called)
1817
1818 def test_on_captcha_generation_error_is_not_called(self):
1819 """on_captcha_generation_error is not called if incorrect app_name."""
1820 self.patch(self.ui, 'on_captcha_generation_error', self._set_called)
1821 mismatch_app_name = self.ui.app_name * 2
1822 self.ui._signals['CaptchaGenerationError'](mismatch_app_name, 'dummy')
1823 self.assertFalse(self._called)
1824
1825 def test_on_user_registered_is_not_called(self):
1826 """on_user_registered is not called if incorrect app_name."""
1827 self.patch(self.ui, 'on_user_registered', self._set_called)
1828 mismatch_app_name = self.ui.app_name * 2
1829 self.ui._signals['UserRegistered'](mismatch_app_name, 'dummy')
1830 self.assertFalse(self._called)
1831
1832 def test_on_user_registration_error_is_not_called(self):
1833 """on_user_registration_error is not called if incorrect app_name."""
1834 self.patch(self.ui, 'on_user_registration_error', self._set_called)
1835 mismatch_app_name = self.ui.app_name * 2
1836 self.ui._signals['UserRegistrationError'](mismatch_app_name, 'dummy')
1837 self.assertFalse(self._called)
1838
1839 def test_on_email_validated_is_not_called(self):
1840 """on_email_validated is not called if incorrect app_name."""
1841 self.patch(self.ui, 'on_email_validated', self._set_called)
1842 mismatch_app_name = self.ui.app_name * 2
1843 self.ui._signals['EmailValidated'](mismatch_app_name, 'dummy')
1844 self.assertFalse(self._called)
1845
1846 def test_on_email_validation_error_is_not_called(self):
1847 """on_email_validation_error is not called if incorrect app_name."""
1848 self.patch(self.ui, 'on_email_validation_error', self._set_called)
1849 mismatch_app_name = self.ui.app_name * 2
1850 self.ui._signals['EmailValidationError'](mismatch_app_name, 'dummy')
1851 self.assertFalse(self._called)
1852
1853 def test_on_logged_in_is_not_called(self):
1854 """on_logged_in is not called if incorrect app_name."""
1855 self.patch(self.ui, 'on_logged_in', self._set_called)
1856 mismatch_app_name = self.ui.app_name * 2
1857 self.ui._signals['LoggedIn'](mismatch_app_name, 'dummy')
1858 self.assertFalse(self._called)
1859
1860 def test_on_login_error_is_not_called(self):
1861 """on_login_error is not called if incorrect app_name."""
1862 self.patch(self.ui, 'on_login_error', self._set_called)
1863 mismatch_app_name = self.ui.app_name * 2
1864 self.ui._signals['LoginError'](mismatch_app_name, 'dummy')
1865 self.assertFalse(self._called)
1866
1867 def test_on_password_reset_token_sent_is_not_called(self):
1868 """on_password_reset_token_sent is not called if incorrect app_name."""
1869 self.patch(self.ui, 'on_password_reset_token_sent', self._set_called)
1870 mismatch_app_name = self.ui.app_name * 2
1871 self.ui._signals['PasswordResetTokenSent'](mismatch_app_name, 'dummy')
1872 self.assertFalse(self._called)
1873
1874 def test_on_password_reset_error_is_not_called(self):
1875 """on_password_reset_error is not called if incorrect app_name."""
1876 self.patch(self.ui, 'on_password_reset_error', self._set_called)
1877 mismatch_app_name = self.ui.app_name * 2
1878 self.ui._signals['PasswordResetError'](mismatch_app_name, 'dummy')
1879 self.assertFalse(self._called)
1880
1881 def test_on_password_changed_is_not_called(self):
1882 """on_password_changed is not called if incorrect app_name."""
1883 self.patch(self.ui, 'on_password_changed', self._set_called)
1884 mismatch_app_name = self.ui.app_name * 2
1885 self.ui._signals['PasswordChanged'](mismatch_app_name, 'dummy')
1886 self.assertFalse(self._called)
1887
1888 def test_on_password_change_error_is_not_called(self):
1889 """on_password_change_error is not called if incorrect app_name."""
1890 self.patch(self.ui, 'on_password_change_error', self._set_called)
1891 mismatch_app_name = self.ui.app_name * 2
1892 self.ui._signals['PasswordChangeError'](mismatch_app_name, 'dummy')
1893 self.assertFalse(self._called)
1894
18031895
1804class LoginOnlyTestCase(UbuntuSSOClientTestCase):1896class LoginOnlyTestCase(UbuntuSSOClientTestCase):
1805 """Test suite for the login only GUI."""1897 """Test suite for the login only GUI."""
18061898
=== modified file 'ubuntu_sso/tests/test_main.py'
--- ubuntu_sso/tests/test_main.py 2010-09-07 12:15:46 +0000
+++ ubuntu_sso/tests/test_main.py 2010-09-07 14:11:20 +0000
@@ -1181,7 +1181,7 @@
11811181
1182 self.assertTrue(1, len(self.memento.records))1182 self.assertTrue(1, len(self.memento.records))
1183 self.assertTrue(self.memento.check(logging.ERROR,1183 self.assertTrue(self.memento.check(logging.ERROR,
1184 LOGIN_OR_REGISTER_GUI_ARGS))1184 str(LOGIN_OR_REGISTER_GUI_ARGS)))
1185 exc_info = self.memento.records[0].exc_info1185 exc_info = self.memento.records[0].exc_info
1186 self.assertIn(self.args, exc_info)1186 self.assertIn(self.args, exc_info)
11871187
@@ -1244,7 +1244,7 @@
12441244
1245 self.assertTrue(1, len(self.memento.records))1245 self.assertTrue(1, len(self.memento.records))
1246 self.assertTrue(self.memento.check(logging.ERROR,1246 self.assertTrue(self.memento.check(logging.ERROR,
1247 LOGIN_ONLY_GUI_ARGS))1247 str(LOGIN_ONLY_GUI_ARGS)))
1248 exc_info = self.memento.records[0].exc_info1248 exc_info = self.memento.records[0].exc_info
1249 self.assertIn(self.args, exc_info)1249 self.assertIn(self.args, exc_info)
12501250

Subscribers

People subscribed via source and target branches