Improve functional tests and test client
This patch includes a couple of small functional test improvement. A. Change swift_test_client.File.sync_metadata to follow Swift object metadata semantics: swift_test_client.File.sync_metadata is designed to post object user metadata to an object. However, prior to this patch, the swift_test_client.File instance keeps the existing object metadata as its member attribute and if sync_metadata is called, it sends both existing metadata and incomming metadata from caller. It looks to result in the odd state as if Swift keeps the existing metadata when POST object requested. To tell the correct Swift object metadata semantics, when POST object requested, the existing metadata in the stored object should be gone even if no metadata is overwritten. i.e. if POST object with 'X-Object-Meta-Key: Val' to a stored object with 'X-Object-Meta-foo: bar', it will result in an object with 'X-Object-Meta-Key' (note that X-Object-Meta-Foo will be deleted) The prior behavior sometimes make us confused in the reviw [1] so that, this patch fixes it to send only incomming metadata if it's set. B. Check the response status code more strictly for ObjectVersioning case This patch fixes test_versioning_check_acl on both TestObjectVersioning and TestObjectVersioningHistoryMode to assert the response status code explisitly instead of asserting just "ResponseError". (e.g. 403 when trying to delete object from other account) 1: https://review.openstack.org/#/c/360933/1/test/functional/tests.py@4142 Change-Id: Ia3e5b40f17dc0f881b695aa4be39c98b91e2bb06
This commit is contained in:
parent
0c8c764547
commit
03b5e76d09
@ -899,12 +899,10 @@ class File(Base):
|
||||
fobj.close()
|
||||
|
||||
def sync_metadata(self, metadata=None, cfg=None, parms=None):
|
||||
if metadata is None:
|
||||
metadata = {}
|
||||
if cfg is None:
|
||||
cfg = {}
|
||||
|
||||
self.metadata.update(metadata)
|
||||
self.metadata = self.metadata if metadata is None else metadata
|
||||
|
||||
if self.metadata:
|
||||
headers = self.make_headers(cfg=cfg)
|
||||
|
@ -4160,7 +4160,7 @@ class TestObjectVersioning(Base):
|
||||
prev_version.initialize()
|
||||
self.assertEqual("bbbbb", prev_version.read())
|
||||
self.assertEqual(prev_version.content_type, 'text/jibberish02')
|
||||
self.assertIn('foo', prev_version.metadata)
|
||||
self.assertNotIn('foo', prev_version.metadata)
|
||||
self.assertIn('fu', prev_version.metadata)
|
||||
|
||||
# as we delete things, the old contents return
|
||||
@ -4337,7 +4337,9 @@ class TestObjectVersioning(Base):
|
||||
org_token = self.env.account.conn.storage_token
|
||||
self.env.account.conn.storage_token = self.env.conn2.storage_token
|
||||
try:
|
||||
self.assertRaises(ResponseError, versioned_obj.delete)
|
||||
with self.assertRaises(ResponseError) as cm:
|
||||
versioned_obj.delete()
|
||||
self.assertEqual(403, cm.exception.status)
|
||||
finally:
|
||||
self.env.account.conn.storage_token = org_token
|
||||
|
||||
@ -4444,7 +4446,7 @@ class TestObjectVersioningHistoryMode(TestObjectVersioning):
|
||||
prev_version.initialize()
|
||||
self.assertEqual("bbbbb", prev_version.read())
|
||||
self.assertEqual(prev_version.content_type, 'text/jibberish02')
|
||||
self.assertIn('foo', prev_version.metadata)
|
||||
self.assertNotIn('foo', prev_version.metadata)
|
||||
self.assertIn('fu', prev_version.metadata)
|
||||
|
||||
# versioned_obj keeps the newest content
|
||||
@ -4534,7 +4536,9 @@ class TestObjectVersioningHistoryMode(TestObjectVersioning):
|
||||
org_token = self.env.account.conn.storage_token
|
||||
self.env.account.conn.storage_token = self.env.conn2.storage_token
|
||||
try:
|
||||
self.assertRaises(ResponseError, versioned_obj.delete)
|
||||
with self.assertRaises(ResponseError) as cm:
|
||||
versioned_obj.delete()
|
||||
self.assertEqual(403, cm.exception.status)
|
||||
finally:
|
||||
self.env.account.conn.storage_token = org_token
|
||||
|
||||
@ -4542,7 +4546,9 @@ class TestObjectVersioningHistoryMode(TestObjectVersioning):
|
||||
self.assertEqual("bbbbb", versioned_obj.read())
|
||||
|
||||
versioned_obj.delete()
|
||||
self.assertRaises(ResponseError, versioned_obj.read)
|
||||
with self.assertRaises(ResponseError) as cm:
|
||||
versioned_obj.read()
|
||||
self.assertEqual(404, cm.exception.status)
|
||||
|
||||
# we have 3 objects in the versions_container, 'aaaaa', 'bbbbb'
|
||||
# and delete-marker with empty content
|
||||
|
Loading…
Reference in New Issue
Block a user