Merge lp:~mabac/launchpad/login-raises-non-string into lp:launchpad

Proposed by Mattias Backman
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 14753
Proposed branch: lp:~mabac/launchpad/login-raises-non-string
Merge into: lp:launchpad
Diff against target: 11 lines (+2/-0)
1 file modified
lib/lp/testing/_login.py (+2/-0)
To merge this branch: bzr merge lp:~mabac/launchpad/login-raises-non-string
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Richard Harding (community) code* Approve
Review via email: mp+91265@code.launchpad.net

Commit message

[r=jcsackett,rharding][no-qa] Raise ValueError if the email parameter to login() is not a string. Branch by Mattias Backman.

Description of the change

Hi,

This branch adds a check to login() in lib/lp/testing/_login.py so that it raises an error if the email parameter is not a string.

Thanks,

Mattias

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) wrote :

In checking the method the only possible options are either an email address or the lp.testing.ANONYMOUS which is a string as well.

I asked in IRC the driving idea behind the change and your explanation of clearing up a potential confusing error message seems potentially helpful in debugging the failing test driven from passing a non-email string to the method.

As noted in irc by salgado, basestring would be a much better comparison since often this will be a unicode string and not a strict str. Please update that.

review: Needs Fixing (code*)
Revision history for this message
Richard Harding (rharding) wrote :

Changes look good to me.

review: Approve (code*)
Revision history for this message
j.c.sackett (jcsackett) wrote :

I have nothing to add, thank you for updating to using basestring.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/testing/_login.py'
2--- lib/lp/testing/_login.py 2012-01-01 02:58:52 +0000
3+++ lib/lp/testing/_login.py 2012-02-02 14:19:27 +0000
4@@ -69,6 +69,8 @@
5 setPrincipal(), otherwise it must allow setting its principal attribute.
6 """
7
8+ if not isinstance(email, basestring):
9+ raise ValueError("Expected email parameter to be a string.")
10 participation = _test_login_impl(participation)
11 setupInteractionByEmail(email, participation)
12