Merge lp:~bac/launchpad/bug-569101 into lp:launchpad

Proposed by Brad Crittenden
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bac/launchpad/bug-569101
Merge into: lp:launchpad
Diff against target: 50 lines (+26/-1)
2 files modified
lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt (+21/-1)
lib/canonical/testing/layers.py (+5/-0)
To merge this branch: bzr merge lp:~bac/launchpad/bug-569101
Reviewer Review Type Date Requested Status
Curtis Hovey (community) Approve
Review via email: mp+24034@code.launchpad.net

Commit message

Uppercase the request method to fix a bug using launchpadlib in the test environment.

Description of the change

= Summary =

Using lplib in the test environment is broken for many calls as the
REQUEST_METHOD is sent as 'get' but expected as GET.

== Proposed fix ==

Uppercase the method in the testing layer before sending it on.

== Pre-implementation notes ==

Fix suggested by Leonard.

== Implementation details ==

As above.

== Tests ==

bin/test -vvt webservice/launchpadlib.txt

The test that exercises the new piece is the anonymous search. It is a
bit contrived but I wanted something that would be around for regression
testing but would also add some explanatory comment. The risk is a
developer in the future will think it is dumb and will remove it.

== Demo and Q/A ==

N/A

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt
  lib/canonical/testing/layers.py

== Pyflakes Doctest notices ==

lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt
    11: undefined name 'launchpadlib_for'

== Pyflakes notices ==

lib/canonical/testing/layers.py
    508: redefinition of unused 'pidfile' from line 95

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thanks for providing this fix. At least some good will come from your trial with delete.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt'
2--- lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt 2010-03-31 19:54:31 +0000
3+++ lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt 2010-04-23 18:46:30 +0000
4@@ -42,9 +42,29 @@
5 >>> print credentials.access_token
6 oauth_token_secret=...&oauth_token=...
7
8-This can be used to create your own Launchpad object.
9+This can be used to create your own Launchpad object. Note you cannot
10+use launchpadlib.uris.DEV_SERVICE_ROOT as the URL as it uses the https
11+scheme which does not work in the test environment.
12
13 >>> from launchpadlib.launchpad import Launchpad
14 >>> launchpad = Launchpad(credentials, 'http://api.launchpad.dev/')
15 >>> print launchpad.me.name
16 no-priv
17+
18+ >>> lp_anon = Launchpad.login_anonymously('launchpadlib test',
19+ ... 'http://api.launchpad.dev/')
20+
21+The Launchpad object for the anonymous user can be used to access
22+public information.
23+
24+ >>> apache_results = lp_anon.project_groups.search(text="Apache")
25+ >>> print apache_results[0].name
26+ apache
27+
28+But trying to access information that requires a logged in user
29+results in an error.
30+
31+ >>> print lp_anon.me.name
32+ Traceback (most recent call last):
33+ ...
34+ HTTPError: HTTP Error 401: Unauthorized...
35
36=== modified file 'lib/canonical/testing/layers.py'
37--- lib/canonical/testing/layers.py 2010-04-06 13:41:11 +0000
38+++ lib/canonical/testing/layers.py 2010-04-23 18:46:30 +0000
39@@ -892,6 +892,11 @@
40 if environ.pop('HTTP_X_ZOPE_HANDLE_ERRORS', 'True') == 'False':
41 environ['wsgi.handleErrors'] = False
42 handle_errors = environ.get('wsgi.handleErrors', True)
43+
44+ # Make sure the request method is something Launchpad will
45+ # recognize. httplib2 usually takes care of this, but we've
46+ # bypassed that code in our test environment.
47+ environ['REQUEST_METHOD'] = environ['REQUEST_METHOD'].upper()
48 # Now we do the proper dance to get the desired request. This is an
49 # almalgam of code from zope.app.testing.functional.HTTPCaller and
50 # zope.publisher.paste.Application.