Revision 20387cd4
b/kamaki/clients/test/pithos.py | ||
---|---|---|
219 | 219 |
expected = [call('%s%s' % (prfx, k), v) for k, v in metas.items()] |
220 | 220 |
self.assertEqual(PC.set_header.mock_calls, expected) |
221 | 221 |
|
222 |
def test_del_account_meta(self): |
|
222 |
@patch('%s.account_post' % pithos_pkg, return_value=FR()) |
|
223 |
def test_del_account_meta(self, ap): |
|
223 | 224 |
keys = ['k1', 'k2', 'k3'] |
224 |
with patch.object(PC, 'account_post', return_value=FR()) as ap:
|
|
225 |
expected = []
|
|
226 |
for key in keys:
|
|
227 |
self.client.del_account_meta(key)
|
|
228 |
expected.append(call(update=True, metadata={key: ''}))
|
|
229 |
self.assertEqual(ap.mock_calls, expected) |
|
230 |
|
|
231 |
def test_create_container(self): |
|
225 |
expected = []
|
|
226 |
for key in keys:
|
|
227 |
self.client.del_account_meta(key)
|
|
228 |
expected.append(call(update=True, metadata={key: ''}))
|
|
229 |
self.assertEqual(ap.mock_calls, expected)
|
|
230 |
|
|
231 |
@patch('%s.put' % pithos_pkg, return_value=FR()) |
|
232 |
def test_create_container(self, put):
|
|
232 | 233 |
FR.status_code = 201 |
233 |
with patch.object(PC, 'put', return_value=FR()) as put:
|
|
234 |
cont = 's0m3c0n731n3r'
|
|
235 |
self.client.create_container(cont)
|
|
236 |
expected = [call('/%s/%s' % (user_id, cont), success=(201, 202))]
|
|
237 |
self.assertEqual(put.mock_calls, expected)
|
|
238 |
FR.status_code = 202
|
|
239 |
self.assertRaises(ClientError, self.client.create_container, cont) |
|
240 |
|
|
241 |
def test_get_container_info(self): |
|
234 |
cont = 's0m3c0n731n3r'
|
|
235 |
self.client.create_container(cont)
|
|
236 |
expected = [call('/%s/%s' % (user_id, cont), success=(201, 202))]
|
|
237 |
self.assertEqual(put.mock_calls, expected)
|
|
238 |
FR.status_code = 202
|
|
239 |
self.assertRaises(ClientError, self.client.create_container, cont)
|
|
240 |
|
|
241 |
@patch('%s.container_head' % pithos_pkg, return_value=FR()) |
|
242 |
def test_get_container_info(self, ch):
|
|
242 | 243 |
FR.headers = container_info |
243 |
with patch.object(PC, 'container_head', return_value=FR()) as ch:
|
|
244 |
r = self.client.get_container_info()
|
|
245 |
self.assert_dicts_are_equal(r, container_info)
|
|
246 |
u = 'some date'
|
|
247 |
r = self.client.get_container_info(until=u)
|
|
248 |
self.assertEqual(ch.mock_calls, [call(until=None), call(until=u)]) |
|
249 |
|
|
250 |
def test_delete_container(self): |
|
244 |
r = self.client.get_container_info()
|
|
245 |
self.assert_dicts_are_equal(r, container_info)
|
|
246 |
u = 'some date'
|
|
247 |
r = self.client.get_container_info(until=u)
|
|
248 |
self.assertEqual(ch.mock_calls, [call(until=None), call(until=u)])
|
|
249 |
|
|
250 |
@patch('%s.delete' % pithos_pkg, return_value=FR()) |
|
251 |
def test_delete_container(self, delete):
|
|
251 | 252 |
FR.status_code = 204 |
252 |
with patch.object(PC, 'delete', return_value=FR()) as delete: |
|
253 |
cont = 's0m3c0n731n3r' |
|
254 |
self.client.delete_container(cont) |
|
255 |
FR.status_code = 404 |
|
256 |
self.assertRaises(ClientError, self.client.delete_container, cont) |
|
257 |
FR.status_code = 409 |
|
253 |
cont = 's0m3c0n731n3r' |
|
254 |
self.client.delete_container(cont) |
|
255 |
for err_code in (404, 409): |
|
256 |
FR.status_code = err_code |
|
258 | 257 |
self.assertRaises(ClientError, self.client.delete_container, cont) |
259 |
acall = call('/%s/%s' % (user_id, cont), success=(204, 404, 409))
|
|
260 |
self.assertEqual(delete.mock_calls, [acall] * 3)
|
|
258 |
acall = call('/%s/%s' % (user_id, cont), success=(204, 404, 409)) |
|
259 |
self.assertEqual(delete.mock_calls, [acall] * 3) |
|
261 | 260 |
|
262 |
def test_list_containers(self): |
|
261 |
@patch('%s.account_get' % pithos_pkg, return_value=FR()) |
|
262 |
def test_list_containers(self, get): |
|
263 | 263 |
FR.json = container_list |
264 |
with patch.object(PC, 'account_get', return_value=FR()): |
|
265 |
r = self.client.list_containers() |
|
266 |
for i in range(len(r)): |
|
267 |
self.assert_dicts_are_equal(r[i], container_list[i]) |
|
264 |
r = self.client.list_containers() |
|
265 |
for i in range(len(r)): |
|
266 |
self.assert_dicts_are_equal(r[i], container_list[i]) |
|
268 | 267 |
|
269 | 268 |
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info) |
270 | 269 |
@patch('%s.container_post' % pithos_pkg, return_value=FR()) |
... | ... | |
373 | 372 |
for arg, val in kwargs.items(): |
374 | 373 |
self.assertEqual(OP.mock_calls[-2][2][arg], val) |
375 | 374 |
|
375 |
@patch('%s.put' % pithos_pkg, return_value=FR()) |
|
376 | 376 |
@patch('%s.set_header' % client_pkg) |
377 |
def test_create_object(self, SH): |
|
377 |
def test_create_object(self, SH, put):
|
|
378 | 378 |
cont = self.client.container |
379 | 379 |
ctype = 'c0n73n7/typ3' |
380 | 380 |
exp_shd = [ |
... | ... | |
382 | 382 |
call('Content-length', '0'), |
383 | 383 |
call('Content-Type', ctype), call('Content-length', '42')] |
384 | 384 |
exp_put = [call('/%s/%s/%s' % (user_id, cont, obj), success=201)] * 2 |
385 |
with patch.object(PC, 'put', return_value=FR()) as put: |
|
386 |
self.client.create_object(obj) |
|
387 |
self.client.create_object(obj, |
|
388 |
content_type=ctype, content_length=42) |
|
389 |
self.assertEqual(PC.set_header.mock_calls, exp_shd) |
|
390 |
self.assertEqual(put.mock_calls, exp_put) |
|
385 |
self.client.create_object(obj) |
|
386 |
self.client.create_object(obj, content_type=ctype, content_length=42) |
|
387 |
self.assertEqual(PC.set_header.mock_calls, exp_shd) |
|
388 |
self.assertEqual(put.mock_calls, exp_put) |
|
391 | 389 |
|
390 |
@patch('%s.put' % pithos_pkg, return_value=FR()) |
|
392 | 391 |
@patch('%s.set_header' % client_pkg) |
393 |
def test_create_directory(self, SH): |
|
392 |
def test_create_directory(self, SH, put):
|
|
394 | 393 |
cont = self.client.container |
395 | 394 |
exp_shd = [ |
396 | 395 |
call('Content-Type', 'application/directory'), |
397 | 396 |
call('Content-length', '0')] |
398 | 397 |
exp_put = [call('/%s/%s/%s' % (user_id, cont, obj), success=201)] |
399 |
with patch.object(PC, 'put', return_value=FR()) as put: |
|
400 |
self.client.create_directory(obj) |
|
401 |
self.assertEqual(PC.set_header.mock_calls, exp_shd) |
|
402 |
self.assertEqual(put.mock_calls, exp_put) |
|
398 |
self.client.create_directory(obj) |
|
399 |
self.assertEqual(PC.set_header.mock_calls, exp_shd) |
|
400 |
self.assertEqual(put.mock_calls, exp_put) |
|
403 | 401 |
|
404 | 402 |
def test_get_object_info(self): |
405 | 403 |
FR.headers = object_info |
... | ... | |
420 | 418 |
self.client.get_object_info, |
421 | 419 |
obj, version=version) |
422 | 420 |
|
423 |
def test_get_object_meta(self): |
|
421 |
@patch('%s.get_object_info' % pithos_pkg, return_value=object_info) |
|
422 |
def test_get_object_meta(self, GOI): |
|
424 | 423 |
expected = dict() |
425 | 424 |
for k, v in object_info.items(): |
426 | 425 |
expected[k] = v |
427 |
with patch.object(PC, 'get_object_info', return_value=object_info): |
|
428 |
r = self.client.get_object_meta(obj) |
|
429 |
self.assert_dicts_are_equal(r, expected) |
|
426 |
r = self.client.get_object_meta(obj) |
|
427 |
self.assert_dicts_are_equal(r, expected) |
|
430 | 428 |
|
431 |
def test_del_object_meta(self): |
|
429 |
@patch('%s.object_post' % pithos_pkg, return_value=FR()) |
|
430 |
def test_del_object_meta(self, post): |
|
432 | 431 |
metakey = '50m3m3t4k3y' |
433 |
with patch.object(PC, 'object_post', return_value=FR()) as post: |
|
434 |
self.client.del_object_meta(obj, metakey) |
|
435 |
self.assertEqual( |
|
436 |
post.mock_calls, |
|
437 |
[call(obj, update=True, metadata={metakey: ''})]) |
|
432 |
self.client.del_object_meta(obj, metakey) |
|
433 |
expected = call(obj, update=True, metadata={metakey: ''}) |
|
434 |
self.assertEqual(post.mock_calls[-1], expected) |
|
438 | 435 |
|
436 |
@patch('%s.post' % client_pkg, return_value=FR()) |
|
439 | 437 |
@patch('%s.set_header' % client_pkg) |
440 |
def test_replace_object_meta(self, SH): |
|
438 |
def test_replace_object_meta(self, SH, post):
|
|
441 | 439 |
metas = dict(k1='new1', k2='new2', k3='new3') |
442 | 440 |
cont = self.client.container |
443 |
with patch.object(PC, 'post', return_value=FR()) as post: |
|
444 |
self.client.replace_object_meta(metas) |
|
445 |
self.assertEqual(post.mock_calls, [ |
|
446 |
call('/%s/%s' % (user_id, cont), |
|
447 |
success=202)]) |
|
448 |
prfx = 'X-Object-Meta-' |
|
449 |
expected = [call('%s%s' % (prfx, k), v) for k, v in metas.items()] |
|
450 |
self.assertEqual(PC.set_header.mock_calls, expected) |
|
441 |
self.client.replace_object_meta(metas) |
|
442 |
expected = call('/%s/%s' % (user_id, cont), success=202) |
|
443 |
self.assertEqual(post.mock_calls[-1], expected) |
|
444 |
prfx = 'X-Object-Meta-' |
|
445 |
expected = [call('%s%s' % (prfx, k), v) for k, v in metas.items()] |
|
446 |
self.assertEqual(PC.set_header.mock_calls, expected) |
|
451 | 447 |
|
452 |
def test_copy_object(self): |
|
448 |
@patch('%s.object_put' % pithos_pkg, return_value=FR()) |
|
449 |
def test_copy_object(self, put): |
|
453 | 450 |
src_cont = 'src-c0nt41n3r' |
454 | 451 |
src_obj = 'src-0bj' |
455 | 452 |
dst_cont = 'dst-c0nt41n3r' |
... | ... | |
464 | 461 |
content_type=None, |
465 | 462 |
source_version=None, |
466 | 463 |
public=False) |
467 |
with patch.object(PC, 'object_put', return_value=FR()) as put: |
|
468 |
self.client.copy_object(src_cont, src_obj, dst_cont) |
|
469 |
self.assertEqual(put.mock_calls[-1], expected) |
|
470 |
self.client.copy_object(src_cont, src_obj, dst_cont, dst_obj) |
|
471 |
self.assertEqual(put.mock_calls[-1][1], (dst_obj,)) |
|
472 |
kwargs = dict( |
|
473 |
source_version='src-v3r510n', |
|
474 |
source_account='src-4cc0un7', |
|
475 |
public=True, |
|
476 |
content_type='c0n73n7Typ3', |
|
477 |
delimiter='5') |
|
478 |
self.client.copy_object(src_cont, src_obj, dst_cont, **kwargs) |
|
479 |
for k, v in kwargs.items(): |
|
480 |
self.assertEqual(v, put.mock_calls[-1][2][k]) |
|
464 |
self.client.copy_object(src_cont, src_obj, dst_cont) |
|
465 |
self.assertEqual(put.mock_calls[-1], expected) |
|
466 |
self.client.copy_object(src_cont, src_obj, dst_cont, dst_obj) |
|
467 |
self.assertEqual(put.mock_calls[-1][1], (dst_obj,)) |
|
468 |
kwargs = dict( |
|
469 |
source_version='src-v3r510n', |
|
470 |
source_account='src-4cc0un7', |
|
471 |
public=True, |
|
472 |
content_type='c0n73n7Typ3', |
|
473 |
delimiter='5') |
|
474 |
self.client.copy_object(src_cont, src_obj, dst_cont, **kwargs) |
|
475 |
for k, v in kwargs.items(): |
|
476 |
self.assertEqual(v, put.mock_calls[-1][2][k]) |
|
481 | 477 |
|
482 |
def test_move_object(self): |
|
478 |
@patch('%s.object_put' % pithos_pkg, return_value=FR()) |
|
479 |
def test_move_object(self, put): |
|
483 | 480 |
src_cont = 'src-c0nt41n3r' |
484 | 481 |
src_obj = 'src-0bj' |
485 | 482 |
dst_cont = 'dst-c0nt41n3r' |
... | ... | |
494 | 491 |
content_type=None, |
495 | 492 |
source_version=None, |
496 | 493 |
public=False) |
497 |
with patch.object(PC, 'object_put', return_value=FR()) as put: |
|
498 |
self.client.move_object(src_cont, src_obj, dst_cont) |
|
499 |
self.assertEqual(put.mock_calls[-1], expected) |
|
500 |
self.client.move_object(src_cont, src_obj, dst_cont, dst_obj) |
|
501 |
self.assertEqual(put.mock_calls[-1][1], (dst_obj,)) |
|
502 |
kwargs = dict( |
|
503 |
source_version='src-v3r510n', |
|
504 |
source_account='src-4cc0un7', |
|
505 |
public=True, |
|
506 |
content_type='c0n73n7Typ3', |
|
507 |
delimiter='5') |
|
508 |
self.client.move_object(src_cont, src_obj, dst_cont, **kwargs) |
|
509 |
for k, v in kwargs.items(): |
|
510 |
self.assertEqual(v, put.mock_calls[-1][2][k]) |
|
494 |
self.client.move_object(src_cont, src_obj, dst_cont) |
|
495 |
self.assertEqual(put.mock_calls[-1], expected) |
|
496 |
self.client.move_object(src_cont, src_obj, dst_cont, dst_obj) |
|
497 |
self.assertEqual(put.mock_calls[-1][1], (dst_obj,)) |
|
498 |
kwargs = dict( |
|
499 |
source_version='src-v3r510n', |
|
500 |
source_account='src-4cc0un7', |
|
501 |
public=True, |
|
502 |
content_type='c0n73n7Typ3', |
|
503 |
delimiter='5') |
|
504 |
self.client.move_object(src_cont, src_obj, dst_cont, **kwargs) |
|
505 |
for k, v in kwargs.items(): |
|
506 |
self.assertEqual(v, put.mock_calls[-1][2][k]) |
|
511 | 507 |
|
512 |
def test_delete_object(self): |
|
508 |
@patch('%s.delete' % client_pkg, return_value=FR()) |
|
509 |
def test_delete_object(self, delete): |
|
513 | 510 |
cont = self.client.container |
514 |
with patch.object(PC, 'delete', return_value=FR()) as delete:
|
|
515 |
self.client.delete_object(obj)
|
|
516 |
self.assertEqual(delete.mock_calls, [
|
|
517 |
call('/%s/%s/%s' % (user_id, cont, obj), success=(204, 404))])
|
|
518 |
FR.status_code = 404
|
|
519 |
self.assertRaises(ClientError, self.client.delete_object, obj)
|
|
511 |
self.client.delete_object(obj)
|
|
512 |
self.assertEqual(
|
|
513 |
delete.mock_calls[-1],
|
|
514 |
call('/%s/%s/%s' % (user_id, cont, obj), success=(204, 404)))
|
|
515 |
FR.status_code = 404 |
|
516 |
self.assertRaises(ClientError, self.client.delete_object, obj) |
|
520 | 517 |
|
518 |
@patch('%s.get' % client_pkg, return_value=FR()) |
|
521 | 519 |
@patch('%s.set_param' % client_pkg) |
522 |
def test_list_objects(self, SP): |
|
520 |
def test_list_objects(self, SP, get):
|
|
523 | 521 |
FR.json = object_list |
524 | 522 |
acc = self.client.account |
525 | 523 |
cont = self.client.container |
526 | 524 |
SP = PC.set_param |
527 |
with patch.object(PC, 'get', return_value=FR()) as get:
|
|
528 |
r = self.client.list_objects()
|
|
529 |
for i in range(len(r)):
|
|
530 |
self.assert_dicts_are_equal(r[i], object_list[i])
|
|
531 |
self.assertEqual(get.mock_calls, [
|
|
532 |
call('/%s/%s' % (acc, cont), success=(200, 204, 304, 404))])
|
|
533 |
self.assertEqual(SP.mock_calls, [call('format', 'json')])
|
|
534 |
FR.status_code = 304
|
|
535 |
self.assertEqual(self.client.list_objects(), [])
|
|
536 |
FR.status_code = 404
|
|
537 |
self.assertRaises(ClientError, self.client.list_objects) |
|
538 |
|
|
525 |
r = self.client.list_objects()
|
|
526 |
for i in range(len(r)):
|
|
527 |
self.assert_dicts_are_equal(r[i], object_list[i])
|
|
528 |
self.assertEqual(get.mock_calls, [
|
|
529 |
call('/%s/%s' % (acc, cont), success=(200, 204, 304, 404))])
|
|
530 |
self.assertEqual(SP.mock_calls, [call('format', 'json')])
|
|
531 |
FR.status_code = 304
|
|
532 |
self.assertEqual(self.client.list_objects(), [])
|
|
533 |
FR.status_code = 404
|
|
534 |
self.assertRaises(ClientError, self.client.list_objects)
|
|
535 |
|
|
536 |
@patch('%s.get' % client_pkg, return_value=FR()) |
|
539 | 537 |
@patch('%s.set_param' % client_pkg) |
540 |
def test_list_objects_in_path(self, SP): |
|
538 |
def test_list_objects_in_path(self, SP, get):
|
|
541 | 539 |
FR.json = object_list |
542 | 540 |
path = '/some/awsome/path' |
543 | 541 |
acc = self.client.account |
544 | 542 |
cont = self.client.container |
545 | 543 |
SP = PC.set_param |
546 |
with patch.object(PC, 'get', return_value=FR()) as get: |
|
547 |
self.client.list_objects_in_path(path) |
|
548 |
self.assertEqual(get.mock_calls, [ |
|
549 |
call('/%s/%s' % (acc, cont), success=(200, 204, 404))]) |
|
550 |
self.assertEqual(SP.mock_calls, [ |
|
551 |
call('format', 'json'), call('path', path)]) |
|
552 |
FR.status_code = 404 |
|
553 |
self.assertRaises(ClientError, self.client.list_objects) |
|
544 |
self.client.list_objects_in_path(path) |
|
545 |
self.assertEqual(get.mock_calls, [ |
|
546 |
call('/%s/%s' % (acc, cont), success=(200, 204, 404))]) |
|
547 |
self.assertEqual(SP.mock_calls, [ |
|
548 |
call('format', 'json'), call('path', path)]) |
|
549 |
FR.status_code = 404 |
|
550 |
self.assertRaises(ClientError, self.client.list_objects) |
|
554 | 551 |
|
555 | 552 |
# Pithos+ only methods |
556 | 553 |
|
557 |
def test_purge_container(self):
|
|
558 |
with patch.object(PC, 'container_delete', return_value=FR()) as cd:
|
|
559 |
self.client.purge_container()
|
|
560 |
self.assertTrue('until' in cd.mock_calls[-1][2])
|
|
561 |
cont = self.client.container
|
|
562 |
self.client.purge_container('another-container')
|
|
563 |
self.assertEqual(self.client.container, cont)
|
|
554 |
@patch('%s.container_delete' % pithos_pkg, return_value=FR())
|
|
555 |
def test_purge_container(self, cd):
|
|
556 |
self.client.purge_container() |
|
557 |
self.assertTrue('until' in cd.mock_calls[-1][2]) |
|
558 |
cont = self.client.container |
|
559 |
self.client.purge_container('another-container') |
|
560 |
self.assertEqual(self.client.container, cont) |
|
564 | 561 |
|
565 |
def test_upload_object_unchunked(self): |
|
562 |
@patch('%s.object_put' % pithos_pkg, return_value=FR()) |
|
563 |
def test_upload_object_unchunked(self, put): |
|
566 | 564 |
num_of_blocks = 8 |
567 | 565 |
tmpFile = self._create_temp_file(num_of_blocks) |
568 | 566 |
expected = dict( |
... | ... | |
574 | 572 |
content_disposition='some content_disposition', |
575 | 573 |
public=True, |
576 | 574 |
permissions=dict(read=['u1', 'g1', 'u2'], write=['u1'])) |
577 |
with patch.object(PC, 'object_put', return_value=FR()) as put: |
|
578 |
self.client.upload_object_unchunked(obj, tmpFile) |
|
579 |
self.assertEqual(put.mock_calls[-1][1], (obj,)) |
|
580 |
self.assertEqual( |
|
581 |
sorted(put.mock_calls[-1][2].keys()), |
|
582 |
sorted(expected.keys())) |
|
583 |
kwargs = dict(expected) |
|
584 |
kwargs.pop('success') |
|
585 |
kwargs['size'] = kwargs.pop('data') |
|
586 |
kwargs['sharing'] = kwargs.pop('permissions') |
|
587 |
tmpFile.seek(0) |
|
588 |
self.client.upload_object_unchunked(obj, tmpFile, **kwargs) |
|
589 |
pmc = put.mock_calls[-1][2] |
|
590 |
for k, v in expected.items(): |
|
591 |
if k == 'data': |
|
592 |
self.assertEqual(len(pmc[k]), v) |
|
593 |
else: |
|
594 |
self.assertEqual(pmc[k], v) |
|
595 |
self.assertRaises( |
|
596 |
ClientError, |
|
597 |
self.client.upload_object_unchunked, |
|
598 |
obj, tmpFile, withHashFile=True) |
|
575 |
self.client.upload_object_unchunked(obj, tmpFile) |
|
576 |
self.assertEqual(put.mock_calls[-1][1], (obj,)) |
|
577 |
self.assertEqual( |
|
578 |
sorted(put.mock_calls[-1][2].keys()), |
|
579 |
sorted(expected.keys())) |
|
580 |
kwargs = dict(expected) |
|
581 |
kwargs.pop('success') |
|
582 |
kwargs['size'] = kwargs.pop('data') |
|
583 |
kwargs['sharing'] = kwargs.pop('permissions') |
|
584 |
tmpFile.seek(0) |
|
585 |
self.client.upload_object_unchunked(obj, tmpFile, **kwargs) |
|
586 |
pmc = put.mock_calls[-1][2] |
|
587 |
for k, v in expected.items(): |
|
588 |
if k == 'data': |
|
589 |
self.assertEqual(len(pmc[k]), v) |
|
590 |
else: |
|
591 |
self.assertEqual(pmc[k], v) |
|
592 |
self.assertRaises( |
|
593 |
ClientError, |
|
594 |
self.client.upload_object_unchunked, |
|
595 |
obj, tmpFile, withHashFile=True) |
|
599 | 596 |
|
600 |
def test_create_object_by_manifestation(self): |
|
597 |
@patch('%s.object_put' % pithos_pkg, return_value=FR()) |
|
598 |
def test_create_object_by_manifestation(self, put): |
|
601 | 599 |
manifest = '%s/%s' % (self.client.container, obj) |
602 | 600 |
kwargs = dict( |
603 | 601 |
etag='some-etag', |
... | ... | |
606 | 604 |
content_disposition='some content_disposition', |
607 | 605 |
public=True, |
608 | 606 |
sharing=dict(read=['u1', 'g1', 'u2'], write=['u1'])) |
609 |
with patch.object(PC, 'object_put', return_value=FR()) as put: |
|
610 |
self.client.create_object_by_manifestation(obj) |
|
611 |
expected = dict(content_length=0, manifest=manifest) |
|
612 |
for k in kwargs: |
|
613 |
expected['permissions' if k == 'sharing' else k] = None |
|
614 |
self.assertEqual(put.mock_calls[-1], call(obj, **expected)) |
|
615 |
self.client.create_object_by_manifestation(obj, **kwargs) |
|
616 |
expected.update(kwargs) |
|
617 |
expected['permissions'] = expected.pop('sharing') |
|
618 |
self.assertEqual(put.mock_calls[-1], call(obj, **expected)) |
|
607 |
self.client.create_object_by_manifestation(obj) |
|
608 |
expected = dict(content_length=0, manifest=manifest) |
|
609 |
for k in kwargs: |
|
610 |
expected['permissions' if k == 'sharing' else k] = None |
|
611 |
self.assertEqual(put.mock_calls[-1], call(obj, **expected)) |
|
612 |
self.client.create_object_by_manifestation(obj, **kwargs) |
|
613 |
expected.update(kwargs) |
|
614 |
expected['permissions'] = expected.pop('sharing') |
|
615 |
self.assertEqual(put.mock_calls[-1], call(obj, **expected)) |
|
619 | 616 |
|
620 | 617 |
@patch('%s.get_object_hashmap' % pithos_pkg, return_value=object_hashmap) |
621 | 618 |
@patch('%s.object_get' % pithos_pkg, return_value=FR()) |
... | ... | |
738 | 735 |
exp_args.update(kwargs) |
739 | 736 |
self.assertEqual(get.mock_calls[-1], call(obj, **exp_args)) |
740 | 737 |
|
741 |
def test_set_account_group(self): |
|
742 |
group = 'aU53rGr0up' |
|
743 |
usernames = ['u1', 'u2', 'u3'] |
|
744 |
with patch.object(PC, 'account_post', return_value=FR()) as post: |
|
745 |
self.client.set_account_group(group, usernames) |
|
746 |
self.assertEqual( |
|
747 |
post.mock_calls[-1], |
|
748 |
call(update=True, groups={group: usernames})) |
|
738 |
@patch('%s.account_post' % pithos_pkg, return_value=FR()) |
|
739 |
def test_set_account_group(self, post): |
|
740 |
(group, usernames) = ('aU53rGr0up', ['u1', 'u2', 'u3']) |
|
741 |
self.client.set_account_group(group, usernames) |
|
742 |
self.assertEqual( |
|
743 |
post.mock_calls[-1], |
|
744 |
call(update=True, groups={group: usernames})) |
|
749 | 745 |
|
750 |
def test_del_account_group(self): |
|
746 |
@patch('%s.account_post' % pithos_pkg, return_value=FR()) |
|
747 |
def test_del_account_group(self, post): |
|
751 | 748 |
group = 'aU53rGr0up' |
752 |
with patch.object(PC, 'account_post', return_value=FR()) as post: |
|
753 |
self.client.del_account_group(group) |
|
754 |
self.assertEqual( |
|
755 |
post.mock_calls[-1], |
|
756 |
call(update=True, groups={group: []})) |
|
749 |
self.client.del_account_group(group) |
|
750 |
self.assertEqual( |
|
751 |
post.mock_calls[-1], |
|
752 |
call(update=True, groups={group: []})) |
|
757 | 753 |
|
758 |
def test_get_account_quota(self): |
|
754 |
@patch('%s.get_account_info' % pithos_pkg, return_value=account_info) |
|
755 |
def test_get_account_quota(self, GAI): |
|
759 | 756 |
key = 'x-account-policy-quota' |
760 |
with patch.object(PC, 'get_account_info', return_value=account_info): |
|
761 |
r = self.client.get_account_quota() |
|
762 |
self.assertEqual(r[key], account_info[key]) |
|
757 |
r = self.client.get_account_quota() |
|
758 |
self.assertEqual(r[key], account_info[key]) |
|
763 | 759 |
|
764 |
def test_get_account_versioning(self): |
|
760 |
@patch('%s.get_account_info' % pithos_pkg, return_value=account_info) |
|
761 |
def test_get_account_versioning(self, GAI): |
|
765 | 762 |
key = 'x-account-policy-versioning' |
766 |
with patch.object(PC, 'get_account_info', return_value=account_info): |
|
767 |
r = self.client.get_account_versioning() |
|
768 |
self.assertEqual(r[key], account_info[key]) |
|
763 |
r = self.client.get_account_versioning() |
|
764 |
self.assertEqual(r[key], account_info[key]) |
|
769 | 765 |
|
770 | 766 |
def test_get_account_meta(self): |
771 | 767 |
key = 'x-account-meta-' |
... | ... | |
797 | 793 |
for k in [k for k in acc_info if k.startswith(key)]: |
798 | 794 |
self.assertEqual(r[k], acc_info[k]) |
799 | 795 |
|
800 |
def test_set_account_meta(self): |
|
796 |
@patch('%s.account_post' % pithos_pkg, return_value=FR()) |
|
797 |
def test_set_account_meta(self, post): |
|
801 | 798 |
metas = dict(k1='v1', k2='v2', k3='v3') |
802 |
with patch.object(PC, 'account_post', return_value=FR()) as post: |
|
803 |
self.client.set_account_meta(metas) |
|
804 |
self.assertEqual( |
|
805 |
post.mock_calls[-1], |
|
806 |
call(update=True, metadata=metas)) |
|
799 |
self.client.set_account_meta(metas) |
|
800 |
self.assertEqual( |
|
801 |
post.mock_calls[-1], |
|
802 |
call(update=True, metadata=metas)) |
|
807 | 803 |
|
808 |
def test_set_account_quota(self): |
|
804 |
@patch('%s.account_post' % pithos_pkg, return_value=FR()) |
|
805 |
def test_set_account_quota(self, post): |
|
809 | 806 |
qu = 1024 |
810 |
with patch.object(PC, 'account_post', return_value=FR()) as post: |
|
811 |
self.client.set_account_quota(qu) |
|
812 |
self.assertEqual(post.mock_calls[-1], call(update=True, quota=qu)) |
|
807 |
self.client.set_account_quota(qu) |
|
808 |
self.assertEqual(post.mock_calls[-1], call(update=True, quota=qu)) |
|
813 | 809 |
|
814 |
def test_set_account_versioning(self): |
|
810 |
@patch('%s.account_post' % pithos_pkg, return_value=FR()) |
|
811 |
def test_set_account_versioning(self, post): |
|
815 | 812 |
vrs = 'n3wV3r51on1ngTyp3' |
816 |
with patch.object(PC, 'account_post', return_value=FR()) as post: |
|
817 |
self.client.set_account_versioning(vrs) |
|
818 |
self.assertEqual( |
|
819 |
post.mock_calls[-1], |
|
820 |
call(update=True, versioning=vrs)) |
|
821 |
|
|
822 |
def test_del_container(self): |
|
823 |
kwarg_list = [ |
|
824 |
dict(delimiter=None, until=None), |
|
825 |
dict(delimiter='X', until='50m3d473')] |
|
826 |
with patch.object(PC, 'container_delete', return_value=FR()) as delete: |
|
827 |
for kwarg in kwarg_list: |
|
828 |
self.client.del_container(**kwarg) |
|
829 |
expected = dict(kwarg) |
|
830 |
expected['success'] = (204, 404, 409) |
|
831 |
self.assertEqual(delete.mock_calls[-1], call(**expected)) |
|
832 |
for status_code in (404, 409): |
|
833 |
FR.status_code = status_code |
|
834 |
self.assertRaises(ClientError, self.client.del_container) |
|
813 |
self.client.set_account_versioning(vrs) |
|
814 |
self.assertEqual( |
|
815 |
post.mock_calls[-1], |
|
816 |
call(update=True, versioning=vrs)) |
|
817 |
|
|
818 |
@patch('%s.container_delete' % pithos_pkg, return_value=FR()) |
|
819 |
def test_del_container(self, delete): |
|
820 |
for kwarg in ( |
|
821 |
dict(delimiter=None, until=None), |
|
822 |
dict(delimiter='X', until='50m3d473')): |
|
823 |
self.client.del_container(**kwarg) |
|
824 |
expected = dict(kwarg) |
|
825 |
expected['success'] = (204, 404, 409) |
|
826 |
self.assertEqual(delete.mock_calls[-1], call(**expected)) |
|
827 |
for status_code in (404, 409): |
|
828 |
FR.status_code = status_code |
|
829 |
self.assertRaises(ClientError, self.client.del_container) |
|
835 | 830 |
|
836 | 831 |
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info) |
837 | 832 |
def test_get_container_versioning(self, GCI): |
... | ... | |
889 | 884 |
self.assertEqual(r, ret[1]) |
890 | 885 |
self.assertEqual(gci.mock_calls[-1], call(until=until)) |
891 | 886 |
|
892 |
def test_set_container_meta(self): |
|
887 |
@patch('%s.container_post' % pithos_pkg, return_value=FR()) |
|
888 |
def test_set_container_meta(self, post): |
|
893 | 889 |
metas = dict(k1='v1', k2='v2', k3='v3') |
894 |
with patch.object(PC, 'container_post', return_value=FR()) as post: |
|
895 |
self.client.set_container_meta(metas) |
|
896 |
self.assertEqual( |
|
897 |
post.mock_calls[-1], |
|
898 |
call(update=True, metadata=metas)) |
|
890 |
self.client.set_container_meta(metas) |
|
891 |
self.assertEqual( |
|
892 |
post.mock_calls[-1], |
|
893 |
call(update=True, metadata=metas)) |
|
899 | 894 |
|
900 |
def test_del_container_meta(self):
|
|
901 |
with patch.object(PC, 'container_post', return_value=FR()) as ap:
|
|
902 |
self.client.del_container_meta('somekey')
|
|
903 |
expected = [call(update=True, metadata={'somekey': ''})]
|
|
904 |
self.assertEqual(ap.mock_calls, expected)
|
|
895 |
@patch('%s.container_post' % pithos_pkg, return_value=FR())
|
|
896 |
def test_del_container_meta(self, ap):
|
|
897 |
self.client.del_container_meta('somekey') |
|
898 |
expected = [call(update=True, metadata={'somekey': ''})] |
|
899 |
self.assertEqual(ap.mock_calls, expected) |
|
905 | 900 |
|
906 |
def test_set_container_quota(self): |
|
901 |
@patch('%s.container_post' % pithos_pkg, return_value=FR()) |
|
902 |
def test_set_container_quota(self, post): |
|
907 | 903 |
qu = 1024 |
908 |
with patch.object(PC, 'container_post', return_value=FR()) as post: |
|
909 |
self.client.set_container_quota(qu) |
|
910 |
self.assertEqual(post.mock_calls[-1], call(update=True, quota=qu)) |
|
904 |
self.client.set_container_quota(qu) |
|
905 |
self.assertEqual(post.mock_calls[-1], call(update=True, quota=qu)) |
|
911 | 906 |
|
912 |
def test_set_container_versioning(self): |
|
907 |
@patch('%s.container_post' % pithos_pkg, return_value=FR()) |
|
908 |
def test_set_container_versioning(self, post): |
|
913 | 909 |
vrs = 'n3wV3r51on1ngTyp3' |
914 |
with patch.object(PC, 'container_post', return_value=FR()) as post: |
|
915 |
self.client.set_container_versioning(vrs) |
|
916 |
self.assertEqual( |
|
917 |
post.mock_calls[-1], |
|
918 |
call(update=True, versioning=vrs)) |
|
919 |
|
|
920 |
def test_del_object(self): |
|
921 |
kwargs = [ |
|
922 |
dict(delimiter=None, until=None), |
|
923 |
dict(delimiter='X', until='50m3d473')] |
|
924 |
with patch.object(PC, 'object_delete', return_value=FR()) as delete: |
|
925 |
for kwarg in kwargs: |
|
926 |
self.client.del_object(obj, **kwarg) |
|
927 |
self.assertEqual(delete.mock_calls[-1], call(obj, **kwarg)) |
|
928 |
|
|
929 |
def test_set_object_meta(self): |
|
910 |
self.client.set_container_versioning(vrs) |
|
911 |
self.assertEqual( |
|
912 |
post.mock_calls[-1], |
|
913 |
call(update=True, versioning=vrs)) |
|
914 |
|
|
915 |
@patch('%s.object_delete' % pithos_pkg, return_value=FR()) |
|
916 |
def test_del_object(self, delete): |
|
917 |
for kwarg in ( |
|
918 |
dict(delimiter=None, until=None), |
|
919 |
dict(delimiter='X', until='50m3d473')): |
|
920 |
self.client.del_object(obj, **kwarg) |
|
921 |
self.assertEqual(delete.mock_calls[-1], call(obj, **kwarg)) |
|
922 |
|
|
923 |
@patch('%s.object_post' % pithos_pkg, return_value=FR()) |
|
924 |
def test_set_object_meta(self, post): |
|
930 | 925 |
metas = dict(k1='v1', k2='v2', k3='v3') |
931 |
with patch.object(PC, 'object_post', return_value=FR()) as post: |
|
932 |
self.assertRaises( |
|
933 |
AssertionError, |
|
934 |
self.client.set_object_meta, |
|
935 |
obj, 'Non dict arg') |
|
936 |
self.client.set_object_meta(obj, metas) |
|
937 |
self.assertEqual( |
|
938 |
post.mock_calls[-1], |
|
939 |
call(obj, update=True, metadata=metas)) |
|
926 |
self.assertRaises( |
|
927 |
AssertionError, |
|
928 |
self.client.set_object_meta, |
|
929 |
obj, 'Non dict arg') |
|
930 |
self.client.set_object_meta(obj, metas) |
|
931 |
self.assertEqual( |
|
932 |
post.mock_calls[-1], |
|
933 |
call(obj, update=True, metadata=metas)) |
|
940 | 934 |
|
941 | 935 |
@patch('%s.object_post' % pithos_pkg, return_value=FR()) |
942 | 936 |
def test_publish_object(self, post): |
... | ... | |
1004 | 998 |
def test_del_object_sharing(self, SOS): |
1005 | 999 |
self.client.del_object_sharing(obj) |
1006 | 1000 |
self.assertEqual(SOS.mock_calls[-1], call(obj)) |
1001 |
|
|
1002 |
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info) |
|
1003 |
@patch('%s.object_post' % pithos_pkg, return_value=FR()) |
|
1004 |
def test_append_object(self, post, GCI): |
|
1005 |
num_of_blocks = 4 |
|
1006 |
tmpFile = self._create_temp_file(4) |
|
1007 |
tmpFile.seek(0, 2) |
|
1008 |
file_size = tmpFile.tell() |
|
1009 |
for turn in range(2): |
|
1010 |
tmpFile.seek(0, 0) |
|
1011 |
|
|
1012 |
try: |
|
1013 |
from progress.bar import ShadyBar |
|
1014 |
apn_bar = ShadyBar('Mock append') |
|
1015 |
except ImportError: |
|
1016 |
apn_bar = None |
|
1017 |
|
|
1018 |
if apn_bar: |
|
1019 |
|
|
1020 |
def append_gen(n): |
|
1021 |
for i in apn_bar.iter(range(n)): |
|
1022 |
yield |
|
1023 |
yield |
|
1024 |
|
|
1025 |
else: |
|
1026 |
append_gen = None |
|
1027 |
|
|
1028 |
self.client.append_object( |
|
1029 |
obj, tmpFile, |
|
1030 |
upload_cb=append_gen if turn else None) |
|
1031 |
self.assertEqual((turn + 1) * num_of_blocks, len(post.mock_calls)) |
|
1032 |
(args, kwargs) = post.mock_calls[-1][1:3] |
|
1033 |
self.assertEqual(args, (obj,)) |
|
1034 |
self.assertEqual(kwargs['content_length'], len(kwargs['data'])) |
|
1035 |
fsize = num_of_blocks * int(kwargs['content_length']) |
|
1036 |
self.assertEqual(fsize, file_size) |
|
1037 |
self.assertEqual(kwargs['content_range'], 'bytes */*') |
|
1038 |
exp = 'application/octet-stream' |
|
1039 |
self.assertEqual(kwargs['content_type'], exp) |
|
1040 |
self.assertEqual(kwargs['update'], True) |
Also available in: Unified diff