Merge lp:~terrycojones/txfluiddb/perms-Dec-2009 into lp:txfluiddb
- perms-Dec-2009
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Tristan Seligmann |
Approved revision: | not available |
Merged at revision: | 6 |
Proposed branch: | lp:~terrycojones/txfluiddb/perms-Dec-2009 |
Merge into: | lp:txfluiddb |
Diff against target: |
710 lines (+273/-62) 3 files modified
txfluiddb/client.py (+60/-11) txfluiddb/http.py (+3/-1) txfluiddb/test/test_client.py (+210/-50) |
To merge this branch: | bzr merge lp:~terrycojones/txfluiddb/perms-Dec-2009 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tristan Seligmann | Needs Fixing | ||
Review via email: mp+17545@code.launchpad.net |
Commit message
Description of the change
Terry Jones (terrycojones) wrote : | # |
Tristan Seligmann (mithrandi) wrote : | # |
> 36 + components.
> 37 + self.components)
I'd write this as:
components.
components.
We're supposed to be applying the Twisted coding standard; could you ensure all of the code you changed has three empty lines between classes, and two empty lines between functions / methods? There are various places that look like they need some additional empty lines, while class TagValueTests seems to have an extra empty line before it.
There are two pyflakes warnings, one of which was probably introduced in your previous branch, but I only noticed now:
http.py:11: 'log' imported but unused
test/test_
Aside from those issues, this all looks good; I like the test coverage, and I assume the semantics are correct given who wrote the code ;)
- 8. By Terry Jones
-
Cleanup following Tristan review: consistent whitespace between classes and methods/funcs, pyflakes warnings fixed, clearer/simple treatment of path in _HasPath.getURL
Preview Diff
1 | === modified file 'txfluiddb/client.py' |
2 | --- txfluiddb/client.py 2010-01-17 11:25:03 +0000 |
3 | +++ txfluiddb/client.py 2010-01-17 19:12:17 +0000 |
4 | @@ -9,6 +9,7 @@ |
5 | from txfluiddb.http import getPage |
6 | |
7 | |
8 | + |
9 | class _HasPath(object): |
10 | """ |
11 | Base class for FluidDB identifiers composed of path components. |
12 | @@ -68,7 +69,7 @@ |
13 | return u'/'.join(self.components) |
14 | |
15 | |
16 | - def getURL(self, endpoint, prefix=None, suffix=[]): |
17 | + def getURL(self, endpoint, prefix=None, suffix=None, collectionName=None): |
18 | """ |
19 | Get the URL for this path as accessed through the given endpoint. |
20 | |
21 | @@ -81,6 +82,9 @@ |
22 | @type suffix: C{list} of C{unicode} |
23 | @param suffix: A list of components to append after this path. |
24 | |
25 | + @type collectionName: C{unicode} |
26 | + @param suffix: A collectionName to use instead of self.collectionName. |
27 | + |
28 | @rtype: C{str} |
29 | """ |
30 | if self.collectionName is None: |
31 | @@ -88,22 +92,41 @@ |
32 | 'Must override collectionName on _HasPath subclasses') |
33 | |
34 | components = [] |
35 | - if prefix is None: |
36 | - components.append(self.collectionName) |
37 | - else: |
38 | + if prefix: |
39 | components.extend(prefix) |
40 | - # Should self.collectionName be appended here? Or is a passed |
41 | - # prefix supposed to take the place of the collection name? |
42 | + components.append(collectionName or self.collectionName) |
43 | components.extend(self.components) |
44 | - components.extend(suffix) |
45 | + if suffix: |
46 | + components.extend(suffix) |
47 | |
48 | components = [quote(component.encode('utf-8'), safe='') |
49 | for component in components] |
50 | return endpoint.getRootURL() + '/'.join(components) |
51 | |
52 | |
53 | - |
54 | -class Namespace(_HasPath): |
55 | +class _HasPerms(object): |
56 | + """ |
57 | + Mixin base class for FluidDB elements that have permissions. |
58 | + """ |
59 | + |
60 | + |
61 | + def getPerms(self, endpoint, action): |
62 | + url = self.getURL(endpoint, |
63 | + prefix=[u'permissions']) + '?action=%s' % action |
64 | + d = endpoint.submit(url=url, method='GET') |
65 | + return d.addCallback(lambda res: (res[u'policy'], res[u'exceptions'])) |
66 | + |
67 | + |
68 | + def setPerms(self, endpoint, action, policy, exceptions): |
69 | + return endpoint.submit( |
70 | + url=self.getURL(endpoint, |
71 | + prefix=[u'permissions']) + '?action=%s' % action, |
72 | + method='PUT', |
73 | + data={u'policy' : policy, u'exceptions' : exceptions }) |
74 | + |
75 | + |
76 | + |
77 | +class Namespace(_HasPath, _HasPerms): |
78 | """ |
79 | Representation of a FluidDB namespace. |
80 | """ |
81 | @@ -141,6 +164,21 @@ |
82 | return Tag(*path) |
83 | |
84 | |
85 | + def tagValues(self, name): |
86 | + """ |
87 | + Get the tag values. |
88 | + |
89 | + @type name: C{unicode} |
90 | + @param name: The name of the tag. |
91 | + |
92 | + @rtype: L{Tag} |
93 | + @return: A TagValues object for the tag with the given name. |
94 | + """ |
95 | + path = list(self.components) |
96 | + path.append(name) |
97 | + return TagValues(*path) |
98 | + |
99 | + |
100 | def getDescription(self, endpoint): |
101 | """ |
102 | Get a description of the namespace. |
103 | @@ -258,7 +296,7 @@ |
104 | @return: The newly-created tag. |
105 | """ |
106 | self.checkComponent(name) |
107 | - return endpoint.submit(url=self.getURL(endpoint, ['tags']), |
108 | + return endpoint.submit(url=self.getURL(endpoint, collectionName='tags'), |
109 | method='POST', |
110 | data={u'name': name, |
111 | u'description': description, |
112 | @@ -279,7 +317,7 @@ |
113 | |
114 | |
115 | |
116 | -class Tag(_HasPath): |
117 | +class Tag(_HasPath, _HasPerms): |
118 | """ |
119 | Representation of a FluidDB tag. |
120 | """ |
121 | @@ -332,6 +370,14 @@ |
122 | |
123 | |
124 | |
125 | +class TagValues(_HasPath, _HasPerms): |
126 | + """ |
127 | + Representation of the set of values of a tag. |
128 | + """ |
129 | + collectionName = u'tag-values' |
130 | + |
131 | + |
132 | + |
133 | class BasicCreds(object): |
134 | """ |
135 | Credentials for HTTP Basic Authentication. |
136 | @@ -346,6 +392,7 @@ |
137 | self.username = username |
138 | self.password = password |
139 | |
140 | + |
141 | def encode(self): |
142 | """ |
143 | Encode these credentials. |
144 | @@ -362,6 +409,7 @@ |
145 | PRIMITIVE_CONTENT_TYPE = 'application/vnd.fluiddb.value+json' |
146 | |
147 | |
148 | + |
149 | class Endpoint(object): |
150 | """ |
151 | A FluidDB endpoint. |
152 | @@ -505,6 +553,7 @@ |
153 | return d.addCallback(_parse) |
154 | |
155 | |
156 | + |
157 | class Object(_HasPath): |
158 | """ |
159 | A FluidDB object. |
160 | |
161 | === modified file 'txfluiddb/http.py' |
162 | --- txfluiddb/http.py 2010-01-17 11:25:03 +0000 |
163 | +++ txfluiddb/http.py 2010-01-17 19:12:17 +0000 |
164 | @@ -8,10 +8,10 @@ |
165 | FluidDB returns a 204 in various cases.""" |
166 | |
167 | from twisted.internet import reactor |
168 | -from twisted.python import log |
169 | from twisted.web import client, error |
170 | |
171 | |
172 | + |
173 | class HTTPError(error.Error): |
174 | def __init__(self, code, message=None, response=None, |
175 | response_headers=None): |
176 | @@ -19,10 +19,12 @@ |
177 | self.response_headers = response_headers |
178 | |
179 | |
180 | + |
181 | class HTTPPageGetter(client.HTTPPageGetter): |
182 | handleStatus_204 = lambda self: self.handleStatus_200() |
183 | |
184 | |
185 | + |
186 | class HTTPClientFactory(client.HTTPClientFactory): |
187 | protocol = HTTPPageGetter |
188 | |
189 | |
190 | === modified file 'txfluiddb/test/test_client.py' |
191 | --- txfluiddb/test/test_client.py 2009-10-18 01:44:44 +0000 |
192 | +++ txfluiddb/test/test_client.py 2010-01-17 19:12:17 +0000 |
193 | @@ -18,7 +18,7 @@ |
194 | L{_HasPath.getURL} raises C{NotImplementedError} if C{collectionName} |
195 | is not overridden. |
196 | """ |
197 | - endpoint = Endpoint('http://fluiddb.test.url/') |
198 | + endpoint = Endpoint('http://fluiddb.url/') |
199 | path = _HasPath(u'foo') |
200 | self.assertRaises(NotImplementedError, path.getURL, endpoint) |
201 | |
202 | @@ -38,44 +38,54 @@ |
203 | The getURL method returns the URL for this entity as accessed through |
204 | the given endpoint. |
205 | """ |
206 | - endpoint = Endpoint('http://fluiddb.test.url/') |
207 | + endpoint = Endpoint('http://fluiddb.url/') |
208 | path = _HasPath(u'foo') |
209 | - path.collectionName = 'tests' |
210 | - self.assertEqual(path.getURL(endpoint), |
211 | - 'http://fluiddb.test.url/tests/foo') |
212 | + path.collectionName = u'tests' |
213 | + self.assertEqual(path.getURL(endpoint), 'http://fluiddb.url/tests/foo') |
214 | |
215 | |
216 | def test_getURLPrefix(self): |
217 | """ |
218 | Passing prefix to getURL prepends the given components to the path. |
219 | """ |
220 | - endpoint = Endpoint('http://fluiddb.test.url/') |
221 | + endpoint = Endpoint('http://fluiddb.url/') |
222 | path = _HasPath(u'foo') |
223 | - path.collectionName = 'tests' |
224 | + path.collectionName = u'tests' |
225 | self.assertEqual(path.getURL(endpoint, prefix=[u'quux', u'42']), |
226 | - 'http://fluiddb.test.url/quux/42/foo') |
227 | + 'http://fluiddb.url/quux/42/tests/foo') |
228 | |
229 | |
230 | def test_getURLSuffix(self): |
231 | """ |
232 | Passing suffix to getURL appends the given components to the path. |
233 | """ |
234 | - endpoint = Endpoint('http://fluiddb.test.url/') |
235 | + endpoint = Endpoint('http://fluiddb.url/') |
236 | path = _HasPath(u'foo') |
237 | - path.collectionName = 'tests' |
238 | + path.collectionName = u'tests' |
239 | self.assertEqual(path.getURL(endpoint, suffix=[u'quux', u'42']), |
240 | - 'http://fluiddb.test.url/tests/foo/quux/42') |
241 | + 'http://fluiddb.url/tests/foo/quux/42') |
242 | + |
243 | + |
244 | + def test_getURLCollectionName(self): |
245 | + """ |
246 | + Passing collectionName to getURL overrides the one in self. |
247 | + """ |
248 | + endpoint = Endpoint('http://fluiddb.url/') |
249 | + path = _HasPath(u'foo') |
250 | + path.collectionName = u'tests' |
251 | + self.assertEqual(path.getURL(endpoint, collectionName=u'new'), |
252 | + 'http://fluiddb.url/new/foo') |
253 | |
254 | |
255 | def test_urlEncoding(self): |
256 | """ |
257 | URL encoding is done according to IRI rules. |
258 | """ |
259 | - endpoint = Endpoint('http://fluiddb.test.url/') |
260 | + endpoint = Endpoint('http://fluiddb.url/') |
261 | path = _HasPath(u'r\xfasty') |
262 | - path.collectionName = 'tests' |
263 | + path.collectionName = u'tests' |
264 | self.assertEqual(path.getURL(endpoint), |
265 | - 'http://fluiddb.test.url/tests/r%C3%BAsty') |
266 | + 'http://fluiddb.url/tests/r%C3%BAsty') |
267 | |
268 | |
269 | |
270 | @@ -84,7 +94,7 @@ |
271 | Tests for L{Namespace}. |
272 | """ |
273 | def setUp(self): |
274 | - self.endpoint = MockEndpoint('http://fluiddb.test.url/') |
275 | + self.endpoint = MockEndpoint('http://fluiddb.url/') |
276 | self.namespace = Namespace(u'test') |
277 | |
278 | |
279 | @@ -118,8 +128,17 @@ |
280 | """ |
281 | The tag method returns a tag of the given name in this namespace. |
282 | """ |
283 | - tag = Namespace(u'test').tag(u'sometag') |
284 | - self.assertEqual(tag.getPath(), u'test/sometag') |
285 | + tag = Namespace(u'test').tag(u'atag') |
286 | + self.assertEqual(tag.getPath(), u'test/atag') |
287 | + |
288 | + |
289 | + def test_tagValues(self): |
290 | + """ |
291 | + The tagValues method returns a TagValues object for the given name |
292 | + in this namespace. |
293 | + """ |
294 | + tagValues = Namespace(u'test').tagValues(u'atag') |
295 | + self.assertEqual(tagValues.getPath(), u'test/atag') |
296 | |
297 | |
298 | def test_collectionName(self): |
299 | @@ -128,7 +147,7 @@ |
300 | """ |
301 | namespace = Namespace(u'test') |
302 | self.assertEqual(namespace.child(u'namespace').getURL(self.endpoint), |
303 | - 'http://fluiddb.test.url/namespaces/test/namespace') |
304 | + 'http://fluiddb.url/namespaces/test/namespace') |
305 | |
306 | |
307 | def test_getDescription(self): |
308 | @@ -146,7 +165,7 @@ |
309 | self.assertEqual(self.endpoint.method, 'GET') |
310 | self.assertEqual( |
311 | self.endpoint.url, |
312 | - 'http://fluiddb.test.url/namespaces/test?returnDescription=true') |
313 | + 'http://fluiddb.url/namespaces/test?returnDescription=true') |
314 | self.assertEqual(self.endpoint.data, None) |
315 | return d |
316 | |
317 | @@ -160,7 +179,7 @@ |
318 | d = self.namespace.setDescription(self.endpoint, u'New description') |
319 | self.assertEqual(self.endpoint.method, 'PUT') |
320 | self.assertEqual(self.endpoint.url, |
321 | - 'http://fluiddb.test.url/namespaces/test') |
322 | + 'http://fluiddb.url/namespaces/test') |
323 | self.assertEqual(json.loads(self.endpoint.data), |
324 | {u'description': u'New description'}) |
325 | return d |
326 | @@ -187,7 +206,7 @@ |
327 | self.assertEqual(self.endpoint.method, 'GET') |
328 | self.assertEqual( |
329 | self.endpoint.url, |
330 | - 'http://fluiddb.test.url/namespaces/test?returnNamespaces=true') |
331 | + 'http://fluiddb.url/namespaces/test?returnNamespaces=true') |
332 | self.assertEqual(self.endpoint.data, None) |
333 | return d |
334 | |
335 | @@ -212,7 +231,7 @@ |
336 | self.assertEqual(self.endpoint.method, 'GET') |
337 | self.assertEqual( |
338 | self.endpoint.url, |
339 | - 'http://fluiddb.test.url/namespaces/test?returnTags=true') |
340 | + 'http://fluiddb.url/namespaces/test?returnTags=true') |
341 | self.assertEqual(self.endpoint.data, None) |
342 | return d |
343 | |
344 | @@ -222,7 +241,7 @@ |
345 | Test creating a new namespace under an existing namespace. |
346 | """ |
347 | res = {u'id': u'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', |
348 | - u'URI': u'http://fluiddb.test.url/namespaces/test/newchild'} |
349 | + u'URI': u'http://fluiddb.url/namespaces/test/newchild'} |
350 | self.endpoint.response = json.dumps(res) |
351 | |
352 | def _gotResult(ns): |
353 | @@ -234,7 +253,7 @@ |
354 | u'New child namespace') |
355 | self.assertEqual(self.endpoint.method, 'POST') |
356 | self.assertEqual(self.endpoint.url, |
357 | - 'http://fluiddb.test.url/namespaces/test') |
358 | + 'http://fluiddb.url/namespaces/test') |
359 | self.assertEqual(json.loads(self.endpoint.data), |
360 | {u'name': u'newchild', |
361 | u'description': u'New child namespace'}) |
362 | @@ -258,7 +277,7 @@ |
363 | Test creating a tag in a namespace. |
364 | """ |
365 | response = {u'id': u'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', |
366 | - u'URI': u'http://fluiddb.test.url/tags/test/newtag'} |
367 | + u'URI': u'http://fluiddb.url/tags/test/newtag'} |
368 | self.endpoint.response = json.dumps(response) |
369 | |
370 | def _gotResult(tag): |
371 | @@ -271,7 +290,7 @@ |
372 | False) |
373 | self.assertEqual(self.endpoint.method, 'POST') |
374 | self.assertEqual(self.endpoint.url, |
375 | - 'http://fluiddb.test.url/tags/test') |
376 | + 'http://fluiddb.url/tags/test') |
377 | self.assertEqual(json.loads(self.endpoint.data), |
378 | {u'name': u'newtag', |
379 | u'description': u'New tag', |
380 | @@ -301,7 +320,48 @@ |
381 | d = self.namespace.delete(self.endpoint) |
382 | self.assertEqual(self.endpoint.method, 'DELETE') |
383 | self.assertEqual(self.endpoint.url, |
384 | - 'http://fluiddb.test.url/namespaces/test') |
385 | + 'http://fluiddb.url/namespaces/test') |
386 | + return d |
387 | + |
388 | + |
389 | + def test_getPerms(self): |
390 | + """ |
391 | + Test getting permissions for a namespace. |
392 | + """ |
393 | + response = {u'policy': u'open', |
394 | + u'exceptions': [u'tom', u'dick', u'harry']} |
395 | + self.endpoint.response = json.dumps(response) |
396 | + |
397 | + def _gotResult((policy, exceptions)): |
398 | + self.assertEqual(policy, u'open') |
399 | + self.assertEqual(exceptions, [u'tom', u'dick', u'harry']) |
400 | + |
401 | + d = self.namespace.getPerms(self.endpoint, 'create') |
402 | + d.addCallback(_gotResult) |
403 | + self.assertEqual(self.endpoint.method, 'GET') |
404 | + self.assertEqual( |
405 | + self.endpoint.url, |
406 | + 'http://fluiddb.url/permissions/namespaces/test?action=create') |
407 | + return d |
408 | + |
409 | + |
410 | + def test_setPerms(self): |
411 | + """ |
412 | + Test setting permissions for a namespace. |
413 | + """ |
414 | + self.endpoint.response = '' |
415 | + |
416 | + d = self.namespace.setPerms(self.endpoint, |
417 | + 'create', |
418 | + u'open', |
419 | + [u'tom', u'dick', u'harry']) |
420 | + self.assertEqual(self.endpoint.method, 'PUT') |
421 | + self.assertEqual( |
422 | + self.endpoint.url, |
423 | + 'http://fluiddb.url/permissions/namespaces/test?action=create') |
424 | + self.assertEqual(json.loads(self.endpoint.data), |
425 | + {u'policy': u'open', |
426 | + u'exceptions': [u'tom', u'dick', u'harry']}) |
427 | return d |
428 | |
429 | |
430 | @@ -311,8 +371,8 @@ |
431 | Tests for L{Tag}. |
432 | """ |
433 | def setUp(self): |
434 | - self.endpoint = MockEndpoint('http://fluiddb.test.url/') |
435 | - self.tag = Namespace(u'test').tag(u'sometag') |
436 | + self.endpoint = MockEndpoint('http://fluiddb.url/') |
437 | + self.tag = Namespace(u'test').tag(u'atag') |
438 | |
439 | |
440 | def test_collectionName(self): |
441 | @@ -320,9 +380,9 @@ |
442 | Tags are under the collection name 'tags'. |
443 | """ |
444 | namespace = Namespace(u'test') |
445 | - endpoint = Endpoint('http://fluiddb.test.url/') |
446 | + endpoint = Endpoint('http://fluiddb.url/') |
447 | self.assertEqual(namespace.tag(u'tag').getURL(endpoint), |
448 | - 'http://fluiddb.test.url/tags/test/tag') |
449 | + 'http://fluiddb.url/tags/test/tag') |
450 | |
451 | |
452 | def test_getDescription(self): |
453 | @@ -341,7 +401,7 @@ |
454 | self.assertEqual(self.endpoint.method, 'GET') |
455 | self.assertEqual( |
456 | self.endpoint.url, |
457 | - 'http://fluiddb.test.url/tags/test/sometag?returnDescription=true') |
458 | + 'http://fluiddb.url/tags/test/atag?returnDescription=true') |
459 | self.assertEqual(self.endpoint.data, None) |
460 | return d |
461 | |
462 | @@ -355,7 +415,7 @@ |
463 | d = self.tag.setDescription(self.endpoint, u'New description') |
464 | self.assertEqual(self.endpoint.method, 'PUT') |
465 | self.assertEqual(self.endpoint.url, |
466 | - 'http://fluiddb.test.url/tags/test/sometag') |
467 | + 'http://fluiddb.url/tags/test/atag') |
468 | self.assertEqual(json.loads(self.endpoint.data), |
469 | {u'description': u'New description'}) |
470 | return d |
471 | @@ -370,7 +430,107 @@ |
472 | d = self.tag.delete(self.endpoint) |
473 | self.assertEqual(self.endpoint.method, 'DELETE') |
474 | self.assertEqual(self.endpoint.url, |
475 | - 'http://fluiddb.test.url/tags/test/sometag') |
476 | + 'http://fluiddb.url/tags/test/atag') |
477 | + return d |
478 | + |
479 | + |
480 | + def test_getPerms(self): |
481 | + """ |
482 | + Test getting permissions for a tag. |
483 | + """ |
484 | + response = {u'policy': u'open', |
485 | + u'exceptions': [u'tom', u'dick', u'harry']} |
486 | + self.endpoint.response = json.dumps(response) |
487 | + |
488 | + def _gotResult((policy, exceptions)): |
489 | + self.assertEqual(policy, u'open') |
490 | + self.assertEqual(exceptions, [u'tom', u'dick', u'harry']) |
491 | + |
492 | + d = self.tag.getPerms(self.endpoint, 'create').addCallback(_gotResult) |
493 | + self.assertEqual(self.endpoint.method, 'GET') |
494 | + self.assertEqual( |
495 | + self.endpoint.url, |
496 | + 'http://fluiddb.url/permissions/tags/test/atag?action=create') |
497 | + return d |
498 | + |
499 | + |
500 | + def test_setPerms(self): |
501 | + """ |
502 | + Test setting permissions for a tag. |
503 | + """ |
504 | + self.endpoint.response = '' |
505 | + |
506 | + d = self.tag.setPerms(self.endpoint, |
507 | + 'create', |
508 | + u'open', |
509 | + [u'tom', u'dick', u'harry']) |
510 | + self.assertEqual(self.endpoint.method, 'PUT') |
511 | + self.assertEqual( |
512 | + self.endpoint.url, |
513 | + 'http://fluiddb.url/permissions/tags/test/atag?action=create') |
514 | + self.assertEqual(json.loads(self.endpoint.data), |
515 | + {u'policy': u'open', |
516 | + u'exceptions': [u'tom', u'dick', u'harry']}) |
517 | + return d |
518 | + |
519 | + |
520 | +class TagValueTests(TestCase): |
521 | + """ |
522 | + Tests for L{TagValues}. |
523 | + """ |
524 | + def setUp(self): |
525 | + self.endpoint = MockEndpoint('http://fluiddb.url/') |
526 | + self.tagValues = Namespace(u'test').tagValues(u'atag') |
527 | + |
528 | + |
529 | + def test_collectionName(self): |
530 | + """ |
531 | + Tag values are under the collection name 'tag-values'. |
532 | + """ |
533 | + namespace = Namespace(u'test') |
534 | + endpoint = Endpoint('http://fluiddb.url/') |
535 | + self.assertEqual(namespace.tagValues(u'tag').getURL(endpoint), |
536 | + 'http://fluiddb.url/tag-values/test/tag') |
537 | + |
538 | + |
539 | + def test_getPerms(self): |
540 | + """ |
541 | + Test getting permissions for a tag's values. |
542 | + """ |
543 | + response = {u'policy': u'open', |
544 | + u'exceptions': [u'tom', u'dick', u'harry']} |
545 | + self.endpoint.response = json.dumps(response) |
546 | + |
547 | + def _gotResult((policy, exceptions)): |
548 | + self.assertEqual(policy, u'open') |
549 | + self.assertEqual(exceptions, [u'tom', u'dick', u'harry']) |
550 | + |
551 | + d = self.tagValues.getPerms(self.endpoint, 'create') |
552 | + d.addCallback(_gotResult) |
553 | + self.assertEqual(self.endpoint.method, 'GET') |
554 | + self.assertEqual( |
555 | + self.endpoint.url, |
556 | + 'http://fluiddb.url/permissions/tag-values/test/atag?action=create') |
557 | + return d |
558 | + |
559 | + |
560 | + def test_setPerms(self): |
561 | + """ |
562 | + Test setting permissions for a tag. |
563 | + """ |
564 | + self.endpoint.response = '' |
565 | + |
566 | + d = self.tagValues.setPerms(self.endpoint, |
567 | + 'create', |
568 | + u'open', |
569 | + [u'tom', u'dick', u'harry']) |
570 | + self.assertEqual(self.endpoint.method, 'PUT') |
571 | + self.assertEqual( |
572 | + self.endpoint.url, |
573 | + 'http://fluiddb.url/permissions/tag-values/test/atag?action=create') |
574 | + self.assertEqual(json.loads(self.endpoint.data), |
575 | + {u'policy': u'open', |
576 | + u'exceptions': [u'tom', u'dick', u'harry']}) |
577 | return d |
578 | |
579 | |
580 | @@ -401,7 +561,7 @@ |
581 | """ |
582 | Constructing an endpoint stores the given base URL. |
583 | """ |
584 | - url = 'http://fluiddb.test.url/' |
585 | + url = 'http://fluiddb.url/' |
586 | endpoint = Endpoint(url) |
587 | self.assertEqual(endpoint.baseURL, url) |
588 | |
589 | @@ -426,9 +586,9 @@ |
590 | """ |
591 | The root URL must include the API version if specified. |
592 | """ |
593 | - endpoint = Endpoint('http://fluiddb.test.url/', '20090817') |
594 | + endpoint = Endpoint('http://fluiddb.url/', '20090817') |
595 | self.assertEqual(endpoint.getRootURL(), |
596 | - 'http://fluiddb.test.url/20090817/') |
597 | + 'http://fluiddb.url/20090817/') |
598 | |
599 | |
600 | def test_basicAuth(self): |
601 | @@ -437,9 +597,9 @@ |
602 | with every request. |
603 | """ |
604 | creds = BasicCreds('testuser', 'password') |
605 | - endpoint = MockEndpoint('http://fluiddb.test.url/', creds=creds) |
606 | + endpoint = MockEndpoint('http://fluiddb.url/', creds=creds) |
607 | endpoint.response = '' |
608 | - endpoint.submit('http://fluiddb.test.url/blah', 'GET') |
609 | + endpoint.submit('http://fluiddb.url/blah', 'GET') |
610 | self.assertEqual(endpoint.headers['Authorization'], |
611 | 'Basic dGVzdHVzZXI6cGFzc3dvcmQ=') |
612 | |
613 | @@ -458,7 +618,7 @@ |
614 | Tests for L{Object}. |
615 | """ |
616 | def setUp(self): |
617 | - self.endpoint = MockEndpoint('http://fluiddb.test.url/') |
618 | + self.endpoint = MockEndpoint('http://fluiddb.url/') |
619 | |
620 | |
621 | def test_getTags(self): |
622 | @@ -484,7 +644,7 @@ |
623 | self.assertEqual(self.endpoint.method, 'GET') |
624 | self.assertEqual( |
625 | self.endpoint.url, |
626 | - 'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx') |
627 | + 'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx') |
628 | self.assertEqual(json.loads(self.endpoint.data), |
629 | {u'showAbout': True}) |
630 | return d |
631 | @@ -504,7 +664,7 @@ |
632 | self.assertEqual(self.endpoint.data, None) |
633 | self.assertEqual( |
634 | self.endpoint.url, |
635 | - 'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
636 | + 'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
637 | return d |
638 | |
639 | |
640 | @@ -553,7 +713,7 @@ |
641 | self.assertEqual(self.endpoint.method, 'DELETE') |
642 | self.assertEqual( |
643 | self.endpoint.url, |
644 | - 'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
645 | + 'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
646 | self.assertEqual(self.endpoint.data, None) |
647 | return d |
648 | |
649 | @@ -570,7 +730,7 @@ |
650 | self.assertEqual(self.endpoint.method, 'PUT') |
651 | self.assertEqual( |
652 | self.endpoint.url, |
653 | - 'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
654 | + 'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
655 | self.assertEqual(json.loads(self.endpoint.data), 42) |
656 | return d |
657 | |
658 | @@ -588,7 +748,7 @@ |
659 | self.assertEqual(self.endpoint.method, 'PUT') |
660 | self.assertEqual( |
661 | self.endpoint.url, |
662 | - 'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
663 | + 'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx/test/tag') |
664 | self.assertEqual(self.endpoint.data, '<p>foo</p>') |
665 | self.assertEqual(self.endpoint.headers['Content-Type'], 'text/html') |
666 | return d |
667 | @@ -598,7 +758,7 @@ |
668 | """ |
669 | Creating an object returns the newly created object. |
670 | """ |
671 | - response = {u'URI': u'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', |
672 | + response = {u'URI': u'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', |
673 | u'id': u'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'} |
674 | self.endpoint.response = json.dumps(response) |
675 | |
676 | @@ -608,7 +768,7 @@ |
677 | |
678 | d = Object.create(self.endpoint).addCallback(_gotResponse) |
679 | self.assertEqual(self.endpoint.method, 'POST') |
680 | - self.assertEqual(self.endpoint.url, 'http://fluiddb.test.url/objects') |
681 | + self.assertEqual(self.endpoint.url, 'http://fluiddb.url/objects') |
682 | self.assertEqual(self.endpoint.data, None) |
683 | return d |
684 | |
685 | @@ -617,7 +777,7 @@ |
686 | """ |
687 | Test creating an object with an about value. |
688 | """ |
689 | - response = {u'URI': u'http://fluiddb.test.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', |
690 | + response = {u'URI': u'http://fluiddb.url/objects/xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', |
691 | u'id': u'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'} |
692 | self.endpoint.response = json.dumps(response) |
693 | |
694 | @@ -627,7 +787,7 @@ |
695 | |
696 | d = Object.create(self.endpoint, u'New object').addCallback(_gotResponse) |
697 | self.assertEqual(self.endpoint.method, 'POST') |
698 | - self.assertEqual(self.endpoint.url, 'http://fluiddb.test.url/objects') |
699 | + self.assertEqual(self.endpoint.url, 'http://fluiddb.url/objects') |
700 | self.assertEqual(json.loads(self.endpoint.data), |
701 | {u'about': u'New object'}) |
702 | return d |
703 | @@ -651,6 +811,6 @@ |
704 | |
705 | d = Object.query(self.endpoint, u'has fluiddb/about').addCallback(_gotResponse) |
706 | self.assertEqual(self.endpoint.method, 'GET') |
707 | - self.assertEqual(self.endpoint.url, 'http://fluiddb.test.url/objects?query=has+fluiddb%2Fabout') |
708 | + self.assertEqual(self.endpoint.url, 'http://fluiddb.url/objects?query=has+fluiddb%2Fabout') |
709 | self.assertEqual(self.endpoint.data, None) |
710 | return d |
Add getting/setting perms on namespaces, tags, and sets of tag values.