~dobey/ubuntu/oneiric/ubuntu-sso-client/release-133

« back to all changes in this revision

Viewing changes to ubuntu_sso/tests/test_gui.py

  • Committer: Ken VanDine
  • Date: 2010-09-09 15:03:00 UTC
  • mfrom: (11.1.3 ubuntu-sso-client-0.99.6)
  • Revision ID: ken.vandine@canonical.com-20100909150300-z0lnnumytp0493tf
Tags: 0.99.6-0ubuntu1
releasing version 0.99.6-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from ubuntu_sso import gui
34
34
 
35
35
 
 
36
# Access to a protected member 'yyy' of a client class
 
37
# pylint: disable=W0212
 
38
# Instance of 'UbuntuSSOClientGUI' has no 'yyy' member
 
39
# pylint: disable=E1101,E1103
 
40
 
 
41
 
36
42
APP_NAME = 'The Super testing app!'
37
43
TC_URI = 'http://localhost'
38
44
HELP_TEXT = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sed
153
159
        direction = 'in' if focus_in else 'out'
154
160
        self.entry.emit('focus-%s-event' % direction, None)
155
161
 
 
162
    # Bad first argument 'LabeledEntry' given to super class
 
163
    # pylint: disable=E1003
156
164
    def assert_correct_label(self):
157
165
        """Check that the entry has the correct label."""
158
166
        # text content is correct
343
351
                      'tc_browser', 'login', 'request_password_token',
344
352
                      'set_new_password')
345
353
        self.ui = self.gui_class(**self.kwargs)
346
 
        self.ERROR = {'message': self.ui.UNKNOWN_ERROR}
 
354
        self.error = {'message': self.ui.UNKNOWN_ERROR}
347
355
 
348
356
    def tearDown(self):
349
357
        """Clean up."""
505
513
 
506
514
    def test_dbus_signals_are_removed(self):
507
515
        """The hooked signals are removed at shutdown time."""
508
 
        self.ui.bus.add_signal_receiver(gui.NO_OP, 'com.iface', 'signal_test')
 
516
        self.ui._setup_signals()
509
517
        assert len(self.ui.bus.callbacks) > 0  # at least one callback
510
518
 
511
519
        self.ui.on_close_clicked()
552
560
            self.assertEqual(expected, actual, msg % (label, expected, actual))
553
561
 
554
562
    def test_password_fields_are_password(self):
 
563
        """Password fields have the is_password flag set."""
555
564
        msg = '"%s" should be a password LabeledEntry instance.'
556
565
        passwords = filter(lambda name: 'password' in name,
557
566
                           self.ui.entries)
591
600
        """Main window has the proper icon."""
592
601
        self.assertEqual('ubuntu-logo', self.ui.window.get_icon_name())
593
602
 
594
 
    def test_transient_window_is_None_if_window_id_is_zero(self):
 
603
    def test_transient_window_is_none_if_window_id_is_zero(self):
595
604
        """The transient window is correct."""
596
605
        self.patch(gtk.gdk, 'window_foreign_new', self._set_called)
597
606
        self.gui_class(window_id=0, **self.kwargs)
837
846
 
838
847
    def test_join_ok_button_does_nothing_if_clicked_but_disabled(self):
839
848
        """The join form can only be submitted if the button is sensitive."""
840
 
        self.patch(self.ui.name_entry, 'get_text', self._set_called)
 
849
        self.patch(self.ui.email1_entry, 'get_text', self._set_called)
841
850
 
842
851
        self.ui.join_ok_button.set_sensitive(False)
843
852
        self.ui.join_ok_button.clicked()
876
885
        self.assertIsInstance(browser, webkit.WebView)
877
886
        self.assertTrue(browser.get_property('visible'))
878
887
 
 
888
        settings = browser.get_settings()
 
889
        self.assertFalse(settings.get_property('enable-plugins'))
 
890
        self.assertFalse(settings.get_property('enable-default-context-menu'))
 
891
 
879
892
        self.ui.tc_browser_vbox.hide()
880
893
 
881
894
    def test_tc_browser_is_destroyed_when_tc_page_is_hid(self):
913
926
        """Terms & Conditions browser shows the proper uri."""
914
927
        self.ui.tc_button.clicked()
915
928
        self.assertEqual(self.ui.tc_browser.get_property('uri'), TC_URI)
 
929
 
 
930
    # Unused variable 'skip'
 
931
    # pylint: disable=W0612
916
932
    test_tc_browser_opens_the_proper_uri.skip = 'The freaking test wont work.'
917
933
 
918
934
 
926
942
 
927
943
    def test_previous_page_is_shown(self):
928
944
        """On UserRegistrationError the previous page is shown."""
929
 
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.ERROR)
 
945
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.error)
930
946
        self.assert_pages_visibility(enter_details=True)
931
947
 
932
948
    def test_warning_label_is_shown(self):
933
949
        """On UserRegistrationError the warning label is shown."""
934
 
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.ERROR)
 
950
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.error)
935
951
        self.assert_correct_label_warning(self.ui.warning_label,
936
952
                                          self.ui.UNKNOWN_ERROR)
937
953
 
1013
1029
 
1014
1030
    def test_on_email_validation_error_verify_email_is_shown(self):
1015
1031
        """On email validation error, the verify_email page is shown."""
1016
 
        self.ui.on_email_validation_error(app_name=APP_NAME, error=self.ERROR)
 
1032
        self.ui.on_email_validation_error(app_name=APP_NAME, error=self.error)
1017
1033
        self.assert_pages_visibility(verify_email=True)
1018
1034
        self.assert_correct_label_warning(self.ui.warning_label,
1019
1035
                                          self.ui.UNKNOWN_ERROR)
1116
1132
                                          self.ui.FIELD_REQUIRED)
1117
1133
        self.assertNotIn('register_user', self.ui.backend._called)
1118
1134
 
 
1135
    # Unused variable 'skip'
 
1136
    # pylint: disable=W0612
 
1137
    test_warning_is_shown_if_name_empty.skip = \
 
1138
        'Unused for now, will be hidden to save space (LP: #627440).'
 
1139
 
1119
1140
    def test_warning_is_shown_if_empty_email(self):
1120
1141
        """A warning message is shown if emails are empty."""
1121
1142
        self.ui.email1_entry.set_text('')
1179
1200
    def test_warning_is_shown_if_password_too_weak(self):
1180
1201
        """A warning message is shown if password is too weak."""
1181
1202
        # password will match but will be too weak
1182
 
        for w in ('', 'h3lloWo', PASSWORD.lower(), 'helloWorld'):
1183
 
            self.ui.password1_entry.set_text(w)
1184
 
            self.ui.password2_entry.set_text(w)
 
1203
        for pwd in ('', 'h3lloWo', PASSWORD.lower(), 'helloWorld'):
 
1204
            self.ui.password1_entry.set_text(pwd)
 
1205
            self.ui.password2_entry.set_text(pwd)
1185
1206
 
1186
1207
            self.ui.join_ok_button.clicked()
1187
1208
 
1304
1325
    def test_on_login_error_morphs_to_login_page(self):
1305
1326
        """On user login error, the previous page is shown."""
1306
1327
        self.click_connect_with_valid_data()
1307
 
        self.ui.on_login_error(app_name=APP_NAME, error=self.ERROR)
 
1328
        self.ui.on_login_error(app_name=APP_NAME, error=self.error)
1308
1329
        self.assert_pages_visibility(login=True)
1309
1330
 
1310
1331
    def test_on_login_error_a_warning_is_shown(self):
1311
1332
        """On user login error, a warning is shown with proper wording."""
1312
1333
        self.click_connect_with_valid_data()
1313
 
        self.ui.on_login_error(app_name=APP_NAME, error=self.ERROR)
 
1334
        self.ui.on_login_error(app_name=APP_NAME, error=self.error)
1314
1335
        self.assert_correct_label_warning(self.ui.warning_label,
1315
1336
                                          self.ui.UNKNOWN_ERROR)
1316
1337
 
1328
1349
    def test_back_to_registration_hides_warning(self):
1329
1350
        """After user login error, warning is hidden when clicking 'Back'."""
1330
1351
        self.click_connect_with_valid_data()
1331
 
        self.ui.on_login_error(app_name=APP_NAME, error=self.ERROR)
 
1352
        self.ui.on_login_error(app_name=APP_NAME, error=self.error)
1332
1353
        self.ui.login_back_button.clicked()
1333
1354
        self.assertFalse(self.ui.warning_label.get_property('visible'))
1334
1355
 
1504
1525
 
1505
1526
    def test_on_password_reset_error_shows_login_page(self):
1506
1527
        """When reset token wasn't successfuly sent the login page is shown."""
1507
 
        self.ui.on_password_reset_error(app_name=APP_NAME, error=self.ERROR)
 
1528
        self.ui.on_password_reset_error(app_name=APP_NAME, error=self.error)
1508
1529
        self.assert_correct_label_warning(self.ui.warning_label,
1509
1530
                                          self.ui.UNKNOWN_ERROR)
1510
1531
        self.assert_pages_visibility(login=True)
1603
1624
        entries = (self.ui.reset_code_entry,
1604
1625
                   self.ui.reset_password1_entry,
1605
1626
                   self.ui.reset_password2_entry)
1606
 
        for xs in itertools.product(('', ' ', 'a'), repeat=3):
 
1627
        for values in itertools.product(('', ' ', 'a'), repeat=3):
1607
1628
            expected = True
1608
 
            for entry, x in zip(entries, xs):
1609
 
                entry.set_text(x)
1610
 
                expected &= bool(x and not x.isspace())
 
1629
            for entry, val in zip(entries, values):
 
1630
                entry.set_text(val)
 
1631
                expected &= bool(val and not val.isspace())
1611
1632
 
1612
1633
            actual = self.ui.set_new_password_ok_button.get_sensitive()
1613
 
            self.assertEqual(expected, actual, msg % (expected, xs))
 
1634
            self.assertEqual(expected, actual, msg % (expected, values))
1614
1635
 
1615
1636
    def test_on_set_new_password_ok_button_clicked_morphs_window(self):
1616
1637
        """Clicking set_new_password_ok_button the processing page is shown."""
1636
1657
 
1637
1658
    def test_on_password_change_error_shows_login_page(self):
1638
1659
        """When password wasn't changed the reset password page is shown."""
1639
 
        self.ui.on_password_change_error(app_name=APP_NAME, error=self.ERROR)
 
1660
        self.ui.on_password_change_error(app_name=APP_NAME, error=self.error)
1640
1661
        self.assert_correct_label_warning(self.ui.warning_label,
1641
1662
                                          self.ui.UNKNOWN_ERROR)
1642
1663
        self.assert_pages_visibility(request_password_token=True)
1723
1744
    def test_warning_is_shown_if_password_too_weak(self):
1724
1745
        """A warning message is shown if password is too weak."""
1725
1746
        # password will match but will be too weak
1726
 
        for w in ('', 'h3lloWo', PASSWORD.lower(), 'helloWorld'):
1727
 
            self.ui.reset_password1_entry.set_text(w)
1728
 
            self.ui.reset_password2_entry.set_text(w)
 
1747
        for pwd in ('', 'h3lloWo', PASSWORD.lower(), 'helloWorld'):
 
1748
            self.ui.reset_password1_entry.set_text(pwd)
 
1749
            self.ui.reset_password2_entry.set_text(pwd)
1729
1750
 
1730
1751
            self.ui.set_new_password_ok_button.set_sensitive(True)
1731
1752
            self.ui.set_new_password_ok_button.clicked()
1759
1780
 
1760
1781
    def test_all_the_signals_are_listed(self):
1761
1782
        """All the backend signals are listed to be binded."""
1762
 
        names = [sig for (sig, cb) in self.ui._signals]
1763
1783
        for sig in ('CaptchaGenerated', 'CaptchaGenerationError',
1764
1784
                    'UserRegistered', 'UserRegistrationError',
1765
1785
                    'LoggedIn', 'LoginError',
1766
1786
                    'EmailValidated', 'EmailValidationError',
1767
1787
                    'PasswordResetTokenSent', 'PasswordResetError',
1768
1788
                    'PasswordChanged', 'PasswordChangeError'):
1769
 
            self.assertIn(sig, names)
 
1789
            self.assertIn(sig, self.ui._signals)
1770
1790
 
1771
1791
    def test_signal_receivers_are_connected(self):
1772
1792
        """Callbacks are connected to signals of interest."""
1773
1793
        msg1 = 'callback %r for signal %r must be added to the internal bus.'
1774
1794
        msg2 = 'callback %r for signal %r must be added to the ui log.'
1775
1795
        dbus_iface = self.ui.iface_name
1776
 
        for signal, method in self.ui._signals:
 
1796
        for signal, method in self.ui._signals.iteritems():
1777
1797
            actual = self.ui.bus.callbacks.get((dbus_iface, signal))
1778
1798
            self.assertEqual(method, actual, msg1 % (method, signal))
1779
1799
            actual = self.ui._signals_receivers.get((dbus_iface, signal))
1780
1800
            self.assertEqual(method, actual, msg2 % (method, signal))
1781
1801
 
 
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
 
1782
1895
 
1783
1896
class LoginOnlyTestCase(UbuntuSSOClientTestCase):
1784
1897
    """Test suite for the login only GUI."""
1804
1917
 
1805
1918
 
1806
1919
class SignalsTestCase(UbuntuSSOClientTestCase):
 
1920
    """Test the GTK signal emission."""
1807
1921
 
1808
1922
    def setUp(self):
1809
1923
        """Init."""
1814
1928
 
1815
1929
    def _set_called(self, widget, *args, **kwargs):
1816
1930
        """Keep trace of signals emition."""
 
1931
        # pylint: disable=W0221
1817
1932
        self._called[args[-1]] = (widget, args[:-1], kwargs)
1818
1933
 
 
1934
    def test_closing_main_window_sends_outcome_as_signal(self):
 
1935
        """A signal is sent when closing the main window."""
 
1936
        self.ui.window.emit('delete-event', gtk.gdk.Event(gtk.gdk.DELETE))
 
1937
        expected = (self.ui.window, (APP_NAME,), {})
 
1938
        self.assertEqual(self._called[gui.SIG_USER_CANCELATION], expected)
 
1939
 
1819
1940
    def test_every_cancel_emits_proper_signal(self):
1820
1941
        """Clicking on any cancel button, 'user-cancelation' signal is sent."""
1821
1942
        sig = gui.SIG_USER_CANCELATION
1832
1953
 
1833
1954
    def test_on_user_registration_error_proper_signal_is_emitted(self):
1834
1955
        """On UserRegistrationError, 'registration-failed' signal is sent."""
1835
 
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.ERROR)
 
1956
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.error)
1836
1957
        self.ui.on_close_clicked()
1837
1958
        expected = (self.ui.window, (APP_NAME, self.ui.UNKNOWN_ERROR), {})
1838
1959
        self.assertEqual(expected,
1847
1968
 
1848
1969
    def test_on_email_validation_error_proper_signals_is_emitted(self):
1849
1970
        """On EmailValidationError, 'registration-failed' signal is sent."""
1850
 
        self.ui.on_email_validation_error(app_name=APP_NAME, error=self.ERROR)
 
1971
        self.ui.on_email_validation_error(app_name=APP_NAME, error=self.error)
1851
1972
        self.ui.on_close_clicked()
1852
1973
        expected = (self.ui.window, (APP_NAME, self.ui.UNKNOWN_ERROR), {})
1853
1974
        self.assertEqual(expected,
1863
1984
    def test_on_login_error_proper_signals_is_emitted(self):
1864
1985
        """On LoginError, 'login-failed' signal is sent."""
1865
1986
        self.click_connect_with_valid_data()
1866
 
        self.ui.on_login_error(app_name=APP_NAME, error=self.ERROR)
 
1987
        self.ui.on_login_error(app_name=APP_NAME, error=self.error)
1867
1988
        self.ui.on_close_clicked()
1868
1989
        expected = (self.ui.window, (APP_NAME, self.ui.UNKNOWN_ERROR), {})
1869
1990
        self.assertEqual(expected,
1872
1993
    def test_registration_successfull_even_if_prior_registration_error(self):
1873
1994
        """Only one signal is sent with the final outcome."""
1874
1995
        self.click_join_with_valid_data()
1875
 
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.ERROR)
 
1996
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.error)
1876
1997
        self.click_join_with_valid_data()
1877
1998
        self.ui.on_email_validated(app_name=APP_NAME, email=EMAIL)
1878
1999
        self.ui.on_close_clicked()
1883
2004
    def test_login_successfull_even_if_prior_login_error(self):
1884
2005
        """Only one signal is sent with the final outcome."""
1885
2006
        self.click_connect_with_valid_data()
1886
 
        self.ui.on_login_error(app_name=APP_NAME, error=self.ERROR)
 
2007
        self.ui.on_login_error(app_name=APP_NAME, error=self.error)
1887
2008
        self.click_connect_with_valid_data()
1888
2009
        self.ui.on_logged_in(app_name=APP_NAME, email=EMAIL)
1889
2010
        self.ui.on_close_clicked()
1894
2015
    def test_user_cancelation_even_if_prior_registration_error(self):
1895
2016
        """Only one signal is sent with the final outcome."""
1896
2017
        self.click_join_with_valid_data()
1897
 
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.ERROR)
 
2018
        self.ui.on_user_registration_error(app_name=APP_NAME, error=self.error)
1898
2019
        self.ui.join_cancel_button.clicked()
1899
2020
 
1900
2021
        self.assertEqual(len(self._called), 1)
1903
2024
    def test_user_cancelation_even_if_prior_login_error(self):
1904
2025
        """Only one signal is sent with the final outcome."""
1905
2026
        self.click_connect_with_valid_data()
1906
 
        self.ui.on_login_error(app_name=APP_NAME, error=self.ERROR)
 
2027
        self.ui.on_login_error(app_name=APP_NAME, error=self.error)
1907
2028
        self.ui.login_cancel_button.clicked()
1908
2029
 
1909
2030
        self.assertEqual(len(self._called), 1)
1910
2031
        self.assertTrue(gui.SIG_USER_CANCELATION in self._called)
 
2032
 
 
2033
 
 
2034
class DefaultButtonsTestCase(UbuntuSSOClientTestCase):
 
2035
    """Each UI page has a default button when visible."""
 
2036
 
 
2037
    def setUp(self):
 
2038
        """Init."""
 
2039
        super(DefaultButtonsTestCase, self).setUp()
 
2040
        self.mapping = (
 
2041
            ('enter_details_vbox', 'join_ok_button'),
 
2042
            ('tc_browser_vbox', 'tc_back_button'),
 
2043
            ('verify_email_vbox', 'verify_token_button'),
 
2044
            ('login_vbox', 'login_ok_button'),
 
2045
            ('request_password_token_vbox',
 
2046
             'request_password_token_ok_button'),
 
2047
            ('set_new_password_vbox', 'set_new_password_ok_button'),
 
2048
            ('success_vbox', 'success_close_button'),
 
2049
            ('processing_vbox', None))
 
2050
 
 
2051
    def test_pages_have_default_widget_set(self):
 
2052
        """Each page has a proper button as default widget."""
 
2053
        msg = 'Page %r must have %r as default_widget (got %r instead).'
 
2054
        for pname, bname in self.mapping:
 
2055
            page = getattr(self.ui, pname)
 
2056
            button = bname and getattr(self.ui, bname)
 
2057
            self.assertTrue(page.default_widget is button,
 
2058
                            msg % (pname, bname, page.default_widget))
 
2059
 
 
2060
    def test_default_widget_can_default(self):
 
2061
        """Each default button can default."""
 
2062
        msg = 'Button %r must have can-default enabled.'
 
2063
        for _, bname in self.mapping:
 
2064
            if bname is not None:
 
2065
                button = getattr(self.ui, bname)
 
2066
                self.assertTrue(button.get_property('can-default'),
 
2067
                                msg % bname)
 
2068
 
 
2069
    def test_set_current_page_grabs_focus_for_default_button(self):
 
2070
        """Setting the current page marks the default widget as default."""
 
2071
        msg = '%r "has_default" must be True when %r if the current page.'
 
2072
        for pname, bname in self.mapping:
 
2073
            if bname is not None:
 
2074
                page = getattr(self.ui, pname)
 
2075
                self.patch(page.default_widget, 'grab_default',
 
2076
                           self._set_called)
 
2077
                self.ui._set_current_page(page)
 
2078
                self.assertEqual(self._called, ((), {}), msg % (bname, pname))
 
2079
                self._called = False