Revision cb65588d
b/kamaki/clients/test/pithos.py | ||
---|---|---|
42 | 42 |
from kamaki.clients.connection.kamakicon import KamakiHTTPConnection as C |
43 | 43 |
|
44 | 44 |
user_id = 'ac0un7-1d-5tr1ng' |
45 |
obj = 'obj3c7N4m3' |
|
45 | 46 |
|
46 | 47 |
account_info = { |
47 | 48 |
'content-language': 'en-us', |
... | ... | |
147 | 148 |
|
148 | 149 |
files = [] |
149 | 150 |
|
150 |
def _create_temp_file(self): |
|
151 |
def _create_temp_file(self, num_of_blocks):
|
|
151 | 152 |
self.files.append(NamedTemporaryFile()) |
152 | 153 |
tmpFile = self.files[-1] |
153 |
num_of_blocks = 8 |
|
154 | 154 |
file_size = num_of_blocks * 4 * 1024 * 1024 |
155 | 155 |
print('\n\tCreate tmp file') |
156 | 156 |
tmpFile.write(urandom(file_size)) |
... | ... | |
267 | 267 |
PC.get_container_info = Mock(return_value=container_info) |
268 | 268 |
PC.container_post = Mock(return_value=self.FR()) |
269 | 269 |
PC.object_put = Mock(return_value=self.FR()) |
270 |
tmpFile = self._create_temp_file()
|
|
271 |
obj = 'objectName'
|
|
270 |
num_of_blocks = 8
|
|
271 |
tmpFile = self._create_temp_file(num_of_blocks)
|
|
272 | 272 |
|
273 | 273 |
# Without kwargs |
274 | 274 |
self.client.upload_object(obj, tmpFile) |
... | ... | |
284 | 284 |
format='json', |
285 | 285 |
json=dict( |
286 | 286 |
hashes=['s0m3h@5h'] * num_of_blocks, |
287 |
bytes=file_size),
|
|
287 |
bytes=num_of_blocks * 4 * 1024 * 1024),
|
|
288 | 288 |
etag=None, |
289 | 289 |
content_encoding=None, |
290 | 290 |
content_type='application/octet-stream', |
... | ... | |
303 | 303 |
expected2 = dict( |
304 | 304 |
json=dict( |
305 | 305 |
hashes=['s0m3h@5h'] * num_of_blocks, |
306 |
bytes=file_size),
|
|
306 |
bytes=num_of_blocks * 4 * 1024 * 1024),
|
|
307 | 307 |
content_type='application/octet-stream', |
308 | 308 |
hashmap=True, |
309 | 309 |
success=201, |
... | ... | |
372 | 372 |
|
373 | 373 |
def test_create_object(self): |
374 | 374 |
PC.set_header = Mock() |
375 |
obj = 'r4nd0m0bj3c7' |
|
376 | 375 |
cont = self.client.container |
377 | 376 |
ctype = 'c0n73n7/typ3' |
378 | 377 |
exp_shd = [ |
... | ... | |
389 | 388 |
|
390 | 389 |
def test_create_directory(self): |
391 | 390 |
PC.set_header = Mock() |
392 |
obj = 'r4nd0m0bj3c7' |
|
393 | 391 |
cont = self.client.container |
394 | 392 |
exp_shd = [ |
395 | 393 |
call('Content-Type', 'application/directory'), |
... | ... | |
402 | 400 |
|
403 | 401 |
def test_get_object_info(self): |
404 | 402 |
self.FR.headers = object_info |
405 |
obj = 'r4nd0m0bj3c7' |
|
406 | 403 |
version = 'v3r510n' |
407 | 404 |
with patch.object(PC, 'object_head', return_value=self.FR()) as head: |
408 | 405 |
r = self.client.get_object_info(obj) |
... | ... | |
421 | 418 |
obj, version=version) |
422 | 419 |
|
423 | 420 |
def test_get_object_meta(self): |
424 |
obj = 'r4nd0m0bj3c7' |
|
425 | 421 |
expected = dict() |
426 | 422 |
for k, v in object_info.items(): |
427 | 423 |
expected[k] = v |
... | ... | |
433 | 429 |
self.assert_dicts_are_equal(r, expected) |
434 | 430 |
|
435 | 431 |
def test_del_object_meta(self): |
436 |
obj = 'r4nd0m0bj3c7' |
|
437 | 432 |
metakey = '50m3m3t4k3y' |
438 | 433 |
with patch.object(PC, 'object_post', return_value=self.FR()) as post: |
439 | 434 |
self.client.del_object_meta(obj, metakey) |
... | ... | |
515 | 510 |
self.assertEqual(v, put.mock_calls[-1][2][k]) |
516 | 511 |
|
517 | 512 |
def test_delete_object(self): |
518 |
obj = 's0m30bj3c7' |
|
519 | 513 |
cont = self.client.container |
520 | 514 |
with patch.object(PC, 'delete', return_value=self.FR()) as delete: |
521 | 515 |
self.client.delete_object(obj) |
... | ... | |
572 | 566 |
self.assertEqual(self.client.container, cont) |
573 | 567 |
|
574 | 568 |
def test_upload_object_unchunked(self): |
575 |
tmpFile = self._create_temp_file()
|
|
576 |
obj = 'obj3c7N4m3'
|
|
569 |
num_of_blocks = 8
|
|
570 |
tmpFile = self._create_temp_file(num_of_blocks)
|
|
577 | 571 |
expected = dict( |
578 | 572 |
success=201, |
579 |
data=8 * 4 * 1024 * 1024,
|
|
573 |
data=num_of_blocks * 4 * 1024 * 1024,
|
|
580 | 574 |
etag='some-etag', |
581 | 575 |
content_encoding='some content_encoding', |
582 | 576 |
content_type='some content-type', |
... | ... | |
607 | 601 |
obj, tmpFile, withHashFile=True) |
608 | 602 |
|
609 | 603 |
def test_create_object_by_manifestation(self): |
610 |
obj = 'obj3c7N4m3' |
|
611 | 604 |
manifest = '%s/%s' % (self.client.container, obj) |
612 | 605 |
kwargs = dict( |
613 | 606 |
etag='some-etag', |
... | ... | |
629 | 622 |
|
630 | 623 |
def test_download_object(self): |
631 | 624 |
PC.get_object_hashmap = Mock(return_value=object_hashmap) |
632 |
tmpFile = self._create_temp_file() |
|
625 |
num_of_blocks = 8 |
|
626 |
tmpFile = self._create_temp_file(num_of_blocks) |
|
633 | 627 |
self.FR.content = tmpFile.read(4 * 1024 * 1024) |
634 |
tmpFile = self._create_temp_file() |
|
628 |
tmpFile = self._create_temp_file(num_of_blocks)
|
|
635 | 629 |
PC.object_get = Mock(return_value=self.FR()) |
636 | 630 |
GET = PC.object_get |
637 |
obj = 'obj3c7N4m3' |
|
638 | 631 |
num_of_blocks = len(object_hashmap['hashes']) |
639 | 632 |
|
640 | 633 |
kwargs = dict( |
641 |
version='version', |
|
642 | 634 |
resume=True, |
635 |
version='version', |
|
643 | 636 |
range_str='10-20', |
644 | 637 |
if_match='if and only if', |
645 | 638 |
if_none_match='if and only not', |
... | ... | |
715 | 708 |
self.assertTrue('data_range' in GET.mock_calls[-1][2]) |
716 | 709 |
else: |
717 | 710 |
self.assertEqual(GET.mock_calls[-1][2][k], v) |
711 |
|
|
712 |
def test_get_object_hashmap(self): |
|
713 |
self.FR.json = object_hashmap |
|
714 |
for empty in (304, 412): |
|
715 |
with patch.object( |
|
716 |
PC, 'object_get', |
|
717 |
side_effect=ClientError('Empty', status=empty)): |
|
718 |
r = self.client.get_object_hashmap(obj) |
|
719 |
self.assertEqual(r, {}) |
|
720 |
exp_args = dict( |
|
721 |
hashmap=True, |
|
722 |
data_range=None, |
|
723 |
version=None, |
|
724 |
if_etag_match=None, |
|
725 |
if_etag_not_match=None, |
|
726 |
if_modified_since=None, |
|
727 |
if_unmodified_since=None) |
|
728 |
kwargs = dict( |
|
729 |
version='s0m3v3r51on', |
|
730 |
if_match='if match', |
|
731 |
if_none_match='if non match', |
|
732 |
if_modified_since='some date here', |
|
733 |
if_unmodified_since='some date here', |
|
734 |
data_range='10-20') |
|
735 |
with patch.object(PC, 'object_get', return_value=self.FR()) as get: |
|
736 |
r = self.client.get_object_hashmap(obj) |
|
737 |
self.assertEqual(r, object_hashmap) |
|
738 |
self.assertEqual(get.mock_calls[-1], call(obj, **exp_args)) |
|
739 |
r = self.client.get_object_hashmap(obj, **kwargs) |
|
740 |
exp_args['if_etag_match'] = kwargs.pop('if_match') |
|
741 |
exp_args['if_etag_not_match'] = kwargs.pop('if_none_match') |
|
742 |
exp_args.update(kwargs) |
|
743 |
self.assertEqual(get.mock_calls[-1], call(obj, **exp_args)) |
Also available in: Unified diff