40 |
40 |
from kamaki.clients.pithos import PithosClient as PC
|
41 |
41 |
from kamaki.clients.connection.kamakicon import KamakiHTTPConnection as C
|
42 |
42 |
|
|
43 |
client_pkg = 'kamaki.clients.Client'
|
|
44 |
pithos_pkg = 'kamaki.clients.pithos.PithosClient'
|
|
45 |
|
43 |
46 |
user_id = 'ac0un7-1d-5tr1ng'
|
44 |
47 |
obj = 'obj3c7N4m3'
|
45 |
48 |
|
... | ... | |
184 |
187 |
|
185 |
188 |
# Pithos+ methods that extend storage API
|
186 |
189 |
|
187 |
|
@patch('kamaki.clients.Client.set_param')
|
|
190 |
@patch('%s.set_param' % client_pkg)
|
188 |
191 |
def test_get_account_info(self, SP):
|
189 |
192 |
FR.headers = account_info
|
190 |
193 |
FR.status_code = 204
|
... | ... | |
204 |
207 |
FR.status_code = 401
|
205 |
208 |
self.assertRaises(ClientError, self.client.get_account_info)
|
206 |
209 |
|
207 |
|
@patch('kamaki.clients.Client.set_header')
|
|
210 |
@patch('%s.set_header' % client_pkg)
|
208 |
211 |
def test_replace_account_meta(self, SH):
|
209 |
212 |
FR.status_code = 202
|
210 |
213 |
metas = dict(k1='v1', k2='v2', k3='v3')
|
... | ... | |
263 |
266 |
for i in range(len(r)):
|
264 |
267 |
self.assert_dicts_are_equal(r[i], container_list[i])
|
265 |
268 |
|
266 |
|
@patch(
|
267 |
|
'kamaki.clients.pithos.PithosClient.get_container_info',
|
268 |
|
return_value=container_info)
|
269 |
|
@patch(
|
270 |
|
'kamaki.clients.pithos.PithosClient.container_post',
|
271 |
|
return_value=FR())
|
272 |
|
@patch(
|
273 |
|
'kamaki.clients.pithos.PithosClient.object_put',
|
274 |
|
return_value=FR())
|
|
269 |
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info)
|
|
270 |
@patch('%s.container_post' % pithos_pkg, return_value=FR())
|
|
271 |
@patch('%s.object_put' % pithos_pkg, return_value=FR())
|
275 |
272 |
def test_upload_object(self, CI, CP, OP):
|
276 |
273 |
num_of_blocks = 8
|
277 |
274 |
tmpFile = self._create_temp_file(num_of_blocks)
|
... | ... | |
376 |
373 |
for arg, val in kwargs.items():
|
377 |
374 |
self.assertEqual(OP.mock_calls[-2][2][arg], val)
|
378 |
375 |
|
379 |
|
@patch('kamaki.clients.Client.set_header')
|
|
376 |
@patch('%s.set_header' % client_pkg)
|
380 |
377 |
def test_create_object(self, SH):
|
381 |
378 |
cont = self.client.container
|
382 |
379 |
ctype = 'c0n73n7/typ3'
|
... | ... | |
392 |
389 |
self.assertEqual(PC.set_header.mock_calls, exp_shd)
|
393 |
390 |
self.assertEqual(put.mock_calls, exp_put)
|
394 |
391 |
|
395 |
|
@patch('kamaki.clients.Client.set_header')
|
|
392 |
@patch('%s.set_header' % client_pkg)
|
396 |
393 |
def test_create_directory(self, SH):
|
397 |
394 |
cont = self.client.container
|
398 |
395 |
exp_shd = [
|
... | ... | |
439 |
436 |
post.mock_calls,
|
440 |
437 |
[call(obj, update=True, metadata={metakey: ''})])
|
441 |
438 |
|
442 |
|
@patch('kamaki.clients.Client.set_header')
|
|
439 |
@patch('%s.set_header' % client_pkg)
|
443 |
440 |
def test_replace_object_meta(self, SH):
|
444 |
441 |
metas = dict(k1='new1', k2='new2', k3='new3')
|
445 |
442 |
cont = self.client.container
|
... | ... | |
521 |
518 |
FR.status_code = 404
|
522 |
519 |
self.assertRaises(ClientError, self.client.delete_object, obj)
|
523 |
520 |
|
524 |
|
@patch('kamaki.clients.Client.set_param')
|
|
521 |
@patch('%s.set_param' % client_pkg)
|
525 |
522 |
def test_list_objects(self, SP):
|
526 |
523 |
FR.json = object_list
|
527 |
524 |
acc = self.client.account
|
... | ... | |
539 |
536 |
FR.status_code = 404
|
540 |
537 |
self.assertRaises(ClientError, self.client.list_objects)
|
541 |
538 |
|
542 |
|
@patch('kamaki.clients.Client.set_param')
|
|
539 |
@patch('%s.set_param' % client_pkg)
|
543 |
540 |
def test_list_objects_in_path(self, SP):
|
544 |
541 |
FR.json = object_list
|
545 |
542 |
path = '/some/awsome/path'
|
... | ... | |
620 |
617 |
expected['permissions'] = expected.pop('sharing')
|
621 |
618 |
self.assertEqual(put.mock_calls[-1], call(obj, **expected))
|
622 |
619 |
|
623 |
|
@patch(
|
624 |
|
'kamaki.clients.pithos.PithosClient.get_object_hashmap',
|
625 |
|
return_value=object_hashmap)
|
626 |
|
@patch(
|
627 |
|
'kamaki.clients.pithos.PithosClient.object_get',
|
628 |
|
return_value=FR())
|
|
620 |
@patch('%s.get_object_hashmap' % pithos_pkg, return_value=object_hashmap)
|
|
621 |
@patch('%s.object_get' % pithos_pkg, return_value=FR())
|
629 |
622 |
def test_download_object(self, GOH, GET):
|
630 |
623 |
num_of_blocks = 8
|
631 |
624 |
tmpFile = self._create_temp_file(num_of_blocks)
|
... | ... | |
840 |
833 |
FR.status_code = status_code
|
841 |
834 |
self.assertRaises(ClientError, self.client.del_container)
|
842 |
835 |
|
843 |
|
@patch(
|
844 |
|
'kamaki.clients.pithos.PithosClient.get_container_info',
|
845 |
|
return_value=container_info)
|
|
836 |
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info)
|
846 |
837 |
def test_get_container_versioning(self, GCI):
|
847 |
838 |
key = 'x-container-policy-versioning'
|
848 |
839 |
cont = 'c0n7-417'
|
... | ... | |
853 |
844 |
self.assertEqual(GCI.mock_calls[-1], call())
|
854 |
845 |
self.assertEqual(bu_cnt, self.client.container)
|
855 |
846 |
|
856 |
|
@patch(
|
857 |
|
'kamaki.clients.pithos.PithosClient.get_container_info',
|
858 |
|
return_value=container_info)
|
|
847 |
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info)
|
859 |
848 |
def test_get_container_quota(self, GCI):
|
860 |
849 |
key = 'x-container-policy-quota'
|
861 |
850 |
cont = 'c0n7-417'
|
... | ... | |
948 |
937 |
self.assertEqual(
|
949 |
938 |
post.mock_calls[-1],
|
950 |
939 |
call(obj, update=True, metadata=metas))
|
|
940 |
|
|
941 |
@patch('%s.object_post' % pithos_pkg, return_value=FR())
|
|
942 |
def test_publish_object(self, post):
|
|
943 |
oinfo = dict(object_info)
|
|
944 |
val = 'pubL1c'
|
|
945 |
oinfo['x-object-public'] = val
|
|
946 |
with patch.object(PC, 'get_object_info', return_value=oinfo) as gof:
|
|
947 |
r = self.client.publish_object(obj)
|
|
948 |
self.assertEqual(
|
|
949 |
post.mock_calls[-1],
|
|
950 |
call(obj, public=True, update=True))
|
|
951 |
self.assertEqual(gof.mock_calls[-1], call(obj))
|
|
952 |
self.assertEqual(r, '%s%s' % (self.url[:-6], val))
|