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
=== modified file 'lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt'
--- lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt 2010-03-31 19:54:31 +0000
+++ lib/canonical/launchpad/pagetests/webservice/launchpadlib.txt 2010-04-23 18:46:30 +0000
@@ -42,9 +42,29 @@
42 >>> print credentials.access_token42 >>> print credentials.access_token
43 oauth_token_secret=...&oauth_token=...43 oauth_token_secret=...&oauth_token=...
4444
45This can be used to create your own Launchpad object.45This can be used to create your own Launchpad object. Note you cannot
46use launchpadlib.uris.DEV_SERVICE_ROOT as the URL as it uses the https
47scheme which does not work in the test environment.
4648
47 >>> from launchpadlib.launchpad import Launchpad49 >>> from launchpadlib.launchpad import Launchpad
48 >>> launchpad = Launchpad(credentials, 'http://api.launchpad.dev/')50 >>> launchpad = Launchpad(credentials, 'http://api.launchpad.dev/')
49 >>> print launchpad.me.name51 >>> print launchpad.me.name
50 no-priv52 no-priv
53
54 >>> lp_anon = Launchpad.login_anonymously('launchpadlib test',
55 ... 'http://api.launchpad.dev/')
56
57The Launchpad object for the anonymous user can be used to access
58public information.
59
60 >>> apache_results = lp_anon.project_groups.search(text="Apache")
61 >>> print apache_results[0].name
62 apache
63
64But trying to access information that requires a logged in user
65results in an error.
66
67 >>> print lp_anon.me.name
68 Traceback (most recent call last):
69 ...
70 HTTPError: HTTP Error 401: Unauthorized...
5171
=== modified file 'lib/canonical/testing/layers.py'
--- lib/canonical/testing/layers.py 2010-04-06 13:41:11 +0000
+++ lib/canonical/testing/layers.py 2010-04-23 18:46:30 +0000
@@ -892,6 +892,11 @@
892 if environ.pop('HTTP_X_ZOPE_HANDLE_ERRORS', 'True') == 'False':892 if environ.pop('HTTP_X_ZOPE_HANDLE_ERRORS', 'True') == 'False':
893 environ['wsgi.handleErrors'] = False893 environ['wsgi.handleErrors'] = False
894 handle_errors = environ.get('wsgi.handleErrors', True)894 handle_errors = environ.get('wsgi.handleErrors', True)
895
896 # Make sure the request method is something Launchpad will
897 # recognize. httplib2 usually takes care of this, but we've
898 # bypassed that code in our test environment.
899 environ['REQUEST_METHOD'] = environ['REQUEST_METHOD'].upper()
895 # Now we do the proper dance to get the desired request. This is an900 # Now we do the proper dance to get the desired request. This is an
896 # almalgam of code from zope.app.testing.functional.HTTPCaller and901 # almalgam of code from zope.app.testing.functional.HTTPCaller and
897 # zope.publisher.paste.Application.902 # zope.publisher.paste.Application.