Merge lp:~leonardr/lazr.restful/tag-web-service-request into lp:lazr.restful

Proposed by Leonard Richardson
Status: Merged
Approved by: Brad Crittenden
Approved revision: 116
Merge reported by: Leonard Richardson
Merged at revision: not available
Proposed branch: lp:~leonardr/lazr.restful/tag-web-service-request
Merge into: lp:lazr.restful
Diff against target: 190 lines (+51/-16) (has conflicts)
8 files modified
src/lazr/restful/NEWS.txt (+9/-0)
src/lazr/restful/docs/webservice-request.txt (+5/-0)
src/lazr/restful/publisher.py (+3/-9)
src/lazr/restful/testing/webservice.py (+1/-0)
src/lazr/restful/tests/test_utils.py (+2/-1)
src/lazr/restful/tests/test_webservice.py (+14/-3)
src/lazr/restful/utils.py (+16/-2)
src/lazr/restful/version.txt (+1/-1)
Text conflict in src/lazr/restful/NEWS.txt
To merge this branch: bzr merge lp:~leonardr/lazr.restful/tag-web-service-request
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+20454@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

I was having problems that stemmed from the fact that browser_request_to_web_service_request() (in publisher.py) was incorrectly tagging new web service requests with version information. I refactored the tagging code from WebServiceRequestTraversal.traverse() into a utility function and used it in both places. (I could have made it a private helper function in publisher.py, but 1) I like being able to test it on its own in a unit test, and 2) I believe it will be useful again in the future.)

I propose releasing this branch as lazr.restful 0.9.22, but it is not based on the current lazr.restful trunk. The current trunk has code to do with mutator named operations which I don't want to integrate into Launchpad right now.

Revision history for this message
Leonard Richardson (leonardr) wrote :
Revision history for this message
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/restful/NEWS.txt'
2--- src/lazr/restful/NEWS.txt 2010-02-23 19:07:23 +0000
3+++ src/lazr/restful/NEWS.txt 2010-03-02 15:20:33 +0000
4@@ -2,6 +2,7 @@
5 NEWS for lazr.restful
6 =====================
7
8+<<<<<<< TREE
9 Development
10 ===========
11
12@@ -15,6 +16,14 @@
13 your web service in the "last_version_with_named_mutator_operations"
14 field of your IWebServiceConfiguration implementation.
15
16+=======
17+0.9.22 (2010-03-02)
18+===================
19+
20+Refactored the code that tags request objects with version
21+information, so that tagging would happen consistently.
22+
23+>>>>>>> MERGE-SOURCE
24 0.9.21 (2010-02-23)
25 ===================
26
27
28=== modified file 'src/lazr/restful/docs/webservice-request.txt'
29--- src/lazr/restful/docs/webservice-request.txt 2009-11-12 19:08:10 +0000
30+++ src/lazr/restful/docs/webservice-request.txt 2010-03-02 15:20:33 +0000
31@@ -29,8 +29,13 @@
32 ... request.setPublication(WebServiceTestPublication(None))
33 ... return request
34
35+ >>> from lazr.restful.interfaces import IWebServiceVersion
36+ >>> class IBetaVersion(IWebServiceVersion):
37+ ... """Marker interface for web service version."""
38+
39 >>> sm = getSiteManager()
40 >>> sm.registerUtility(SimpleWebServiceConfiguration())
41+ >>> sm.registerUtility(IBetaVersion, IWebServiceVersion, name="beta")
42 >>> sm.registerAdapter(browser_request_to_web_service_request)
43
44 >>> website_request = TestRequest(SERVER_URL="http://cookbooks.dev/")
45
46=== modified file 'src/lazr/restful/publisher.py'
47--- src/lazr/restful/publisher.py 2010-02-11 17:57:16 +0000
48+++ src/lazr/restful/publisher.py 2010-03-02 15:20:33 +0000
49@@ -36,6 +36,7 @@
50 IByteStorage, ICollection, ICollectionField, IEntry, IEntryField,
51 IHTTPResource, IServiceRootResource, IWebBrowserInitiatedRequest,
52 IWebServiceClientRequest, IWebServiceConfiguration, IWebServiceVersion)
53+from lazr.restful.utils import tag_request_with_version_name
54
55
56 class WebServicePublicationMixin:
57@@ -253,13 +254,7 @@
58 break
59 if version is None:
60 raise NotFound(self, '', self)
61- self.annotations[self.VERSION_ANNOTATION] = version
62-
63- # Find the version-specific interface this request should
64- # provide, and provide it.
65- to_provide = getUtility(IWebServiceVersion, name=version)
66- alsoProvides(self, to_provide)
67- self.version = version
68+ tag_request_with_version_name(self, version)
69
70 # Find the appropriate service root for this version and set
71 # the publication's application appropriately.
72@@ -309,7 +304,6 @@
73 web_service_request = config.createRequest(body, environ)
74 web_service_request.setVirtualHostRoot(
75 names=[config.path_override, web_service_version])
76- web_service_request.annotations[web_service_request.VERSION_ANNOTATION] = (
77- web_service_request)
78+ tag_request_with_version_name(web_service_request, web_service_version)
79 web_service_request._vh_root = website_request.getVirtualHostRoot()
80 return web_service_request
81
82=== modified file 'src/lazr/restful/testing/webservice.py'
83--- src/lazr/restful/testing/webservice.py 2010-02-11 17:57:16 +0000
84+++ src/lazr/restful/testing/webservice.py 2010-03-02 15:20:33 +0000
85@@ -118,6 +118,7 @@
86 self.query_string_params = {}
87 self.method = 'GET'
88
89+
90 def getTraversalStack(self):
91 """See `IPublicationRequest`.
92
93
94=== modified file 'src/lazr/restful/tests/test_utils.py'
95--- src/lazr/restful/tests/test_utils.py 2010-02-18 15:23:59 +0000
96+++ src/lazr/restful/tests/test_utils.py 2010-03-02 15:20:33 +0000
97@@ -29,4 +29,5 @@
98 endInteraction()
99
100 # For the sake of convenience, test_get_current_web_service_request()
101- # is tested in test_webservice.py.
102+ # and tag_request_with_version_name() are tested in test_webservice.py.
103+
104
105=== modified file 'src/lazr/restful/tests/test_webservice.py'
106--- src/lazr/restful/tests/test_webservice.py 2010-02-25 17:07:16 +0000
107+++ src/lazr/restful/tests/test_webservice.py 2010-03-02 15:20:33 +0000
108@@ -36,7 +36,8 @@
109 create_web_service_request, WebServiceTestPublication)
110 from lazr.restful.testing.tales import test_tales
111 from lazr.restful.utils import (
112- get_current_browser_request, get_current_web_service_request)
113+ get_current_browser_request, get_current_web_service_request,
114+ tag_request_with_version_name)
115
116
117 def get_resource_factory(model_interface, resource_interface):
118@@ -459,8 +460,18 @@
119 webservice_request = get_current_web_service_request()
120 self.assertEquals("2.0", webservice_request.version)
121 marker_20 = getUtility(IWebServiceVersion, "2.0")
122- marker_20.providedBy(webservice_request)
123-
124+ self.assertTrue(marker_20.providedBy(webservice_request))
125+
126+ # We can use tag_request_with_version_name to change the
127+ # version of a request object.
128+ tag_request_with_version_name(webservice_request, '1.0')
129+ self.assertEquals("1.0", webservice_request.version)
130+ marker_10 = getUtility(IWebServiceVersion, "1.0")
131+ self.assertTrue(marker_10.providedBy(webservice_request))
132+
133+ tag_request_with_version_name(webservice_request, '2.0')
134+ self.assertEquals("2.0", webservice_request.version)
135+ self.assertTrue(marker_20.providedBy(webservice_request))
136
137 def additional_tests():
138 return unittest.TestLoader().loadTestsFromName(__name__)
139
140=== modified file 'src/lazr/restful/utils.py'
141--- src/lazr/restful/utils.py 2010-02-18 15:02:10 +0000
142+++ src/lazr/restful/utils.py 2010-03-02 15:20:33 +0000
143@@ -13,6 +13,7 @@
144 'safe_hasattr',
145 'smartquote',
146 'simple_popen2',
147+ 'tag_request_with_version_name',
148 'VersionedDict',
149 ]
150
151@@ -25,10 +26,12 @@
152
153 from simplejson import encoder
154
155+from zope.component import getUtility
156 from zope.schema import getFieldsInOrder
157-from zope.interface import classImplements
158+from zope.interface import alsoProvides, classImplements
159
160-from lazr.restful.interfaces import IWebServiceClientRequest
161+from lazr.restful.interfaces import (
162+ IWebServiceClientRequest, IWebServiceVersion)
163
164
165 missing = object()
166@@ -236,6 +239,17 @@
167 return None
168 return IWebServiceClientRequest(request)
169
170+
171+def tag_request_with_version_name(request, version):
172+ """Tag a request with a version name and marker interface."""
173+ request.annotations[request.VERSION_ANNOTATION] = version
174+ # Find the version-specific marker interface this request should
175+ # provide, and provide it.
176+ to_provide = getUtility(IWebServiceVersion, name=version)
177+ alsoProvides(request, to_provide)
178+ request.version = version
179+
180+
181 def simple_popen2(command, input, env=None, in_bufsize=1024, out_bufsize=128):
182 """Run a command, give it input on its standard input, and capture its
183 standard output.
184
185=== modified file 'src/lazr/restful/version.txt'
186--- src/lazr/restful/version.txt 2010-02-23 13:26:11 +0000
187+++ src/lazr/restful/version.txt 2010-03-02 15:20:33 +0000
188@@ -1,1 +1,1 @@
189-0.9.21
190+0.9.22

Subscribers

People subscribed via source and target branches