Merge lp:~mikemc/ubuntu-sso-client/fix-1031437-PIL-exception into lp:ubuntu-sso-client

Proposed by Mike McCracken on 2012-07-31
Status: Merged
Approved by: Roberto Alsina on 2012-08-01
Approved revision: 988
Merged at revision: 989
Proposed branch: lp:~mikemc/ubuntu-sso-client/fix-1031437-PIL-exception
Merge into: lp:ubuntu-sso-client
Diff against target: 55 lines (+15/-4)
2 files modified
ubuntu_sso/qt/setup_account_page.py (+4/-4)
ubuntu_sso/qt/tests/test_setup_account.py (+11/-0)
To merge this branch: bzr merge lp:~mikemc/ubuntu-sso-client/fix-1031437-PIL-exception
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve on 2012-08-01
Alejandro J. Cura (community) 2012-07-31 Approve on 2012-07-31
Review via email: mp+117504@code.launchpad.net

Commit Message

- Fix hang on captcha generation due to PIL exception. (LP: #1031437)

I tested this on darwin and linux.
Note that testing requires an IRL test, because the unit tests passed despite this bug.

Description of the Change

- Fix hang on captcha generation due to PIL exception. (LP: #1031437)

To post a comment you must log in.
Alejandro J. Cura (alecu) wrote :

Please add a new unit test that exercises this bug.

review: Needs Fixing
988. By Mike McCracken on 2012-07-31

add test to catch regression and check that image loaded has nonempty size

Mike McCracken (mikemc) wrote :

Test for on_captcha_generated added and verified that it shows the problem on darwin and linux.

Alejandro J. Cura (alecu) wrote :

Looks good!
All tests pass on ubuntu & windows 7.

review: Approve
Roberto Alsina (ralsina) :
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/setup_account_page.py'
2--- ubuntu_sso/qt/setup_account_page.py 2012-07-24 19:41:15 +0000
3+++ ubuntu_sso/qt/setup_account_page.py 2012-07-31 20:58:19 +0000
4@@ -30,7 +30,7 @@
5
6 import tempfile
7 import os
8-from io import StringIO
9+from io import BytesIO
10 from functools import partial
11
12 # pylint: disable=F0401
13@@ -329,10 +329,10 @@
14 # done either by a setParent or something within the qtreactor, PIL
15 # in this case does solve the issue. Sorry :(
16 pil_image = Image.open(self.captcha_file)
17- string_io = StringIO()
18- pil_image.save(string_io, format='png')
19+ bytes_io = BytesIO()
20+ pil_image.save(bytes_io, format='png')
21 pixmap_image = QtGui.QPixmap()
22- pixmap_image.loadFromData(string_io.getvalue())
23+ pixmap_image.loadFromData(bytes_io.getvalue())
24 self.captcha_image = pixmap_image
25 self.on_captcha_refresh_complete()
26
27
28=== modified file 'ubuntu_sso/qt/tests/test_setup_account.py'
29--- ubuntu_sso/qt/tests/test_setup_account.py 2012-06-08 15:10:34 +0000
30+++ ubuntu_sso/qt/tests/test_setup_account.py 2012-07-31 20:58:19 +0000
31@@ -30,6 +30,8 @@
32
33 from PyQt4 import QtGui, QtCore
34
35+from ubuntu_sso.tests import CAPTCHA_PATH
36+
37 from ubuntu_sso.qt import common, setup_account_page as gui
38 from ubuntu_sso.qt.tests import PageBaseTestCase
39
40@@ -337,6 +339,15 @@
41 self.ui.showEvent(QtGui.QShowEvent())
42 self.ui.hideEvent(QtGui.QHideEvent())
43
44+ def test_on_captcha_generated(self):
45+ """Check that the captcha image is handled correctly."""
46+
47+ self.ui.captcha_file = CAPTCHA_PATH
48+ self.ui.on_captcha_generated(u"fake app name",
49+ "fake id")
50+ pixmap_empty = self.ui.captcha_image.size().isEmpty()
51+ self.assertEqual(pixmap_empty, False)
52+
53 def test_on_captcha_refreshing_visible(self):
54 """Check the state of the overlay on captcha refreshing."""
55 self.ui.hide_overlay()

Subscribers

People subscribed via source and target branches