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
=== modified file 'src/lazr/restful/NEWS.txt'
--- src/lazr/restful/NEWS.txt 2010-02-23 19:07:23 +0000
+++ src/lazr/restful/NEWS.txt 2010-03-02 15:20:33 +0000
@@ -2,6 +2,7 @@
2NEWS for lazr.restful2NEWS for lazr.restful
3=====================3=====================
44
5<<<<<<< TREE
5Development6Development
6===========7===========
78
@@ -15,6 +16,14 @@
15your web service in the "last_version_with_named_mutator_operations"16your web service in the "last_version_with_named_mutator_operations"
16field of your IWebServiceConfiguration implementation.17field of your IWebServiceConfiguration implementation.
1718
19=======
200.9.22 (2010-03-02)
21===================
22
23Refactored the code that tags request objects with version
24information, so that tagging would happen consistently.
25
26>>>>>>> MERGE-SOURCE
180.9.21 (2010-02-23)270.9.21 (2010-02-23)
19===================28===================
2029
2130
=== modified file 'src/lazr/restful/docs/webservice-request.txt'
--- src/lazr/restful/docs/webservice-request.txt 2009-11-12 19:08:10 +0000
+++ src/lazr/restful/docs/webservice-request.txt 2010-03-02 15:20:33 +0000
@@ -29,8 +29,13 @@
29 ... request.setPublication(WebServiceTestPublication(None))29 ... request.setPublication(WebServiceTestPublication(None))
30 ... return request30 ... return request
3131
32 >>> from lazr.restful.interfaces import IWebServiceVersion
33 >>> class IBetaVersion(IWebServiceVersion):
34 ... """Marker interface for web service version."""
35
32 >>> sm = getSiteManager()36 >>> sm = getSiteManager()
33 >>> sm.registerUtility(SimpleWebServiceConfiguration())37 >>> sm.registerUtility(SimpleWebServiceConfiguration())
38 >>> sm.registerUtility(IBetaVersion, IWebServiceVersion, name="beta")
34 >>> sm.registerAdapter(browser_request_to_web_service_request)39 >>> sm.registerAdapter(browser_request_to_web_service_request)
3540
36 >>> website_request = TestRequest(SERVER_URL="http://cookbooks.dev/")41 >>> website_request = TestRequest(SERVER_URL="http://cookbooks.dev/")
3742
=== modified file 'src/lazr/restful/publisher.py'
--- src/lazr/restful/publisher.py 2010-02-11 17:57:16 +0000
+++ src/lazr/restful/publisher.py 2010-03-02 15:20:33 +0000
@@ -36,6 +36,7 @@
36 IByteStorage, ICollection, ICollectionField, IEntry, IEntryField,36 IByteStorage, ICollection, ICollectionField, IEntry, IEntryField,
37 IHTTPResource, IServiceRootResource, IWebBrowserInitiatedRequest,37 IHTTPResource, IServiceRootResource, IWebBrowserInitiatedRequest,
38 IWebServiceClientRequest, IWebServiceConfiguration, IWebServiceVersion)38 IWebServiceClientRequest, IWebServiceConfiguration, IWebServiceVersion)
39from lazr.restful.utils import tag_request_with_version_name
3940
4041
41class WebServicePublicationMixin:42class WebServicePublicationMixin:
@@ -253,13 +254,7 @@
253 break254 break
254 if version is None:255 if version is None:
255 raise NotFound(self, '', self)256 raise NotFound(self, '', self)
256 self.annotations[self.VERSION_ANNOTATION] = version257 tag_request_with_version_name(self, version)
257
258 # Find the version-specific interface this request should
259 # provide, and provide it.
260 to_provide = getUtility(IWebServiceVersion, name=version)
261 alsoProvides(self, to_provide)
262 self.version = version
263258
264 # Find the appropriate service root for this version and set259 # Find the appropriate service root for this version and set
265 # the publication's application appropriately.260 # the publication's application appropriately.
@@ -309,7 +304,6 @@
309 web_service_request = config.createRequest(body, environ)304 web_service_request = config.createRequest(body, environ)
310 web_service_request.setVirtualHostRoot(305 web_service_request.setVirtualHostRoot(
311 names=[config.path_override, web_service_version])306 names=[config.path_override, web_service_version])
312 web_service_request.annotations[web_service_request.VERSION_ANNOTATION] = (307 tag_request_with_version_name(web_service_request, web_service_version)
313 web_service_request)
314 web_service_request._vh_root = website_request.getVirtualHostRoot()308 web_service_request._vh_root = website_request.getVirtualHostRoot()
315 return web_service_request309 return web_service_request
316310
=== modified file 'src/lazr/restful/testing/webservice.py'
--- src/lazr/restful/testing/webservice.py 2010-02-11 17:57:16 +0000
+++ src/lazr/restful/testing/webservice.py 2010-03-02 15:20:33 +0000
@@ -118,6 +118,7 @@
118 self.query_string_params = {}118 self.query_string_params = {}
119 self.method = 'GET'119 self.method = 'GET'
120120
121
121 def getTraversalStack(self):122 def getTraversalStack(self):
122 """See `IPublicationRequest`.123 """See `IPublicationRequest`.
123124
124125
=== modified file 'src/lazr/restful/tests/test_utils.py'
--- src/lazr/restful/tests/test_utils.py 2010-02-18 15:23:59 +0000
+++ src/lazr/restful/tests/test_utils.py 2010-03-02 15:20:33 +0000
@@ -29,4 +29,5 @@
29 endInteraction()29 endInteraction()
3030
31 # For the sake of convenience, test_get_current_web_service_request()31 # For the sake of convenience, test_get_current_web_service_request()
32 # is tested in test_webservice.py.32 # and tag_request_with_version_name() are tested in test_webservice.py.
33
3334
=== modified file 'src/lazr/restful/tests/test_webservice.py'
--- src/lazr/restful/tests/test_webservice.py 2010-02-25 17:07:16 +0000
+++ src/lazr/restful/tests/test_webservice.py 2010-03-02 15:20:33 +0000
@@ -36,7 +36,8 @@
36 create_web_service_request, WebServiceTestPublication)36 create_web_service_request, WebServiceTestPublication)
37from lazr.restful.testing.tales import test_tales37from lazr.restful.testing.tales import test_tales
38from lazr.restful.utils import (38from lazr.restful.utils import (
39 get_current_browser_request, get_current_web_service_request)39 get_current_browser_request, get_current_web_service_request,
40 tag_request_with_version_name)
4041
4142
42def get_resource_factory(model_interface, resource_interface):43def get_resource_factory(model_interface, resource_interface):
@@ -459,8 +460,18 @@
459 webservice_request = get_current_web_service_request()460 webservice_request = get_current_web_service_request()
460 self.assertEquals("2.0", webservice_request.version)461 self.assertEquals("2.0", webservice_request.version)
461 marker_20 = getUtility(IWebServiceVersion, "2.0")462 marker_20 = getUtility(IWebServiceVersion, "2.0")
462 marker_20.providedBy(webservice_request)463 self.assertTrue(marker_20.providedBy(webservice_request))
463464
465 # We can use tag_request_with_version_name to change the
466 # version of a request object.
467 tag_request_with_version_name(webservice_request, '1.0')
468 self.assertEquals("1.0", webservice_request.version)
469 marker_10 = getUtility(IWebServiceVersion, "1.0")
470 self.assertTrue(marker_10.providedBy(webservice_request))
471
472 tag_request_with_version_name(webservice_request, '2.0')
473 self.assertEquals("2.0", webservice_request.version)
474 self.assertTrue(marker_20.providedBy(webservice_request))
464475
465def additional_tests():476def additional_tests():
466 return unittest.TestLoader().loadTestsFromName(__name__)477 return unittest.TestLoader().loadTestsFromName(__name__)
467478
=== modified file 'src/lazr/restful/utils.py'
--- src/lazr/restful/utils.py 2010-02-18 15:02:10 +0000
+++ src/lazr/restful/utils.py 2010-03-02 15:20:33 +0000
@@ -13,6 +13,7 @@
13 'safe_hasattr',13 'safe_hasattr',
14 'smartquote',14 'smartquote',
15 'simple_popen2',15 'simple_popen2',
16 'tag_request_with_version_name',
16 'VersionedDict',17 'VersionedDict',
17 ]18 ]
1819
@@ -25,10 +26,12 @@
2526
26from simplejson import encoder27from simplejson import encoder
2728
29from zope.component import getUtility
28from zope.schema import getFieldsInOrder30from zope.schema import getFieldsInOrder
29from zope.interface import classImplements31from zope.interface import alsoProvides, classImplements
3032
31from lazr.restful.interfaces import IWebServiceClientRequest33from lazr.restful.interfaces import (
34 IWebServiceClientRequest, IWebServiceVersion)
3235
3336
34missing = object()37missing = object()
@@ -236,6 +239,17 @@
236 return None239 return None
237 return IWebServiceClientRequest(request)240 return IWebServiceClientRequest(request)
238241
242
243def tag_request_with_version_name(request, version):
244 """Tag a request with a version name and marker interface."""
245 request.annotations[request.VERSION_ANNOTATION] = version
246 # Find the version-specific marker interface this request should
247 # provide, and provide it.
248 to_provide = getUtility(IWebServiceVersion, name=version)
249 alsoProvides(request, to_provide)
250 request.version = version
251
252
239def simple_popen2(command, input, env=None, in_bufsize=1024, out_bufsize=128):253def simple_popen2(command, input, env=None, in_bufsize=1024, out_bufsize=128):
240 """Run a command, give it input on its standard input, and capture its254 """Run a command, give it input on its standard input, and capture its
241 standard output.255 standard output.
242256
=== modified file 'src/lazr/restful/version.txt'
--- src/lazr/restful/version.txt 2010-02-23 13:26:11 +0000
+++ src/lazr/restful/version.txt 2010-03-02 15:20:33 +0000
@@ -1,1 +1,1 @@
10.9.2110.9.22

Subscribers

People subscribed via source and target branches