Merge lp:~leonardr/launchpad/multiversion-wadl into lp:launchpad/db-devel
- multiversion-wadl
- Merge into db-devel
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Tim Penhey | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~leonardr/launchpad/multiversion-wadl | ||||
Merge into: | lp:launchpad/db-devel | ||||
Diff against target: |
483 lines (+168/-95) 9 files modified
Makefile (+17/-9) configs/development/launchpad-lazr.conf (+1/-1) configs/testrunner-appserver/launchpad-lazr.conf (+1/-1) configs/testrunner/launchpad-lazr.conf (+1/-1) lib/canonical/launchpad/doc/webapp-publication.txt (+1/-1) lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt (+43/-17) lib/canonical/launchpad/systemhomes.py (+35/-32) lib/lp/code/stories/webservice/xx-branchmergeproposal.txt (+37/-18) utilities/create-lp-wadl.py (+32/-15) |
||||
To merge this branch: | bzr merge lp:~leonardr/launchpad/multiversion-wadl | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gary Poster (community) | Approve | ||
Tim Penhey (community) | release-critical | Approve | |
Review via email: mp+20405@code.launchpad.net |
Commit message
Description of the change
Leonard Richardson (leonardr) wrote : | # |
Tim Penhey (thumper) : | # |
Leonard Richardson (leonardr) wrote : | # |
This needs another review. Two tests failed when I ran the ec2 suite. Both of them were fallout from when I changed the 'api' vhost's root url from "http://
The fix to webapp-
ec2 test is running again and will hopefully come up roses in the morning.
Leonard Richardson (leonardr) wrote : | # |
Incremental diff: http://
Leonard Richardson (leonardr) wrote : | # |
OK, one more. My earlier fix to xx-branchmergep
The problem here is that the web service URLs generated by a browser-initiated request look like "http://
This branch also upgrades the version of lazr.restful used. I'm not 100% sure that this new version of lazr.restful is necessary, and I'm going to do some preliminary tests with the old version before landing.
Incremental diff: http://
Leonard Richardson (leonardr) wrote : | # |
I should mention that I'm still trying to track down a launchpadlib test failure.
Gary Poster (gary) wrote : | # |
r10428 and r10429 approved. I'd like fix_url to be removed eventually, but I'll not worry about it now.
Preview Diff
1 | === modified file 'Makefile' | |||
2 | --- Makefile 2010-02-19 22:02:36 +0000 | |||
3 | +++ Makefile 2010-03-03 00:11:15 +0000 | |||
4 | @@ -28,8 +28,10 @@ | |||
5 | 28 | 28 | ||
6 | 29 | BZR_VERSION_INFO = bzr-version-info.py | 29 | BZR_VERSION_INFO = bzr-version-info.py |
7 | 30 | 30 | ||
10 | 31 | WADL_FILE = lib/canonical/launchpad/apidoc/wadl-$(LPCONFIG).xml | 31 | APIDOC_DIR = lib/canonical/launchpad/apidoc |
11 | 32 | API_INDEX = lib/canonical/launchpad/apidoc/index.html | 32 | WADL_TEMPLATE = $(APIDOC_DIR).tmp/wadl-$(LPCONFIG)-%(version)s.xml |
12 | 33 | DEVEL_WADL_FILE = $(APIDOC_DIR)/wadl-$(LPCONFIG)-devel.xml | ||
13 | 34 | API_INDEX = $(APIDOC_DIR)/index.html | ||
14 | 33 | 35 | ||
15 | 34 | # DO NOT ALTER : this should just build by default | 36 | # DO NOT ALTER : this should just build by default |
16 | 35 | default: inplace | 37 | default: inplace |
17 | @@ -44,12 +46,14 @@ | |||
18 | 44 | hosted_branches: $(PY) | 46 | hosted_branches: $(PY) |
19 | 45 | $(PY) ./utilities/make-dummy-hosted-branches | 47 | $(PY) ./utilities/make-dummy-hosted-branches |
20 | 46 | 48 | ||
24 | 47 | $(WADL_FILE): $(BZR_VERSION_INFO) | 49 | $(DEVEL_WADL_FILE): $(BZR_VERSION_INFO) |
25 | 48 | LPCONFIG=$(LPCONFIG) $(PY) ./utilities/create-lp-wadl.py > $@.tmp | 50 | mkdir $(APIDOC_DIR).tmp |
26 | 49 | mv $@.tmp $@ | 51 | LPCONFIG=$(LPCONFIG) $(PY) ./utilities/create-lp-wadl.py "$(WADL_TEMPLATE)" |
27 | 52 | mv $(APIDOC_DIR).tmp/* $(APIDOC_DIR) | ||
28 | 53 | rmdir $(APIDOC_DIR).tmp | ||
29 | 50 | 54 | ||
32 | 51 | $(API_INDEX): $(WADL_FILE) | 55 | $(API_INDEX): $(DEVEL_WADL_FILE) |
33 | 52 | bin/apiindex $(WADL_FILE) > $@.tmp | 56 | bin/apiindex $(DEVEL_WADL_FILE) > $@.tmp |
34 | 53 | mv $@.tmp $@ | 57 | mv $@.tmp $@ |
35 | 54 | 58 | ||
36 | 55 | apidoc: compile $(API_INDEX) | 59 | apidoc: compile $(API_INDEX) |
37 | @@ -240,7 +244,7 @@ | |||
38 | 240 | $(BZR_VERSION_INFO): | 244 | $(BZR_VERSION_INFO): |
39 | 241 | scripts/update-bzr-version-info.sh | 245 | scripts/update-bzr-version-info.sh |
40 | 242 | 246 | ||
42 | 243 | support_files: $(WADL_FILE) $(BZR_VERSION_INFO) | 247 | support_files: $(DEVEL_WADL_FILE) $(BZR_VERSION_INFO) |
43 | 244 | 248 | ||
44 | 245 | # Intended for use on developer machines | 249 | # Intended for use on developer machines |
45 | 246 | start: inplace stop support_files initscript-start | 250 | start: inplace stop support_files initscript-start |
46 | @@ -309,7 +313,11 @@ | |||
47 | 309 | $(RM) -r lib/mailman | 313 | $(RM) -r lib/mailman |
48 | 310 | $(RM) -rf lib/canonical/launchpad/icing/build/* | 314 | $(RM) -rf lib/canonical/launchpad/icing/build/* |
49 | 311 | $(RM) -r $(CODEHOSTING_ROOT) | 315 | $(RM) -r $(CODEHOSTING_ROOT) |
51 | 312 | $(RM) $(WADL_FILE) $(API_INDEX) | 316 | mv $(APIDOC_DIR)/wadl-testrunner-devel.xml \ |
52 | 317 | $(APIDOC_DIR)/wadl-testrunner-devel.xml.bak | ||
53 | 318 | $(RM) $(APIDOC_DIR)/wadl*.xml $(API_INDEX) | ||
54 | 319 | mv $(APIDOC_DIR)/wadl-testrunner-devel.xml.bak \ | ||
55 | 320 | $(APIDOC_DIR)/wadl-testrunner-devel.xml | ||
56 | 313 | $(RM) $(BZR_VERSION_INFO) | 321 | $(RM) $(BZR_VERSION_INFO) |
57 | 314 | $(RM) _pythonpath.py | 322 | $(RM) _pythonpath.py |
58 | 315 | $(RM) -rf \ | 323 | $(RM) -rf \ |
59 | 316 | 324 | ||
60 | === modified file 'configs/development/launchpad-lazr.conf' | |||
61 | --- configs/development/launchpad-lazr.conf 2010-02-24 05:00:02 +0000 | |||
62 | +++ configs/development/launchpad-lazr.conf 2010-03-03 00:11:15 +0000 | |||
63 | @@ -262,7 +262,7 @@ | |||
64 | 262 | 262 | ||
65 | 263 | [vhost.api] | 263 | [vhost.api] |
66 | 264 | hostname: api.launchpad.dev | 264 | hostname: api.launchpad.dev |
68 | 265 | rooturl: https://api.launchpad.dev/beta/ | 265 | rooturl: https://api.launchpad.dev/ |
69 | 266 | 266 | ||
70 | 267 | [vhost.blueprints] | 267 | [vhost.blueprints] |
71 | 268 | hostname: blueprints.launchpad.dev | 268 | hostname: blueprints.launchpad.dev |
72 | 269 | 269 | ||
73 | === modified file 'configs/testrunner-appserver/launchpad-lazr.conf' | |||
74 | --- configs/testrunner-appserver/launchpad-lazr.conf 2010-02-12 19:34:42 +0000 | |||
75 | +++ configs/testrunner-appserver/launchpad-lazr.conf 2010-03-03 00:11:15 +0000 | |||
76 | @@ -23,7 +23,7 @@ | |||
77 | 23 | rooturl: http://launchpad.dev:8085/ | 23 | rooturl: http://launchpad.dev:8085/ |
78 | 24 | 24 | ||
79 | 25 | [vhost.api] | 25 | [vhost.api] |
81 | 26 | rooturl: http://api.launchpad.dev:8085/beta/ | 26 | rooturl: http://api.launchpad.dev:8085/ |
82 | 27 | 27 | ||
83 | 28 | [vhost.blueprints] | 28 | [vhost.blueprints] |
84 | 29 | rooturl: http://blueprints.launchpad.dev:8085/ | 29 | rooturl: http://blueprints.launchpad.dev:8085/ |
85 | 30 | 30 | ||
86 | === modified file 'configs/testrunner/launchpad-lazr.conf' | |||
87 | --- configs/testrunner/launchpad-lazr.conf 2010-02-24 05:00:02 +0000 | |||
88 | +++ configs/testrunner/launchpad-lazr.conf 2010-03-03 00:11:15 +0000 | |||
89 | @@ -229,7 +229,7 @@ | |||
90 | 229 | rooturl: http://launchpad.dev/ | 229 | rooturl: http://launchpad.dev/ |
91 | 230 | 230 | ||
92 | 231 | [vhost.api] | 231 | [vhost.api] |
94 | 232 | rooturl: http://api.launchpad.dev/beta/ | 232 | rooturl: http://api.launchpad.dev/ |
95 | 233 | 233 | ||
96 | 234 | [vhosts] | 234 | [vhosts] |
97 | 235 | use_https: False | 235 | use_https: False |
98 | 236 | 236 | ||
99 | === renamed file 'lib/canonical/launchpad/apidoc/wadl-testrunner.xml' => 'lib/canonical/launchpad/apidoc/wadl-testrunner-devel.xml' | |||
100 | === modified file 'lib/canonical/launchpad/doc/webapp-publication.txt' | |||
101 | --- lib/canonical/launchpad/doc/webapp-publication.txt 2010-02-12 19:34:42 +0000 | |||
102 | +++ lib/canonical/launchpad/doc/webapp-publication.txt 2010-03-03 00:11:15 +0000 | |||
103 | @@ -38,7 +38,7 @@ | |||
104 | 38 | althosts: | 38 | althosts: |
105 | 39 | ---- | 39 | ---- |
106 | 40 | api @ api.launchpad.dev | 40 | api @ api.launchpad.dev |
108 | 41 | rooturl: http://api.launchpad.dev/beta/ | 41 | rooturl: http://api.launchpad.dev/ |
109 | 42 | althosts: | 42 | althosts: |
110 | 43 | ---- | 43 | ---- |
111 | 44 | blueprints @ blueprints.launchpad.dev | 44 | blueprints @ blueprints.launchpad.dev |
112 | 45 | 45 | ||
113 | === modified file 'lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt' | |||
114 | --- lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt 2009-08-20 04:46:48 +0000 | |||
115 | +++ lib/canonical/launchpad/pagetests/webservice/xx-wadl.txt 2010-03-03 00:11:15 +0000 | |||
116 | @@ -1,16 +1,18 @@ | |||
117 | 1 | = Launchpad's WADL caching = | 1 | = Launchpad's WADL caching = |
118 | 2 | 2 | ||
127 | 3 | Because Launchpad's main WADL file is so big, we cache it internally. | 3 | Because Launchpad's main WADL files are so big, we cache them |
128 | 4 | Because it only changes when the Launchpad software changes, it is | 4 | internally: one WADL file for every version of the web service. |
129 | 5 | cached to a file. Right now, the Launchpad webservice serves a | 5 | Because the WADL only changes when the Launchpad software changes, |
130 | 6 | special test file (canonical/launchpad/apidoc/wadl-testrunner.xml) | 6 | these documents are cached to files. Right now, the Launchpad |
131 | 7 | when a client asks for the big WADL definition. It was loaded on | 7 | webservice serves a special test file |
132 | 8 | module import using the canonical.config.config.instance_name, so a | 8 | (canonical/launchpad/apidoc/wadl-testrunner-devel.xml) when a client |
133 | 9 | development instance will use the file | 9 | asks for the big WADL definition for the 'devel' version. The |
134 | 10 | canonical/launchpad/apidoc/wadl-development.xml. | 10 | 'testrunner' part comes from canonical.config.config.instance_name, so |
135 | 11 | a development instance will use the file | ||
136 | 12 | canonical/launchpad/apidoc/wadl-development-{version}.xml. | ||
137 | 11 | 13 | ||
138 | 12 | >>> test_wadl = webservice.get( | 14 | >>> test_wadl = webservice.get( |
140 | 13 | ... '/', 'application/vd.sun.wadl+xml').body | 15 | ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body |
141 | 14 | >>> print test_wadl | 16 | >>> print test_wadl |
142 | 15 | <?xml version="1.0"?> | 17 | <?xml version="1.0"?> |
143 | 16 | <wadl:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 18 | <wadl:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
144 | @@ -24,15 +26,16 @@ | |||
145 | 24 | </wadl:application> | 26 | </wadl:application> |
146 | 25 | <BLANKLINE> | 27 | <BLANKLINE> |
147 | 26 | 28 | ||
151 | 27 | Let's look at the real contents, though. To do this, we need to do | 29 | Let's look at the real contents, though. To do this, we need to |
152 | 28 | what utilities/create-lp-wadl.py does: clear out the cache on the | 30 | deactivate the cache. Simply clearing it out will just cause it to be |
153 | 29 | class. | 31 | filled up again. |
154 | 30 | 32 | ||
155 | 31 | >>> from canonical.launchpad.systemhomes import WebServiceApplication | 33 | >>> from canonical.launchpad.systemhomes import WebServiceApplication |
156 | 34 | >>> old_cached_wadl = WebServiceApplication.cached_wadl | ||
157 | 32 | >>> WebServiceApplication.cached_wadl = None | 35 | >>> WebServiceApplication.cached_wadl = None |
158 | 33 | 36 | ||
159 | 34 | >>> wadl = webservice.get( | 37 | >>> wadl = webservice.get( |
161 | 35 | ... '/', 'application/vd.sun.wadl+xml').body | 38 | ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body |
162 | 36 | >>> wadl = wadl.decode('UTF-8') | 39 | >>> wadl = wadl.decode('UTF-8') |
163 | 37 | 40 | ||
164 | 38 | The real file is much bigger than the test file. | 41 | The real file is much bigger than the test file. |
165 | @@ -40,15 +43,38 @@ | |||
166 | 40 | >>> len(wadl) > len(test_wadl) | 43 | >>> len(wadl) > len(test_wadl) |
167 | 41 | True | 44 | True |
168 | 42 | 45 | ||
172 | 43 | The new output is now cached on the WebServiceApplication class. | 46 | The WADL we received is keyed to the 'devel' version of the web |
173 | 44 | 47 | service. This version will always be present. | |
174 | 45 | >>> WebServiceApplication.cached_wadl == wadl | 48 | |
175 | 49 | >>> 'http://api.launchpad.dev/devel/' in wadl | ||
176 | 50 | True | ||
177 | 51 | |||
178 | 52 | If we retrieve the WADL for the '1.0' version of the web service, | ||
179 | 53 | we'll get a document keyed to the '1.0' version. The '1.0' version | ||
180 | 54 | will be deprecated along with the Lucid release of Ubuntu. | ||
181 | 55 | |||
182 | 56 | >>> wadl_10 = webservice.get( | ||
183 | 57 | ... '/', 'application/vd.sun.wadl+xml', api_version='1.0').body | ||
184 | 58 | >>> wadl_10 = wadl_10.decode('UTF-8') | ||
185 | 59 | |||
186 | 60 | >>> 'http://api.launchpad.dev/1.0/' in wadl_10 | ||
187 | 61 | True | ||
188 | 62 | |||
189 | 63 | If we retrieve the WADL for the 'beta' version of the web service, | ||
190 | 64 | we'll get a document keyed to the 'beta' version. The '1.0' version | ||
191 | 65 | will be deprecated along with the Karmic release of Ubuntu. | ||
192 | 66 | |||
193 | 67 | >>> wadl_beta = webservice.get( | ||
194 | 68 | ... '/', 'application/vd.sun.wadl+xml', api_version='beta').body | ||
195 | 69 | >>> wadl_beta = wadl_beta.decode('UTF-8') | ||
196 | 70 | |||
197 | 71 | >>> 'http://api.launchpad.dev/beta/' in wadl_beta | ||
198 | 46 | True | 72 | True |
199 | 47 | 73 | ||
200 | 48 | We don't need the cache anymore, so we'll reinstate the testing | 74 | We don't need the cache anymore, so we'll reinstate the testing |
201 | 49 | version. This way, other tests will have a clean slate. | 75 | version. This way, other tests will have a clean slate. |
202 | 50 | 76 | ||
204 | 51 | >>> WebServiceApplication.cached_wadl = test_wadl | 77 | >>> WebServiceApplication.cached_wadl = old_cached_wadl |
205 | 52 | 78 | ||
206 | 53 | Like all lazr.restful applications, Launchpad's web service generates | 79 | Like all lazr.restful applications, Launchpad's web service generates |
207 | 54 | valid WADL. | 80 | valid WADL. |
208 | 55 | 81 | ||
209 | === modified file 'lib/canonical/launchpad/systemhomes.py' | |||
210 | --- lib/canonical/launchpad/systemhomes.py 2010-02-16 14:07:17 +0000 | |||
211 | +++ lib/canonical/launchpad/systemhomes.py 2010-03-03 00:11:15 +0000 | |||
212 | @@ -343,15 +343,8 @@ | |||
213 | 343 | class WebServiceApplication(ServiceRootResource): | 343 | class WebServiceApplication(ServiceRootResource): |
214 | 344 | """See `IWebServiceApplication`. | 344 | """See `IWebServiceApplication`. |
215 | 345 | 345 | ||
225 | 346 | This implementation adds a 'cached_wadl' attribute. If set, it will be | 346 | This implementation adds a 'cached_wadl' attribute, which starts |
226 | 347 | served by `toWADL` rather than calculating the toWADL result. | 347 | out as an empty dict and is populated as needed. |
218 | 348 | |||
219 | 349 | On import, the class tries to load a file to populate this attribute. By | ||
220 | 350 | doing it on import, this makes it easy to clear, as is needed by | ||
221 | 351 | utilities/create-lp-wadl.py. | ||
222 | 352 | |||
223 | 353 | If the attribute is not set, toWADL will set the attribute on the class | ||
224 | 354 | once it is calculated. | ||
227 | 355 | """ | 348 | """ |
228 | 356 | implements(IWebServiceApplication, ICanonicalUrlData) | 349 | implements(IWebServiceApplication, ICanonicalUrlData) |
229 | 357 | 350 | ||
230 | @@ -359,31 +352,41 @@ | |||
231 | 359 | path = '' | 352 | path = '' |
232 | 360 | rootsite = None | 353 | rootsite = None |
233 | 361 | 354 | ||
251 | 362 | _wadl_filename = os.path.join( | 355 | cached_wadl = {} |
235 | 363 | os.path.dirname(os.path.normpath(__file__)), | ||
236 | 364 | 'apidoc', 'wadl-%s.xml' % config.instance_name) | ||
237 | 365 | |||
238 | 366 | cached_wadl = None | ||
239 | 367 | |||
240 | 368 | # Attempt to load the WADL. | ||
241 | 369 | _wadl_fd = None | ||
242 | 370 | try: | ||
243 | 371 | _wadl_fd = codecs.open(_wadl_filename, encoding='UTF-8') | ||
244 | 372 | try: | ||
245 | 373 | cached_wadl = _wadl_fd.read() | ||
246 | 374 | finally: | ||
247 | 375 | _wadl_fd.close() | ||
248 | 376 | except IOError: | ||
249 | 377 | pass | ||
250 | 378 | del _wadl_fd | ||
252 | 379 | 356 | ||
253 | 380 | def toWADL(self): | 357 | def toWADL(self): |
260 | 381 | """See `IWebServiceApplication`.""" | 358 | """See `IWebServiceApplication`. |
261 | 382 | if self.cached_wadl is not None: | 359 | |
262 | 383 | return self.cached_wadl | 360 | Look for a cached WADL file for the request version at the |
263 | 384 | wadl = super(WebServiceApplication, self).toWADL() | 361 | location used by the script |
264 | 385 | self.__class__.cached_wadl = wadl | 362 | utilities/create-launchpad-wadl.py. If the file is present, |
265 | 386 | return wadl | 363 | load the file and cache its contents rather than generating |
266 | 364 | new WADL. Otherwise, generate new WADL and cache it. | ||
267 | 365 | """ | ||
268 | 366 | version = self.request.version | ||
269 | 367 | if self.__class__.cached_wadl is None: | ||
270 | 368 | # The cache has been disabled for testing | ||
271 | 369 | # purposes. Generate the WADL. | ||
272 | 370 | return super(WebServiceApplication, self).toWADL() | ||
273 | 371 | if version not in self.__class__.cached_wadl: | ||
274 | 372 | # It's not cached. Look for it on disk. | ||
275 | 373 | _wadl_filename = os.path.join( | ||
276 | 374 | os.path.dirname(os.path.normpath(__file__)), | ||
277 | 375 | 'apidoc', 'wadl-%s-%s.xml' % (config.instance_name, version)) | ||
278 | 376 | |||
279 | 377 | _wadl_fd = None | ||
280 | 378 | try: | ||
281 | 379 | _wadl_fd = codecs.open(_wadl_filename, encoding='UTF-8') | ||
282 | 380 | try: | ||
283 | 381 | wadl = _wadl_fd.read() | ||
284 | 382 | finally: | ||
285 | 383 | _wadl_fd.close() | ||
286 | 384 | except IOError: | ||
287 | 385 | # It's not on disk; generate it. | ||
288 | 386 | wadl = super(WebServiceApplication, self).toWADL() | ||
289 | 387 | del _wadl_fd | ||
290 | 388 | self.__class__.cached_wadl[version] = wadl | ||
291 | 389 | return self.__class__.cached_wadl[version] | ||
292 | 387 | 390 | ||
293 | 388 | 391 | ||
294 | 389 | class TestOpenIDApplication: | 392 | class TestOpenIDApplication: |
295 | 390 | 393 | ||
296 | === modified file 'lib/lp/code/stories/webservice/xx-branchmergeproposal.txt' | |||
297 | --- lib/lp/code/stories/webservice/xx-branchmergeproposal.txt 2010-02-26 09:54:20 +0000 | |||
298 | +++ lib/lp/code/stories/webservice/xx-branchmergeproposal.txt 2010-03-03 00:11:15 +0000 | |||
299 | @@ -7,13 +7,31 @@ | |||
300 | 7 | >>> from lazr.restful.testing.webservice import pprint_entry | 7 | >>> from lazr.restful.testing.webservice import pprint_entry |
301 | 8 | >>> login('admin@canonical.com') | 8 | >>> login('admin@canonical.com') |
302 | 9 | >>> target = factory.makeBranch() | 9 | >>> target = factory.makeBranch() |
304 | 10 | >>> target_url = str(canonical_url(target, rootsite='api')) | 10 | |
305 | 11 | >>> from canonical.launchpad.webapp.servers import WebServiceTestRequest | ||
306 | 12 | >>> request = WebServiceTestRequest(version="beta") | ||
307 | 13 | >>> request.processInputs() | ||
308 | 14 | |||
309 | 15 | >>> from lazr.restful.utils import get_current_web_service_request | ||
310 | 16 | >>> request = get_current_web_service_request() | ||
311 | 17 | |||
312 | 18 | >>> def fix_url(url): | ||
313 | 19 | ... """Convert a browser request to a web service client request. | ||
314 | 20 | ... This is a bit of a hack, but it's the simplest way to get a | ||
315 | 21 | ... URL that the web service client will respect.""" | ||
316 | 22 | ... return url.replace("launchpad.dev/api/", "api.launchpad.dev/") | ||
317 | 23 | |||
318 | 24 | >>> target_url = fix_url(str(canonical_url( | ||
319 | 25 | ... target, request=request, rootsite='api'))) | ||
320 | 11 | >>> source = factory.makeBranchTargetBranch(target.target) | 26 | >>> source = factory.makeBranchTargetBranch(target.target) |
322 | 12 | >>> source_url = str(canonical_url(source, rootsite='api')) | 27 | >>> source_url = fix_url(str( |
323 | 28 | ... canonical_url(source, request=request, rootsite='api'))) | ||
324 | 13 | >>> prerequisite = factory.makeBranchTargetBranch(target.target) | 29 | >>> prerequisite = factory.makeBranchTargetBranch(target.target) |
326 | 14 | >>> prerequisite_url = canonical_url(prerequisite, rootsite='api') | 30 | >>> prerequisite_url = fix_url(str(canonical_url( |
327 | 31 | ... prerequisite, request=request, rootsite='api'))) | ||
328 | 15 | >>> registrant = source.registrant | 32 | >>> registrant = source.registrant |
330 | 16 | >>> reviewer_url = canonical_url(factory.makePerson(), rootsite='api') | 33 | >>> reviewer_url = fix_url(str(canonical_url( |
331 | 34 | ... factory.makePerson(), request=request, rootsite='api'))) | ||
332 | 17 | >>> logout() | 35 | >>> logout() |
333 | 18 | >>> registrant_webservice = webservice_for_person( | 36 | >>> registrant_webservice = webservice_for_person( |
334 | 19 | ... registrant, permission=OAuthPermission.WRITE_PUBLIC) | 37 | ... registrant, permission=OAuthPermission.WRITE_PUBLIC) |
335 | @@ -28,7 +46,7 @@ | |||
336 | 28 | >>> pprint_entry(bmp) | 46 | >>> pprint_entry(bmp) |
337 | 29 | address: u'mp+...@code.launchpad.dev' | 47 | address: u'mp+...@code.launchpad.dev' |
338 | 30 | all_comments_collection_link: | 48 | all_comments_collection_link: |
340 | 31 | u'http://api.launchpad.dev/beta/~.../+merge/.../all_comments' | 49 | u'http://api.launchpad.dev/devel/~.../+merge/.../all_comments' |
341 | 32 | commit_message: u'It was merged!\n' | 50 | commit_message: u'It was merged!\n' |
342 | 33 | date_created: u'...' | 51 | date_created: u'...' |
343 | 34 | date_merged: None | 52 | date_merged: None |
344 | @@ -38,40 +56,40 @@ | |||
345 | 38 | description: u'Merge\nit!' | 56 | description: u'Merge\nit!' |
346 | 39 | merge_reporter_link: None | 57 | merge_reporter_link: None |
347 | 40 | merged_revno: None | 58 | merged_revno: None |
349 | 41 | prerequisite_branch_link: u'http://api.launchpad.dev/beta/~...' | 59 | prerequisite_branch_link: u'http://api.launchpad.dev/devel/~...' |
350 | 42 | preview_diff_link: None | 60 | preview_diff_link: None |
351 | 43 | private: False | 61 | private: False |
352 | 44 | queue_position: None | 62 | queue_position: None |
353 | 45 | queue_status: u'Needs review' | 63 | queue_status: u'Needs review' |
354 | 46 | queued_revid: None | 64 | queued_revid: None |
355 | 47 | queuer_link: None | 65 | queuer_link: None |
357 | 48 | registrant_link: u'http://api.launchpad.dev/beta/~person-name...' | 66 | registrant_link: u'http://api.launchpad.dev/devel/~person-name...' |
358 | 49 | resource_type_link: | 67 | resource_type_link: |
360 | 50 | u'http://api.launchpad.dev/beta/#branch_merge_proposal' | 68 | u'http://api.launchpad.dev/devel/#branch_merge_proposal' |
361 | 51 | reviewed_revid: None | 69 | reviewed_revid: None |
362 | 52 | reviewer_link: None | 70 | reviewer_link: None |
365 | 53 | self_link: u'http://api.launchpad.dev/beta/~.../+merge/...' | 71 | self_link: u'http://api.launchpad.dev/devel/~.../+merge/...' |
366 | 54 | source_branch_link: u'http://api.launchpad.dev/beta/~...' | 72 | source_branch_link: u'http://api.launchpad.dev/devel/~...' |
367 | 55 | superseded_by_link: None | 73 | superseded_by_link: None |
368 | 56 | supersedes_link: None | 74 | supersedes_link: None |
370 | 57 | target_branch_link: u'http://api.launchpad.dev/beta/~...' | 75 | target_branch_link: u'http://api.launchpad.dev/devel/~...' |
371 | 58 | votes_collection_link: | 76 | votes_collection_link: |
373 | 59 | u'http://api.launchpad.dev/beta/~.../+merge/.../votes' | 77 | u'http://api.launchpad.dev/devel/~.../+merge/.../votes' |
374 | 60 | 78 | ||
375 | 61 | Our review request is listed in the votes collection. | 79 | Our review request is listed in the votes collection. |
376 | 62 | 80 | ||
377 | 63 | >>> votes = webservice.get( | 81 | >>> votes = webservice.get( |
378 | 64 | ... bmp['votes_collection_link']).jsonBody() | 82 | ... bmp['votes_collection_link']).jsonBody() |
379 | 65 | >>> pprint_entry(votes['entries'][0]) | 83 | >>> pprint_entry(votes['entries'][0]) |
381 | 66 | branch_merge_proposal_link: u'http://api.launchpad.dev/beta/~.../+merge/...' | 84 | branch_merge_proposal_link: u'http://api.launchpad.dev/devel/~.../+merge/...' |
382 | 67 | comment_link: None | 85 | comment_link: None |
383 | 68 | date_created: u'...' | 86 | date_created: u'...' |
384 | 69 | is_pending: True | 87 | is_pending: True |
387 | 70 | registrant_link: u'http://api.launchpad.dev/beta/~person-name...' | 88 | registrant_link: u'http://api.launchpad.dev/devel/~person-name...' |
388 | 71 | resource_type_link: u'http://api.launchpad.dev/beta/#code_review_vote_reference' | 89 | resource_type_link: u'http://api.launchpad.dev/devel/#code_review_vote_reference' |
389 | 72 | review_type: u'green' | 90 | review_type: u'green' |
392 | 73 | reviewer_link: u'http://api.launchpad.dev/beta/~person-name...' | 91 | reviewer_link: u'http://api.launchpad.dev/devel/~person-name...' |
393 | 74 | self_link: u'http://api.launchpad.dev/beta/~...' | 92 | self_link: u'http://api.launchpad.dev/devel/~...' |
394 | 75 | 93 | ||
395 | 76 | 94 | ||
396 | 77 | == Get an existing merge proposal == | 95 | == Get an existing merge proposal == |
397 | @@ -96,7 +114,8 @@ | |||
398 | 96 | ... vote=CodeReviewVote.ABSTAIN, parent=comment, | 114 | ... vote=CodeReviewVote.ABSTAIN, parent=comment, |
399 | 97 | ... merge_proposal=fixit_proposal) | 115 | ... merge_proposal=fixit_proposal) |
400 | 98 | 116 | ||
402 | 99 | >>> proposal_url = canonical_url(fixit_proposal, rootsite='api') | 117 | >>> proposal_url = fix_url(canonical_url( |
403 | 118 | ... fixit_proposal, request=request, rootsite='api')) | ||
404 | 100 | >>> new_person = factory.makePerson() | 119 | >>> new_person = factory.makePerson() |
405 | 101 | >>> target_owner = fixit_proposal.target_branch.owner | 120 | >>> target_owner = fixit_proposal.target_branch.owner |
406 | 102 | >>> logout() | 121 | >>> logout() |
407 | 103 | 122 | ||
408 | === modified file 'utilities/create-lp-wadl.py' | |||
409 | --- utilities/create-lp-wadl.py 2009-10-17 14:06:03 +0000 | |||
410 | +++ utilities/create-lp-wadl.py 2010-03-03 00:11:15 +0000 | |||
411 | @@ -7,12 +7,15 @@ | |||
412 | 7 | 7 | ||
413 | 8 | Usage hint: | 8 | Usage hint: |
414 | 9 | 9 | ||
416 | 10 | % LPCONFIG="edge" utilities/create-lp-wadl.py > launchpad.wadl | 10 | % LPCONFIG="edge" utilities/create-lp-wadl.py launchpad-%(version)s.wadl |
417 | 11 | """ | 11 | """ |
418 | 12 | 12 | ||
419 | 13 | import _pythonpath | 13 | import _pythonpath |
420 | 14 | 14 | ||
421 | 15 | import sys | 15 | import sys |
422 | 16 | import urlparse | ||
423 | 17 | |||
424 | 18 | from zope.component import getUtility | ||
425 | 16 | 19 | ||
426 | 17 | from canonical.launchpad.ftests import login, ANONYMOUS | 20 | from canonical.launchpad.ftests import login, ANONYMOUS |
427 | 18 | from canonical.launchpad.scripts import execute_zcml_for_scripts | 21 | from canonical.launchpad.scripts import execute_zcml_for_scripts |
428 | @@ -20,27 +23,41 @@ | |||
429 | 20 | WebServicePublication, WebServiceTestRequest) | 23 | WebServicePublication, WebServiceTestRequest) |
430 | 21 | from canonical.launchpad.webapp.vhosts import allvhosts | 24 | from canonical.launchpad.webapp.vhosts import allvhosts |
431 | 22 | from canonical.launchpad.systemhomes import WebServiceApplication | 25 | from canonical.launchpad.systemhomes import WebServiceApplication |
432 | 26 | from lazr.restful.interfaces import IWebServiceConfiguration | ||
433 | 23 | 27 | ||
435 | 24 | def main(): | 28 | def main(path_template): |
436 | 25 | WebServiceApplication.cached_wadl = None # do not use cached file version | 29 | WebServiceApplication.cached_wadl = None # do not use cached file version |
437 | 26 | execute_zcml_for_scripts() | 30 | execute_zcml_for_scripts() |
438 | 31 | config = getUtility(IWebServiceConfiguration) | ||
439 | 27 | 32 | ||
440 | 28 | # Request the WADL from the root resource. | 33 | # Request the WADL from the root resource. |
441 | 29 | # We do this by creating a request object asking for a WADL | 34 | # We do this by creating a request object asking for a WADL |
442 | 30 | # representation. | 35 | # representation. |
455 | 31 | request = WebServiceTestRequest(environ={ | 36 | for version in config.active_versions: |
456 | 32 | 'SERVER_URL': allvhosts.configs['api'].rooturl, | 37 | url = urlparse.urljoin(allvhosts.configs['api'].rooturl, version) |
457 | 33 | 'HTTP_HOST': allvhosts.configs['api'].hostname, | 38 | request = WebServiceTestRequest(version=version, environ={ |
458 | 34 | 'HTTP_ACCEPT': 'application/vd.sun.wadl+xml' | 39 | 'SERVER_URL': url, |
459 | 35 | }) | 40 | 'HTTP_HOST': allvhosts.configs['api'].hostname, |
460 | 36 | # We then bypass the usual publisher processing by associating | 41 | 'HTTP_ACCEPT': 'application/vd.sun.wadl+xml' |
461 | 37 | # the request with the WebServicePublication (usually done by the | 42 | }) |
462 | 38 | # publisher) and then calling the root resource - retrieved through | 43 | # We then bypass the usual publisher processing by associating |
463 | 39 | # getApplication(). | 44 | # the request with the WebServicePublication (usually done by the |
464 | 40 | request.setPublication(WebServicePublication(None)) | 45 | # publisher) and then calling the root resource - retrieved through |
465 | 41 | login(ANONYMOUS, request) | 46 | # getApplication(). |
466 | 42 | print request.publication.getApplication(request)(request) | 47 | request.setPublication(WebServicePublication(None)) |
467 | 48 | login(ANONYMOUS, request) | ||
468 | 49 | filename = path_template % {'version' : version} | ||
469 | 50 | print "Writing WADL for version %s to %s." % (version, filename) | ||
470 | 51 | f = open(filename, 'w') | ||
471 | 52 | content = request.publication.getApplication(request)(request) | ||
472 | 53 | f.write(content) | ||
473 | 54 | f.close() | ||
474 | 43 | return 0 | 55 | return 0 |
475 | 44 | 56 | ||
476 | 45 | if __name__ == '__main__': | 57 | if __name__ == '__main__': |
478 | 46 | sys.exit(main()) | 58 | if len(sys.argv) != 2: |
479 | 59 | print "Usage: %s [WADL path template]" % sys.argv[0] | ||
480 | 60 | print " Example: %s path/to/wadl/wadl-%%(version).xml" % ( | ||
481 | 61 | sys.argv[0]) | ||
482 | 62 | sys.exit(-1) | ||
483 | 63 | sys.exit(main(sys.argv[1])) |
This branch changes the build process so that it generates a static WADL file for every version of the web service, not just one file. There were a number of parts of this system that I didn't understand and might not be necessary anymore (mainly the fake 'development' WADL file, which only seems to get in the way), but I left them alone rather than make this branch more complex.