Merge lp:~diegosarmentero/ubuntu-sso-client/reset-error into lp:ubuntu-sso-client

Proposed by Diego Sarmentero on 2012-03-23
Status: Merged
Approved by: Diego Sarmentero on 2012-03-26
Approved revision: 937
Merged at revision: 935
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/reset-error
Merge into: lp:ubuntu-sso-client
Diff against target: 55 lines (+22/-1)
3 files modified
ubuntu_sso/main/tests/test_common.py (+12/-0)
ubuntu_sso/utils/webclient/qtnetwork.py (+2/-1)
ubuntu_sso/utils/webclient/tests/test_webclient.py (+8/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/reset-error
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve on 2012-03-26
Natalia Bidart 2012-03-23 Approve on 2012-03-26
Review via email: mp+99039@code.launchpad.net

Commit Message

- Converting to unicode some data returned by webclient in QByteArray format (LP: 961315).

To post a comment you must log in.
Natalia Bidart (nataliabidart) wrote :

The fix applied to account.py should be applied to the webclient module instead, since despite we're ensuring having unicode for NewPasswordError, we may leak QBytes from other calls, into other exceptions or results, and that's not good.

So, unless is not doable and I'm missing something (please advice), this branch needs to address that, providing a test for the webclient module ensuring that no qt types are leaked.

Thanks!

review: Needs Fixing
933. By Diego Sarmentero on 2012-03-23

Improving tests.

934. By Diego Sarmentero on 2012-03-23

Tests fixed.

935. By Diego Sarmentero on 2012-03-23

merge

Natalia Bidart (nataliabidart) wrote :

A couple of minor neat picks:

* the 'pass' sentence in the MyException class is not needed

* the docstring for test_webclienterror_not_string says "The returned content are bytes." but your code makes the content unicode, not bytes...

* the way to test this:

        try:
            yield self.wc.request(self.base_iri + THROWERROR)
        except Exception, e:
            for error in e.args:
                self.assertTrue(isinstance(error, basestring))

like I mentioned over IRC, is:

    deferred = self.wc.request(self.base_iri + THROWERROR)
    failure = yield self.assertFailure(deferred, webclient.WebClientError)
    # do the asserts over failure (failure.value has the real exception)

review: Needs Fixing
936. By Diego Sarmentero on 2012-03-26

Minor fixes.

Diego Sarmentero (diegosarmentero) wrote :

> A couple of minor neat picks:
>
> * the 'pass' sentence in the MyException class is not needed
>
> * the docstring for test_webclienterror_not_string says "The returned content
> are bytes." but your code makes the content unicode, not bytes...
>
> * the way to test this:
>
> try:
> yield self.wc.request(self.base_iri + THROWERROR)
> except Exception, e:
> for error in e.args:
> self.assertTrue(isinstance(error, basestring))
>
> like I mentioned over IRC, is:
>
> deferred = self.wc.request(self.base_iri + THROWERROR)
> failure = yield self.assertFailure(deferred, webclient.WebClientError)
> # do the asserts over failure (failure.value has the real exception)

Fixed!

937. By Diego Sarmentero on 2012-03-26

removing unnecessary variable.

Natalia Bidart (nataliabidart) wrote :

Looks great!

review: Approve
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/main/tests/test_common.py'
2--- ubuntu_sso/main/tests/test_common.py 2012-02-17 18:43:17 +0000
3+++ ubuntu_sso/main/tests/test_common.py 2012-03-26 14:31:18 +0000
4@@ -118,6 +118,18 @@
5 self.assertEqual(result["errtype"], e.__class__.__name__)
6 self.assertEqual(result["message"], sample_string)
7
8+ def test_first_arg_is_exception(self):
9+ """If the first arg is an Exception, use it's message attribute'."""
10+
11+ class MyException(Exception):
12+ """Custom Exception."""
13+
14+ message = u'My custom error for ♥ Ubuntu'
15+ my_exc = MyException(message)
16+ result = except_to_errdict(my_exc)
17+ self.assertEqual(result["errtype"], my_exc.__class__.__name__)
18+ self.assertEqual(result["message"], message)
19+
20 def test_first_arg_is_unicode(self):
21 """If the first arg is a unicode, use it as the message."""
22 sample_string = u"a sample string"
23
24=== modified file 'ubuntu_sso/utils/webclient/qtnetwork.py'
25--- ubuntu_sso/utils/webclient/qtnetwork.py 2012-03-19 23:53:06 +0000
26+++ ubuntu_sso/utils/webclient/qtnetwork.py 2012-03-26 14:31:18 +0000
27@@ -188,7 +188,8 @@
28 response = Response(bytes(content), headers)
29 d.callback(response)
30 else:
31- error_string = reply.errorString()
32+ content = unicode(content)
33+ error_string = unicode(reply.errorString())
34 logger.debug('_handle_finished error (%s,%s).', error,
35 error_string)
36 if error == QNetworkReply.AuthenticationRequiredError:
37
38=== modified file 'ubuntu_sso/utils/webclient/tests/test_webclient.py'
39--- ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-03-19 23:43:56 +0000
40+++ ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-03-26 14:31:18 +0000
41@@ -373,6 +373,14 @@
42 self.assertTrue(isinstance(result.content, bytes),
43 "The type of %r must be bytes" % result.content)
44
45+ @defer.inlineCallbacks
46+ def test_webclienterror_not_string(self):
47+ """The returned exception contains unicode data."""
48+ deferred = self.wc.request(self.base_iri + THROWERROR)
49+ failure = yield self.assertFailure(deferred, webclient.WebClientError)
50+ for error in failure.args:
51+ self.assertTrue(isinstance(error, basestring))
52+
53
54 class FakeSavingReactor(object):
55 """A fake reactor that saves connection attempts."""

Subscribers

People subscribed via source and target branches