Merge lp:~leonardr/lazr.restfulclient/test-long-etag into lp:lazr.restfulclient

Proposed by Leonard Richardson on 2010-03-16
Status: Merged
Merged at revision: not available
Proposed branch: lp:~leonardr/lazr.restfulclient/test-long-etag
Merge into: lp:lazr.restfulclient
Diff against target: 112 lines (+17/-24)
4 files modified
src/lazr/restfulclient/NEWS.txt (+6/-0)
src/lazr/restfulclient/_browser.py (+1/-7)
src/lazr/restfulclient/docs/authorizer.txt (+9/-16)
src/lazr/restfulclient/version.txt (+1/-1)
To merge this branch: bzr merge lp:~leonardr/lazr.restfulclient/test-long-etag
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code 2010-03-16 Approve on 2010-03-16
Review via email: mp+21455@code.launchpad.net

Description of the Change

Ignore the name of this branch; the thing I was testing didn't need any changes, but I found some test failures while I was testing.

A new version of simplejson breaks some lazr.restfulclient tests: what used to be a ValueError is now a JSONDecodeError. I had code that created a fake web service and interpreted a ValueError as a sign that a client had managed to authenticate with the service--since the web service didn't actually serve any JSON, the client's next step after authenticating ended in failure.

I decided to fix the tests by making the fake web service a little better, making it serve some (fake) JSON, so that if the client authenticates with the fake web service there will be no error at all.

To keep the fake web service simple, I removed some no-longer-needed code that was used to fix bug 457146. Since Launchpad now runs a version of lazr.restful that doesn't have bug 457146 (and has for months), I think it's safe to remove the client-side hack. I won't remove the corresponding code from lazr.restful, because old versions of lazr.restfulclient are still around and manifesting bug 457146.

To post a comment you must log in.
Brad Crittenden (bac) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restfulclient/NEWS.txt'
2--- src/lazr/restfulclient/NEWS.txt 2010-03-09 19:50:44 +0000
3+++ src/lazr/restfulclient/NEWS.txt 2010-03-16 16:04:19 +0000
4@@ -2,6 +2,12 @@
5 NEWS for lazr.restfulclient
6 ===========================
7
8+0.9.13 (Development)
9+===================
10+
11+- Removed of some no-longer-needed compatibility code for buggy
12+ servers, and fixed the tests to work with the new release of simplejson.
13+
14 0.9.12 (2010-03-09)
15 ===================
16
17
18=== modified file 'src/lazr/restfulclient/_browser.py'
19--- src/lazr/restfulclient/_browser.py 2010-03-09 15:20:23 +0000
20+++ src/lazr/restfulclient/_browser.py 2010-03-16 16:04:19 +0000
21@@ -270,14 +270,8 @@
22
23 def get_wadl_application(self, url):
24 """GET a WADL representation of the resource at the requested url."""
25- # We're probably talking to an old version of lazr.restful
26- # that misspells the WADL media type. Accept either the correctly
27- # spelled media type or the misspelling.
28 wadl_type = 'application/vnd.sun.wadl+xml'
29- misspelled_wadl_type = 'application/vd.sun.wadl+xml'
30- accept = "%s, %s" % (wadl_type, misspelled_wadl_type)
31- response, content = self._request(
32- url, media_type=wadl_type, extra_headers={'Accept': accept})
33+ response, content = self._request(url, media_type=wadl_type)
34 return Application(str(url), content)
35
36 def post(self, url, method_name, **kws):
37
38=== modified file 'src/lazr/restfulclient/docs/authorizer.txt'
39--- src/lazr/restfulclient/docs/authorizer.txt 2009-12-14 21:04:46 +0000
40+++ src/lazr/restfulclient/docs/authorizer.txt 2010-03-16 16:04:19 +0000
41@@ -15,10 +15,15 @@
42 >>> wadl_string = pkg_resources.resource_string(
43 ... 'wadllib.tests.data', 'launchpad-wadl.xml')
44
45+ >>> responses = { 'application/vnd.sun.wadl+xml' : wadl_string,
46+ ... 'application/json' : '{}' }
47+
48 >>> def dummy_application(environ, start_response):
49+ ... media_type = environ['HTTP_ACCEPT']
50+ ... content = responses[media_type]
51 ... start_response(
52- ... '200', [('Content-type','application/vnd.sun.wadl+xml')])
53- ... return [wadl_string]
54+ ... '200', [('Content-type', media_type)])
55+ ... return [content]
56
57
58 The WADL file will be protected with HTTP Basic Auth. To access it,
59@@ -73,14 +78,11 @@
60
61 If we provide the right credentials, we can retrieve the WADL. We'll
62 still get an exception, because our fake web service is too fake for
63-ServiceRoot--it doesn't serve any JSON resources--but we're able to
64-make HTTP requests without getting 401 errors.
65+ServiceRoot--its 'service root' resource doesn't match the WADL--but
66+we're able to make HTTP requests without getting 401 errors.
67
68 >>> authorizer = BasicHttpAuthorizer("user", "password")
69 >>> client = ServiceRoot(authorizer, "http://api.launchpad.dev/")
70- Traceback (most recent call last):
71- ...
72- ValueError: No JSON object could be decoded
73
74 Teardown.
75
76@@ -178,9 +180,6 @@
77 >>> authorizer = OAuthAuthorizer(
78 ... valid_consumer.key, access_token=valid_token)
79 >>> client = ServiceRoot(authorizer, "http://api.launchpad.dev/")
80- Traceback (most recent call last):
81- ...
82- ValueError: No JSON object could be decoded
83
84 It's even possible to get anonymous access by providing an empty
85 access token.
86@@ -188,9 +187,6 @@
87 >>> authorizer = OAuthAuthorizer(
88 ... valid_consumer, access_token=empty_token)
89 >>> client = ServiceRoot(authorizer, "http://api.launchpad.dev/")
90- Traceback (most recent call last):
91- ...
92- ValueError: No JSON object could be decoded
93
94 Because of the way the AnonymousAccessDataStore (defined
95 earlier in the test) works, you can even get anonymous access by
96@@ -200,9 +196,6 @@
97 >>> authorizer = OAuthAuthorizer(
98 ... "random consumer", access_token=empty_token)
99 >>> client = ServiceRoot(authorizer, "http://api.launchpad.dev/")
100- Traceback (most recent call last):
101- ...
102- ValueError: No JSON object could be decoded
103
104 If you try to provide credentials with an unrecognized OAuth consumer,
105 you'll get an error--even if the credentials are valid. The data store
106
107=== modified file 'src/lazr/restfulclient/version.txt'
108--- src/lazr/restfulclient/version.txt 2010-03-09 15:28:38 +0000
109+++ src/lazr/restfulclient/version.txt 2010-03-16 16:04:19 +0000
110@@ -1,1 +1,1 @@
111-0.9.12
112+0.9.13

Subscribers

People subscribed via source and target branches