Skip to content
This repository was archived by the owner on Jun 12, 2019. It is now read-only.

Commit df5b885

Browse files
author
Nicolas Le Manchet
committed
Test new metadata
1 parent 386ea99 commit df5b885

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed

Diff for: runabove/tests/storage.py

+60-35
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,6 @@ def test_list_by_region(self):
161161
self.assertIsInstance(container.region, runabove.region.Region)
162162
self.assertEqual(container.region.name, self.region)
163163

164-
def test_get_by_name(self):
165-
self.mock_wrapper.get.return_value = json.loads(self.answer_one)
166-
container = self.containers.get_by_name(self.region, self.name)
167-
self.mock_wrapper.get.assert_called_once_with(
168-
self.containers.basepath + '/' +
169-
self.containers._api.encode_for_api(self.name),
170-
{'region': self.region}
171-
)
172-
self.assertIsInstance(container, runabove.storage.Container)
173-
self.assertEqual(container.name, self.name)
174-
175164
@mock.patch('swiftclient.client.Connection')
176165
def test_get_swift_client(self, mock_swiftclient):
177166
mock_get_token = self.containers._handler.tokens.get
@@ -195,6 +184,17 @@ def test_swift_call(self, mock_swiftclient):
195184
self.containers._swifts = swifts
196185
self.containers._swift_call('BHS-1', 'put_container')
197186

187+
@mock.patch('runabove.storage.ContainerManager._swift_call')
188+
def test_get_by_name(self, mock_swift_call):
189+
container = self.containers.get_by_name(self.region, self.name)
190+
mock_swift_call.assert_called_once_with(
191+
self.region,
192+
'head_container',
193+
self.name
194+
)
195+
self.assertIsInstance(container, runabove.storage.Container)
196+
self.assertEqual(container.name, self.name)
197+
198198
@mock.patch('runabove.storage.ContainerManager._swift_call')
199199
def test_delete(self, mock_swift_call):
200200
self.containers.delete(self.region, self.name)
@@ -275,30 +275,34 @@ def test_get_region_url_not_found(self):
275275
@mock.patch('runabove.storage.ContainerManager._swift_call')
276276
def test_copy_object(self, mock_swift_call):
277277
self.containers.copy_object(self.region, self.name, 'Test')
278+
headers = {
279+
'X-Copy-From': '/' + self.name + '/Test',
280+
'content-length': 0
281+
}
278282
mock_swift_call.assert_called_once_with(
279283
self.region,
280284
'put_object',
281285
self.name,
282286
'Test',
283287
None,
284-
headers = {'X-Copy-From': '/' + self.name + '/Test'},
285-
content_length=0,
286-
content_type=None
288+
headers=headers
287289
)
288290

289291
@mock.patch('runabove.storage.ContainerManager._swift_call')
290292
def test_copy_object_other_container(self, mock_swift_call):
291293
self.containers.copy_object(self.region, self.name, 'Test',
292294
to_container='test1')
295+
headers = {
296+
'X-Copy-From': '/' + self.name + '/Test',
297+
'content-length': 0
298+
}
293299
mock_swift_call.assert_called_once_with(
294300
self.region,
295301
'put_object',
296302
'test1',
297303
'Test',
298304
None,
299-
headers = {'X-Copy-From': '/' + self.name + '/Test'},
300-
content_length=0,
301-
content_type=None
305+
headers=headers
302306
)
303307

304308
@mock.patch('runabove.storage.ContainerManager._get_swift_client')
@@ -366,9 +370,8 @@ def setUp(self, mock_containers, mock_region):
366370
self.container = runabove.storage.Container(
367371
self.mock_containers,
368372
self.container_name,
369-
1024,
370-
5,
371-
self.mock_region
373+
self.mock_region,
374+
meta=None
372375
)
373376

374377
def test_list_objects(self):
@@ -428,18 +431,16 @@ def test_delete_object(self):
428431
'Test'
429432
)
430433

431-
@mock.patch('mimetypes.guess_type')
432434
@mock.patch('runabove.storage.Container.get_object_by_name')
433-
def test_create_object(self, mock_get_object_by_name, mock_guess_type):
434-
mock_guess_type.return_value = ('application/json',)
435+
def test_create_object(self, mock_get_object_by_name):
435436
obj = self.container.create_object('Test', 'content')
436437
self.mock_containers._swift_call.assert_called_once_with(
437438
self.mock_region.name,
438439
'put_object',
439440
self.container.name,
440441
'Test',
441442
'content',
442-
content_type='application/json'
443+
headers=None
443444
)
444445

445446
@mock.patch('runabove.storage.ObjectStored')
@@ -455,13 +456,6 @@ def test_copy(self, mock_obj):
455456
new_object_name
456457
)
457458

458-
def test_is_public(self):
459-
result = self.container.is_public
460-
self.mock_containers.get_by_name.assert_called_once_with(
461-
self.mock_region.name,
462-
self.container.name
463-
)
464-
465459
def test_set_public(self):
466460
self.container.set_public()
467461
self.mock_containers.set_public.assert_called_once_with(
@@ -485,6 +479,23 @@ def test_url(self):
485479
)
486480
self.assertEqual(url, base_url + '/' + self.container_name)
487481

482+
@mock.patch('runabove.storage.Container')
483+
def test_get_meta(self, mock_cnt):
484+
fake_meta = {'X-meta': 'meta'}
485+
mock_cnt._meta = fake_meta
486+
self.mock_containers.get_by_name.return_value = mock_cnt
487+
meta = self.container.meta
488+
self.mock_containers.get_by_name.assert_called_once_with(
489+
self.mock_region.name,
490+
self.container.name,
491+
list_objects=False
492+
)
493+
self.assertEqual(meta, fake_meta)
494+
495+
def test_set_meta(self):
496+
fake_meta = {'X-meta': 'meta'}
497+
self.container.meta = fake_meta
498+
488499

489500
class TestObjectStored(unittest.TestCase):
490501

@@ -495,10 +506,7 @@ def setUp(self, mock_container):
495506
self.mock_container = mock_container
496507
self.obj = runabove.storage.ObjectStored(
497508
self.mock_container,
498-
self.obj_name,
499-
1024,
500-
'Thu, 31 Jul 2014 07:57:30 GMT',
501-
'image/png'
509+
self.obj_name
502510
)
503511

504512
@mock.patch('runabove.storage.ObjectStored')
@@ -513,6 +521,23 @@ def test_data(self, mock_obj):
513521
)
514522
self.assertEqual(data, fake_data)
515523

524+
@mock.patch('runabove.storage.ObjectStored')
525+
def test_get_meta(self, mock_obj):
526+
fake_meta = {'X-meta': 'meta'}
527+
mock_obj._meta = fake_meta
528+
self.mock_container.get_object_by_name.return_value = mock_obj
529+
meta = self.obj.meta
530+
self.mock_container.get_object_by_name.assert_called_once_with(
531+
self.obj.name,
532+
download=False
533+
)
534+
self.assertEqual(meta, fake_meta)
535+
536+
@mock.patch('runabove.storage.ContainerManager._swift_call')
537+
def test_set_meta(self, mock_swift_call):
538+
fake_meta = {'X-meta': 'meta'}
539+
self.obj.meta = fake_meta
540+
516541
@mock.patch('runabove.storage.ObjectStored')
517542
def test_data_already_downloaded(self, mock_obj):
518543
fake_data = 'SomeData'

0 commit comments

Comments
 (0)