Merge lp:~diegosarmentero/ubuntu-sso-client/captcha-refresh into lp:ubuntu-sso-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Roberto Alsina
Approved revision: 799
Merged at revision: 795
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/captcha-refresh
Merge into: lp:ubuntu-sso-client
Diff against target: 152 lines (+90/-1)
2 files modified
ubuntu_sso/qt/controllers.py (+3/-0)
ubuntu_sso/qt/tests/test_controllers.py (+87/-1)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/captcha-refresh
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+76621@code.launchpad.net

Commit message

- Fixed: There is no feedback on captcha loading/refreshing (LP: #852105).

Description of the change

- Fixed: There is no feedback on captcha loading/refreshing (LP: #852105).

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

I'm getting this lint issue:

== Python Lint Notices ==

ubuntu_sso/qt/tests/test_controllers.py:
    742: [W0622, FakeSetupAccountView.save] Redefining built-in 'format'

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

I see that you're not testing the captcha_refreshing new call. Can you please add a test for that?

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

I see that you're not testing the captcha_refreshing new call. Can you please add a test for that?

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

(sorry for the duplicated comment, LP was acting up)

796. By Diego Sarmentero

Adding more tests.

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

oh no! no again! :-)

ubuntu_sso/qt/tests/test_controllers.py:
    756: [C0103, FakeControllerForCaptcha.addErrback] Invalid name "addErrback" (should match ([a-z_][a-z0-9_]{2,79}$|setUp|tearDown))
    758: [W0201, FakeControllerForCaptcha.addErrback] Attribute 'callback_error' defined outside __init__

review: Needs Fixing
797. By Diego Sarmentero

lint issues fixed.

798. By Diego Sarmentero

lint issues fixed.

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

Looks good!

review: Approve
799. By Diego Sarmentero

Added bug number.

Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

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-21 21:41:04 +0000
3+++ ubuntu_sso/qt/controllers.py 2011-09-27 12:14:24 +0000
4@@ -374,6 +374,7 @@
5 if old_file:
6 d.addCallback(lambda x: os.unlink(old_file))
7 d.addErrback(self.on_captcha_generation_error)
8+ self.view.on_captcha_refreshing()
9
10 def _set_titles(self):
11 """Set the diff titles of the view."""
12@@ -408,11 +409,13 @@
13 pixmap_image = QPixmap()
14 pixmap_image.loadFromData(string_io.getvalue())
15 self.view.captcha_image = pixmap_image
16+ self.view.on_captcha_refresh_complete()
17
18 def on_captcha_generation_error(self, error):
19 """An error ocurred."""
20 logger.debug('SetUpAccountController.on_captcha_generation_error')
21 self.message_box.critical(CAPTCHA_LOAD_ERROR, self.view)
22+ self.view.on_captcha_refresh_complete()
23
24 def on_user_registration_error(self, app_name, error):
25 """Let the user know we could not register."""
26
27=== modified file 'ubuntu_sso/qt/tests/test_controllers.py'
28--- ubuntu_sso/qt/tests/test_controllers.py 2011-09-21 21:41:04 +0000
29+++ ubuntu_sso/qt/tests/test_controllers.py 2011-09-27 12:14:24 +0000
30@@ -24,6 +24,13 @@
31 from mocker import MATCH, MockerTestCase
32 from PyQt4.QtGui import QWizard
33
34+# pylint: disable=F0401
35+try:
36+ from PIL import Image
37+except ImportError:
38+ import Image
39+# pylint: enable=F0401
40+
41 from ubuntu_sso.qt.controllers import (
42 BackendController,
43 ChooseSignInController,
44@@ -711,6 +718,52 @@
45 """Simulate to add the message to the label as SetupAccount do."""
46
47
48+class FakeSetupAccountView(FakeView):
49+
50+ """A Fake view."""
51+
52+ captcha_file = None
53+ captcha_image = None
54+ captcha_refresh_executed = False
55+ captcha_refreshing_value = False
56+
57+ def on_captcha_refresh_complete(self):
58+ """Fake the call to refresh finished."""
59+ self.captcha_refresh_executed = True
60+
61+ def on_captcha_refreshing(self):
62+ """Fake the call to refreshing."""
63+ self.captcha_refreshing_value = True
64+
65+ def fake_open(self, filename):
66+ """Fake open for Image."""
67+ return self
68+
69+ # pylint: disable=W0622
70+ def save(self, io, format):
71+ """Fake save for Image."""
72+ # pylint: enable=W0622
73+
74+
75+class FakeControllerForCaptcha(object):
76+
77+ """Fake controller to test refresh_captcha method."""
78+
79+ def __init__(self):
80+ """Initialize FakeControllerForCaptcha."""
81+ self.callback_error = False
82+
83+ def generate_captcha(self, *args):
84+ """Fake generate deferred for captcha."""
85+ return self
86+
87+ # pylint: disable=C0103
88+ def addErrback(self, call):
89+ """Fake addErrback."""
90+ self.callback_error = call is not None
91+ # pylint: enable=C0103
92+
93+
94 class FakeEmailVerificationView(FakePageUiStyle):
95 """Fake EmailVerification Page."""
96
97@@ -721,6 +774,26 @@
98 self.next_button = self
99
100
101+class SetupAccountControllerCaptchaTest(BaseTestCase):
102+ """Tests for SetupAccountController, but without Mocker."""
103+
104+ def setUp(self):
105+ """Set the different tests."""
106+ super(SetupAccountControllerCaptchaTest, self).setUp()
107+ self.message_box = FakeMessageBox()
108+ self.controller = SetUpAccountController(message_box=self.message_box)
109+ self.patch(self.controller, 'view', FakeSetupAccountView())
110+ self.fake_backend = FakeControllerForCaptcha()
111+ self.patch(self.controller, 'backend', self.fake_backend)
112+
113+ def test_refresh_captcha(self):
114+ """Test the Refresh Captcha function."""
115+ self.assertFalse(self.controller.view.captcha_refreshing_value)
116+ self.controller._refresh_captcha()
117+ self.assertTrue(self.controller.view.captcha_refreshing_value)
118+ self.assertTrue(self.fake_backend.callback_error)
119+
120+
121 class SetupAccountControllerValidationTest(BaseTestCase):
122 """Tests for SetupAccountController, but without Mocker."""
123
124@@ -730,7 +803,7 @@
125 self.message_box = FakeMessageBox()
126 self.controller = SetUpAccountController(message_box=self.message_box)
127 self.patch(self.controller, '_refresh_captcha', self._set_called)
128- self.patch(self.controller, 'view', FakeView())
129+ self.patch(self.controller, 'view', FakeSetupAccountView())
130
131 def test_on_user_registration_refresh_captcha(self):
132 """If there is a user reg. error, captcha should refresh."""
133@@ -764,6 +837,19 @@
134 expected = (('', self.controller.view), {})
135 self.assertEqual(self.message_box.critical_args, expected)
136
137+ def test_on_captcha_generated(self):
138+ """Test if the method that shows the overlay is executed."""
139+ self.patch(Image, "open", self.controller.view.fake_open)
140+ self.assertFalse(self.controller.view.captcha_refresh_executed)
141+ self.controller.on_captcha_generated('app_name', 'captcha_id')
142+ self.assertTrue(self.controller.view.captcha_refresh_executed)
143+
144+ def test_on_captcha_generation_error(self):
145+ """Test if the method that hides the overlay is executed."""
146+ self.assertFalse(self.controller.view.captcha_refresh_executed)
147+ self.controller.on_captcha_generation_error({})
148+ self.assertTrue(self.controller.view.captcha_refresh_executed)
149+
150
151 class EmailVerificationControllerTestCase(MockerTestCase):
152 """Test the controller."""

Subscribers

People subscribed via source and target branches