Merge lp:~diegosarmentero/ubuntu-sso-client/845750 into lp:ubuntu-sso-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Natalia Bidart
Approved revision: 790
Merged at revision: 786
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/845750
Merge into: lp:ubuntu-sso-client
Prerequisite: lp:~diegosarmentero/ubuntu-sso-client/845759
Diff against target: 229 lines (+88/-34)
2 files modified
ubuntu_sso/qt/controllers.py (+40/-0)
ubuntu_sso/qt/tests/test_windows.py (+48/-34)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/845750
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Review via email: mp+75606@code.launchpad.net

This proposal supersedes a proposal from 2011-09-13.

Commit message

- Fixed button style from Reset Password Page and Forgotten Password Page. (LP: #845750).

Description of the change

Fixed button style from Reset Password Page and Forgotten Password Page.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote : Posted in a previous version of this proposal

Code looks good!

A simple improvement to the test code

in FakeForgottenPasswordPage, instead of:

    def setProperty(self, key, val):
        """Fake setProperty to restyle some widget."""
        self.property_key = key
        self.property_value = val

it would be better to have an instance attr:

    self.properties = {}

and then:

    def setProperty(self, key, val):
        """Fake setProperty to restyle some widget."""
        self.propertyies[key] = val

With that change, you can have:

    def setDefault(self, val):
        """Fake button setDefault."""
        self.is_default = val

become:

    def setDefault(self, val):
        """Fake button setDefault."""
        self.properties['default'] = val

The next improvement would be to have the common functionality for the fakes into a base class and reuse that from the 2 controllers (FakeForgottenPasswordPage, FakeResetPasswordPage) and any other class that needs a similar testing.

review: Needs Fixing
789. By Diego Sarmentero

Improved generic wizard fake.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I'm getting:

== Python Lint Notices ==

ubuntu_sso/qt/controllers.py:
    758: [C0103, ResetPasswordController.pageInitialized] Invalid name "pageInitialized" (should match ([a-z_][a-z0-9_]{2,79}$|setUp|tearDown))

review: Needs Fixing
790. By Diego Sarmentero

Fixed lint issue

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/qt/controllers.py'
2--- ubuntu_sso/qt/controllers.py 2011-09-15 19:51:28 +0000
3+++ ubuntu_sso/qt/controllers.py 2011-09-15 21:40:25 +0000
4@@ -642,6 +642,20 @@
5 self.message_box = message_box
6 super(ForgottenPasswordController, self).__init__(title, subtitle)
7
8+ #pylint: disable=C0103
9+ def pageInitialized(self):
10+ """Set the initial state of ForgottenPassword page."""
11+ self.view.send_button.setDefault(True)
12+ self.view.send_button.setEnabled(False)
13+ # The style from this property come from the Wizard
14+ self.view.send_button.setProperty("DisabledState",
15+ not self.view.send_button.isEnabled())
16+ self.view.send_button.style().unpolish(
17+ self.view.send_button)
18+ self.view.send_button.style().polish(
19+ self.view.send_button)
20+ #pylint: enable=C0103
21+
22 def _register_fields(self):
23 """Register the fields of the wizard page."""
24 self.view.registerField('email_address',
25@@ -679,6 +693,12 @@
26 """Validate that we have an email."""
27 email = unicode(self.view.email_address_line_edit.text())
28 self.view.send_button.setEnabled(is_correct_email(email))
29+ self.view.send_button.setProperty("DisabledState",
30+ not self.view.send_button.isEnabled())
31+ self.view.send_button.style().unpolish(
32+ self.view.send_button)
33+ self.view.send_button.style().polish(
34+ self.view.send_button)
35
36 def on_try_again(self):
37 """Set back the widget to the initial state."""
38@@ -735,6 +755,20 @@
39 self.message_box = message_box
40 super(ResetPasswordController, self).__init__(title, subtitle)
41
42+ #pylint: disable=C0103
43+ def pageInitialized(self):
44+ """Set the initial state of ForgottenPassword page."""
45+ self.view.ui.reset_password_button.setDefault(True)
46+ self.view.ui.reset_password_button.setEnabled(False)
47+ # The style from this property come from the Wizard
48+ self.view.ui.reset_password_button.setProperty("DisabledState",
49+ not self.view.ui.reset_password_button.isEnabled())
50+ self.view.ui.reset_password_button.style().unpolish(
51+ self.view.ui.reset_password_button)
52+ self.view.ui.reset_password_button.style().polish(
53+ self.view.ui.reset_password_button)
54+ #pylint: enable=C0103
55+
56 def _set_translated_strings(self):
57 """Translate the diff strings used in the app."""
58 self.view.ui.reset_password_button.setText(RESET_PASSWORD)
59@@ -766,6 +800,12 @@
60 elif not code:
61 enabled = False
62 self.view.ui.reset_password_button.setEnabled(enabled)
63+ self.view.ui.reset_password_button.setProperty("DisabledState",
64+ not self.view.ui.reset_password_button.isEnabled())
65+ self.view.ui.reset_password_button.style().unpolish(
66+ self.view.ui.reset_password_button)
67+ self.view.ui.reset_password_button.style().polish(
68+ self.view.ui.reset_password_button)
69
70 def _add_line_edits_validations(self):
71 """Add the validations to be use by the line edits."""
72
73=== modified file 'ubuntu_sso/qt/tests/test_windows.py'
74--- ubuntu_sso/qt/tests/test_windows.py 2011-09-15 19:51:28 +0000
75+++ ubuntu_sso/qt/tests/test_windows.py 2011-09-15 21:40:25 +0000
76@@ -971,33 +971,13 @@
77 self.controller.setupUi(self.view)
78
79
80-class FakeForgottenPasswordPage(FakeView):
81+class FakeForgottenPasswordPage(tests.FakePageUiStyle):
82 """Fake the page."""
83
84 def __init__(self):
85+ super(FakeForgottenPasswordPage, self).__init__()
86 self.email_address_line_edit = self
87 self.send_button = self
88- self._text = ""
89- self._enabled = False
90- super(FakeForgottenPasswordPage, self).__init__()
91-
92- def text(self):
93- """Return text."""
94- return self._text
95-
96- # setText, setEnabled are inherited
97- # pylint: disable=C0103
98- def setText(self, text):
99- """Save text."""
100- self._text = text
101-
102- def setEnabled(self, value):
103- """Fake setEnabled."""
104- self._enabled = value
105-
106- def enabled(self):
107- """Fake enabled."""
108- return self._enabled
109
110
111 class ForgottenPasswordControllerValidationTest(TestCase):
112@@ -1017,6 +997,17 @@
113 """Store 'args' and 'kwargs' for test assertions."""
114 self._called = (args, kwargs)
115
116+ def test_page_initialized(self):
117+ """Test the initial state of the page when it is loaded."""
118+ self.controller.pageInitialized()
119+ self.assertFalse(self.controller.view.send_button.enabled())
120+ self.assertTrue(self.controller.view.send_button.properties['default'])
121+ self.assertTrue("DisabledState" in self.controller.view.properties)
122+ self.assertEqual(self.controller.view.properties["DisabledState"],
123+ not self.controller.view.send_button.enabled())
124+ self.assertTrue(self.controller.view.properties.get('unpolish', False))
125+ self.assertTrue(self.controller.view.properties.get('polish', False))
126+
127 def test_valid(self):
128 """The submit button should be enabled with a valid email."""
129 self.controller.view.email_address_line_edit.setText("a@b")
130@@ -1024,6 +1015,11 @@
131 self.controller.view.email_address_line_edit.text()), u"")
132 self.controller._validate()
133 self.assertTrue(self.controller.view.send_button.enabled())
134+ self.assertTrue("DisabledState" in self.controller.view.properties)
135+ self.assertEqual(self.controller.view.properties["DisabledState"],
136+ not self.controller.view.send_button.enabled())
137+ self.assertTrue(self.controller.view.properties.get('unpolish', False))
138+ self.assertTrue(self.controller.view.properties.get('polish', False))
139
140 def test_invalid(self):
141 """The submit button should be disabled with an invalid email."""
142@@ -1032,6 +1028,11 @@
143 unicode(self.controller.view.email_address_line_edit.text()), u"")
144 self.controller._validate()
145 self.assertFalse(self.controller.view.send_button.enabled())
146+ self.assertTrue("DisabledState" in self.controller.view.properties)
147+ self.assertEqual(self.controller.view.properties["DisabledState"],
148+ not self.controller.view.send_button.enabled())
149+ self.assertTrue(self.controller.view.properties.get('unpolish', False))
150+ self.assertTrue(self.controller.view.properties.get('polish', False))
151
152 def test_empty(self):
153 """The submit button should be disabled without email."""
154@@ -1225,29 +1226,19 @@
155 password))
156
157
158-class FakeResetPasswordPage(object):
159+class FakeResetPasswordPage(tests.FakePageUiStyle):
160
161 """Fake ResetPasswordPage."""
162
163 def __init__(self, *args):
164 """Initialize."""
165- self.ui = self
166+ super(FakeResetPasswordPage, self).__init__()
167 self.ui.reset_code_line_edit = FakeLineEdit()
168 self.ui.password_line_edit = FakeLineEdit()
169 self.ui.confirm_password_line_edit = FakeLineEdit()
170 self.reset_password_button = self
171 self._enabled = 9 # Intentionally wrong.
172
173- # setEnabled is inherited
174- # pylint: disable=C0103
175- def setEnabled(self, value):
176- """Fake setEnabled."""
177- self._enabled = value
178-
179- def enabled(self):
180- """Fake enabled."""
181- return self._enabled
182-
183
184 class ResetPasswordControllerValidationTest(TestCase):
185
186@@ -1260,6 +1251,19 @@
187 self.controller.view = FakeResetPasswordPage()
188 self._called = False
189
190+ def test_page_initialized(self):
191+ """Test the initial state of the page when it is loaded."""
192+ self.controller.pageInitialized()
193+ self.assertFalse(
194+ self.controller.view.reset_password_button.enabled())
195+ self.assertTrue(
196+ self.controller.view.reset_password_button.properties['default'])
197+ self.assertTrue("DisabledState" in self.controller.view.properties)
198+ self.assertEqual(self.controller.view.properties["DisabledState"],
199+ not self.controller.view.reset_password_button.enabled())
200+ self.assertTrue(self.controller.view.properties.get('unpolish', False))
201+ self.assertTrue(self.controller.view.properties.get('polish', False))
202+
203 def _set_called(self, *args, **kwargs):
204 """Store 'args' and 'kwargs' for test assertions."""
205 self._called = (args, kwargs)
206@@ -1271,6 +1275,11 @@
207 self.controller.view.confirm_password_line_edit.setText("1234567A")
208 self.controller._validate()
209 self.assertTrue(self.controller.view.reset_password_button.enabled())
210+ self.assertTrue("DisabledState" in self.controller.view.properties)
211+ self.assertEqual(self.controller.view.properties["DisabledState"],
212+ not self.controller.view.reset_password_button.enabled())
213+ self.assertTrue(self.controller.view.properties.get('unpolish', False))
214+ self.assertTrue(self.controller.view.properties.get('polish', False))
215
216 def test_invalid_code(self):
217 """Disable the button with an invalid code."""
218@@ -1279,6 +1288,11 @@
219 self.controller.view.confirm_password_line_edit.setText("1234567A")
220 self.controller._validate()
221 self.assertFalse(self.controller.view.reset_password_button.enabled())
222+ self.assertTrue("DisabledState" in self.controller.view.properties)
223+ self.assertEqual(self.controller.view.properties["DisabledState"],
224+ not self.controller.view.reset_password_button.enabled())
225+ self.assertTrue(self.controller.view.properties.get('unpolish', False))
226+ self.assertTrue(self.controller.view.properties.get('polish', False))
227
228 def test_invalid_password(self):
229 """Disable the button with an invalid password."""

Subscribers

People subscribed via source and target branches