Revision cd6ada1d
b/pithos/api/tests.py | ||
---|---|---|
169 | 169 |
self._assert_json(data, type, size) |
170 | 170 |
|
171 | 171 |
def _assert_json(self, data, type, size): |
172 |
print '#', data |
|
173 | 172 |
convert = lambda s: s.lower() |
174 | 173 |
info = [convert(elem) for elem in self.extended[type]] |
175 | 174 |
self.assertTrue(len(data) <= size) |
... | ... | |
191 | 190 |
self.assertTrue(len(entities) <= size) |
192 | 191 |
for e in entities: |
193 | 192 |
for item in info: |
194 |
print '#', item |
|
195 | 193 |
self.assertTrue(e.hasAttribute(item)) |
196 | 194 |
|
197 | 195 |
def assert_raises_fault(self, status, callableObj, *args, **kwargs): |
... | ... | |
424 | 422 |
self.containers = ['apples', 'bananas', 'kiwis', 'oranges', 'pears'] |
425 | 423 |
for item in self.containers: |
426 | 424 |
self.client.create_container(item) |
427 |
|
|
428 |
def test_update_meta(self): |
|
429 |
meta = {'test':'test', 'tost':'tost'} |
|
425 |
|
|
426 |
#keep track of initial account groups |
|
427 |
self.initial_groups = self.client.retrieve_account_groups() |
|
428 |
|
|
429 |
#keep track of initial account meta |
|
430 |
self.initial_meta = self.client.retrieve_account_metadata(restricted=True) |
|
431 |
|
|
432 |
meta = {'foo':'bar'} |
|
430 | 433 |
self.client.update_account_metadata(**meta) |
431 |
self.assertEqual(meta, self.client.retrieve_account_metadata(restricted=True))
|
|
434 |
self.updated_meta = self.initial_meta.update(meta)
|
|
432 | 435 |
|
436 |
def tearDown(self): |
|
437 |
#delete additionally created meta |
|
438 |
l = [] |
|
439 |
for m in self.client.retrieve_account_metadata(restricted=True): |
|
440 |
if m not in self.initial_meta: |
|
441 |
l.append(m) |
|
442 |
self.client.delete_account_metadata(l) |
|
443 |
|
|
444 |
#delete additionally created groups |
|
445 |
l = [] |
|
446 |
for g in self.client.retrieve_account_groups(): |
|
447 |
if g not in self.initial_groups: |
|
448 |
l.append(g) |
|
449 |
self.client.unset_account_groups(l) |
|
450 |
|
|
451 |
#print '#', self.client.retrieve_account_groups() |
|
452 |
#print '#', self.client.retrieve_account_metadata(restricted=True) |
|
453 |
BaseTestCase.tearDown(self) |
|
454 |
|
|
455 |
def test_update_meta(self): |
|
456 |
with AssertMappingInvariant(self.client.retrieve_account_groups): |
|
457 |
meta = {'test':'test', 'tost':'tost'} |
|
458 |
self.client.update_account_metadata(**meta) |
|
459 |
|
|
460 |
meta.update(self.initial_meta) |
|
461 |
self.assertEqual(meta, |
|
462 |
self.client.retrieve_account_metadata( |
|
463 |
restricted=True)) |
|
464 |
|
|
433 | 465 |
def test_invalid_account_update_meta(self): |
434 |
meta = {'HTTP_X_ACCOUNT_META_TEST':'test', |
|
435 |
'HTTP_X_ACCOUNT_META_TOST':'tost'} |
|
466 |
meta = {'test':'test', 'tost':'tost'} |
|
436 | 467 |
self.assert_raises_fault(401, |
437 | 468 |
self.invalid_client.update_account_metadata, |
438 | 469 |
**meta) |
439 |
|
|
470 |
|
|
471 |
def test_reset_meta(self): |
|
472 |
with AssertMappingInvariant(self.client.retrieve_account_groups): |
|
473 |
meta = {'test':'test', 'tost':'tost'} |
|
474 |
self.client.update_account_metadata(**meta) |
|
475 |
|
|
476 |
meta = {'test':'test33'} |
|
477 |
self.client.reset_account_metadata(**meta) |
|
478 |
|
|
479 |
self.assertEqual(meta, self.client.retrieve_account_metadata(restricted=True)) |
|
480 |
|
|
481 |
#def test_delete_meta(self): |
|
482 |
# with AssertMappingInvariant(self.client.reset_account_groups): |
|
483 |
# meta = {'test':'test', 'tost':'tost'} |
|
484 |
# self.client.update_account_metadata(**meta) |
|
485 |
# |
|
486 |
# self.client.delete_account_metadata(**meta) |
|
487 |
|
|
488 |
def test_set_account_groups(self): |
|
489 |
with AssertMappingInvariant(self.client.retrieve_account_metadata): |
|
490 |
groups = {'pithosdev':'verigak,gtsouk,chazapis'} |
|
491 |
self.client.set_account_groups(**groups) |
|
492 |
|
|
493 |
self.assertEqual(groups, self.client.retrieve_account_groups()) |
|
494 |
|
|
495 |
more_groups = {'clientsdev':'pkanavos,mvasilak'} |
|
496 |
self.client.set_account_groups(**more_groups) |
|
497 |
|
|
498 |
groups.update(more_groups) |
|
499 |
self.assertEqual(groups, self.client.retrieve_account_groups()) |
|
500 |
|
|
501 |
def test_reset_account_groups(self): |
|
502 |
with AssertMappingInvariant(self.client.retrieve_account_metadata): |
|
503 |
groups = {'pithosdev':'verigak,gtsouk,chazapis', |
|
504 |
'clientsdev':'pkanavos,mvasilak'} |
|
505 |
self.client.set_account_groups(**groups) |
|
506 |
|
|
507 |
self.assertEqual(groups, self.client.retrieve_account_groups()) |
|
508 |
|
|
509 |
groups = {'pithosdev':'verigak,gtsouk,chazapis, papagian'} |
|
510 |
self.client.reset_account_groups(**groups) |
|
511 |
|
|
512 |
self.assertTrue(groups, self.client.retrieve_account_groups()) |
|
513 |
|
|
514 |
def test_delete_account_groups(self): |
|
515 |
with AssertMappingInvariant(self.client.retrieve_account_metadata): |
|
516 |
groups = {'pithosdev':'verigak,gtsouk,chazapis', |
|
517 |
'clientsdev':'pkanavos,mvasilak'} |
|
518 |
self.client.set_account_groups(**groups) |
|
519 |
|
|
520 |
self.client.unset_account_groups(groups.keys()) |
|
521 |
|
|
522 |
self.assertEqual({}, self.client.retrieve_account_groups()) |
|
523 |
|
|
440 | 524 |
class ContainerHead(BaseTestCase): |
441 | 525 |
def setUp(self): |
442 | 526 |
BaseTestCase.setUp(self) |
... | ... | |
1198 | 1282 |
'content_range':'%s' %range} |
1199 | 1283 |
if content_length: |
1200 | 1284 |
args['content_length'] = content_length |
1285 |
|
|
1201 | 1286 |
status = self.client.update_object(self.containers[0], self.obj['name'], |
1202 | 1287 |
StringIO(data), **args)[0] |
1203 | 1288 |
|
... | ... | |
1223 | 1308 |
def test_update_object_invalid_range(self): |
1224 | 1309 |
with AssertContentInvariant(self.client.retrieve_object, |
1225 | 1310 |
self.containers[0], self.obj['name']): |
1226 |
self.test_update_object(499, 0, True)
|
|
1311 |
self.assert_raises_fault(416, self.test_update_object, 499, 0, True)
|
|
1227 | 1312 |
|
1228 | 1313 |
def test_update_object_invalid_range_and_length(self): |
1229 | 1314 |
with AssertContentInvariant(self.client.retrieve_object, |
1230 | 1315 |
self.containers[0], self.obj['name']): |
1231 |
self.test_update_object(499, 0, True, -1) |
|
1316 |
self.assert_raises_fault(416, self.test_update_object, 499, 0, True, |
|
1317 |
-1) |
|
1232 | 1318 |
|
1233 | 1319 |
def test_update_object_invalid_range_with_no_content_length(self): |
1234 | 1320 |
with AssertContentInvariant(self.client.retrieve_object, |
1235 | 1321 |
self.containers[0], self.obj['name']): |
1236 |
self.test_update_object(499, 0, True, content_length = None) |
|
1322 |
self.assert_raises_fault(416, self.test_update_object, 499, 0, True, |
|
1323 |
content_length = None) |
|
1237 | 1324 |
|
1238 | 1325 |
def test_update_object_out_of_limits(self): |
1239 | 1326 |
with AssertContentInvariant(self.client.retrieve_object, |
... | ... | |
1300 | 1387 |
def __exit__(self, type, value, tb): |
1301 | 1388 |
map = self.callable(*self.args, **self.kwargs) |
1302 | 1389 |
for k in self.map.keys(): |
1303 |
if is_date(map[k]): |
|
1390 |
if is_date(self.map[k]):
|
|
1304 | 1391 |
continue |
1305 | 1392 |
assert map[k] == self.map[k] |
1306 | 1393 |
|
b/pithos/lib/client.py | ||
---|---|---|
94 | 94 |
kwargs['headers']['X-Auth-Token'] = self.token |
95 | 95 |
if body: |
96 | 96 |
kwargs['body'] = body |
97 |
kwargs['headers'].setdefault('content-type', |
|
98 |
'application/octet-stream') |
|
97 | 99 |
kwargs['headers'].setdefault('content-length', len(body) if body else 0) |
98 |
kwargs['headers'].setdefault('content-type', 'application/octet-stream') |
|
99 | 100 |
try: |
100 | 101 |
#print '*', method, full_path, kwargs |
101 | 102 |
conn.request(method, full_path, **kwargs) |
... | ... | |
118 | 119 |
|
119 | 120 |
|
120 | 121 |
if int(resp.status) in ERROR_CODES.keys(): |
122 |
#print '**', resp.status |
|
121 | 123 |
raise Fault(data, int(resp.status)) |
122 | 124 |
|
123 |
#print '*', resp.status, headers, data |
|
125 |
#print '**', resp.status, headers, data
|
|
124 | 126 |
return resp.status, headers, data |
125 | 127 |
|
126 | 128 |
def delete(self, path, format='text', params={}): |
... | ... | |
146 | 148 |
if format == 'json': |
147 | 149 |
data = json.loads(data) if data else '' |
148 | 150 |
elif format == 'xml': |
149 |
print '#', data |
|
150 | 151 |
data = minidom.parseString(data) |
151 | 152 |
else: |
152 | 153 |
data = data.strip().split('\n') if data else '' |
... | ... | |
190 | 191 |
for k,v in ex_meta.items(): |
191 | 192 |
k = '%s%s' % (prefix, k) |
192 | 193 |
headers[k] = v |
193 |
return self.post(path, headers=headers, params=params)
|
|
194 |
return self.post(path, headers=headers) |
|
194 | 195 |
|
195 | 196 |
def _reset_metadata(self, path, entity, **meta): |
196 | 197 |
""" |
... | ... | |
309 | 310 |
h = {'Content-Type':'application/directory'} |
310 | 311 |
return self.create_zero_length_object(container, object, **h) |
311 | 312 |
|
313 |
def create_directory_marker(self, container, object): |
|
314 |
"""creates a dierectory marker""" |
|
315 |
return self.create_object(container, object, f=None) |
|
316 |
|
|
312 | 317 |
def create_object(self, container, object, f=stdin, format='text', meta={}, |
313 | 318 |
etag=None, content_type=None, content_encoding=None, |
314 | 319 |
content_disposition=None, **headers): |
315 |
"""creates an object"""
|
|
320 |
"""creates a zero-length object"""
|
|
316 | 321 |
path = '/%s/%s' % (container, object) |
317 | 322 |
for k, v in headers.items(): |
318 | 323 |
if not v: |
... | ... | |
328 | 333 |
data = f.read() if f else None |
329 | 334 |
return self.put(path, data, format, headers=headers) |
330 | 335 |
|
336 |
def create_zero_length_object(self, container, object, meta={}, etag=None, |
|
337 |
content_type=None, content_encoding=None, |
|
338 |
content_disposition=None, **headers): |
|
339 |
args = locals() |
|
340 |
for elem in ['self', 'container', 'headers']: |
|
341 |
args.pop(elem) |
|
342 |
args.update(headers) |
|
343 |
return self.create_object(container, f=None, **args) |
|
344 |
|
|
331 | 345 |
def update_object(self, container, object, f=stdin, offset=None, meta={}, |
332 | 346 |
content_length=None, content_type=None, |
333 | 347 |
content_encoding=None, content_disposition=None, |
... | ... | |
537 | 551 |
params = {'update':None} |
538 | 552 |
return self.post('', headers=headers, params=params) |
539 | 553 |
|
554 |
def reset_account_groups(self, **groups): |
|
555 |
"""overrides account groups""" |
|
556 |
headers = {} |
|
557 |
for key, val in groups.items(): |
|
558 |
headers['x-account-group-%s' % key] = val |
|
559 |
meta = self.retrieve_account_metadata() |
|
560 |
headers.update(meta) |
|
561 |
return self.post('', headers=headers) |
|
562 |
|
|
540 | 563 |
# Storage Container Services |
541 | 564 |
|
542 | 565 |
def list_objects(self, container, format='text', limit=10000, marker=None, |
... | ... | |
614 | 637 |
return self.retrieve_object_version(container, object, version='list', |
615 | 638 |
detail=True, **args) |
616 | 639 |
|
640 |
def create_zero_length_object(self, container, object, meta={}, |
|
641 |
etag=None, content_type=None, content_encoding=None, |
|
642 |
content_disposition=None, x_object_manifest=None, |
|
643 |
x_object_sharing=None, x_object_public=None): |
|
644 |
"""createas a zero length object""" |
|
645 |
args = locals() |
|
646 |
for elem in ['self', 'container', 'object']: |
|
647 |
args.pop(elem) |
|
648 |
return OOS_Client.create_zero_length_object(self, container, object, |
|
649 |
**args) |
|
650 |
|
|
617 | 651 |
def create_object(self, container, object, f=stdin, meta={}, |
618 | 652 |
etag=None, content_type=None, content_encoding=None, |
619 | 653 |
content_disposition=None, x_object_manifest=None, |
b/tools/store | ||
---|---|---|
406 | 406 |
meta=meta, **args) |
407 | 407 |
elif self.x_object_manifest: |
408 | 408 |
self.client.create_manifestation(container, object, self.x_object_manifest) |
409 |
elif not f: |
|
410 |
self.client.create_zero_length_object(container, object, meta=meta, **args) |
|
409 | 411 |
else: |
410 |
data = f.read() if f else None
|
|
412 |
data = f.read() |
|
411 | 413 |
self.client.create_object(container, object, data, meta=meta, **args) |
412 | 414 |
if f: |
413 | 415 |
f.close() |
Also available in: Unified diff