Use more specific asserts in test/probe tests
I changed asserts with more specific assert methods. e.g.: from assertTrue(sth == None) to assertIsNone(*) or assertTrue(isinstance(inst, type)) to assertIsInstace(inst, type) or assertTrue(not sth) to assertFalse(sth). The code gets more readable, and a better description will be shown on fail. Change-Id: I3768faa568e3964e726ecc48ac8cb133cb088284
This commit is contained in:
parent
fb910954b2
commit
300d388825
@ -85,8 +85,8 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
|
|||||||
found_policy_indexes = \
|
found_policy_indexes = \
|
||||||
set(metadata['X-Backend-Storage-Policy-Index'] for
|
set(metadata['X-Backend-Storage-Policy-Index'] for
|
||||||
node, metadata in head_responses)
|
node, metadata in head_responses)
|
||||||
self.assertTrue(
|
self.assertGreater(
|
||||||
len(found_policy_indexes) > 1,
|
len(found_policy_indexes), 1,
|
||||||
'primary nodes did not disagree about policy index %r' %
|
'primary nodes did not disagree about policy index %r' %
|
||||||
head_responses)
|
head_responses)
|
||||||
# find our object
|
# find our object
|
||||||
@ -123,7 +123,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
|
|||||||
found_policy_indexes = \
|
found_policy_indexes = \
|
||||||
set(metadata['X-Backend-Storage-Policy-Index'] for
|
set(metadata['X-Backend-Storage-Policy-Index'] for
|
||||||
node, metadata in head_responses)
|
node, metadata in head_responses)
|
||||||
self.assertTrue(len(found_policy_indexes) == 1,
|
self.assertEqual(len(found_policy_indexes), 1,
|
||||||
'primary nodes disagree about policy index %r' %
|
'primary nodes disagree about policy index %r' %
|
||||||
head_responses)
|
head_responses)
|
||||||
|
|
||||||
@ -172,8 +172,8 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
|
|||||||
found_policy_indexes = \
|
found_policy_indexes = \
|
||||||
set(metadata['X-Backend-Storage-Policy-Index'] for
|
set(metadata['X-Backend-Storage-Policy-Index'] for
|
||||||
node, metadata in head_responses)
|
node, metadata in head_responses)
|
||||||
self.assertTrue(
|
self.assertGreater(
|
||||||
len(found_policy_indexes) > 1,
|
len(found_policy_indexes), 1,
|
||||||
'primary nodes did not disagree about policy index %r' %
|
'primary nodes did not disagree about policy index %r' %
|
||||||
head_responses)
|
head_responses)
|
||||||
# find our object
|
# find our object
|
||||||
@ -215,7 +215,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
|
|||||||
new_found_policy_indexes = \
|
new_found_policy_indexes = \
|
||||||
set(metadata['X-Backend-Storage-Policy-Index'] for node,
|
set(metadata['X-Backend-Storage-Policy-Index'] for node,
|
||||||
metadata in head_responses)
|
metadata in head_responses)
|
||||||
self.assertTrue(len(new_found_policy_indexes) == 1,
|
self.assertEqual(len(new_found_policy_indexes), 1,
|
||||||
'primary nodes disagree about policy index %r' %
|
'primary nodes disagree about policy index %r' %
|
||||||
dict((node['port'],
|
dict((node['port'],
|
||||||
metadata['X-Backend-Storage-Policy-Index'])
|
metadata['X-Backend-Storage-Policy-Index'])
|
||||||
|
@ -56,7 +56,7 @@ class TestObjectAsyncUpdate(ReplProbeTest):
|
|||||||
# Assert the other primary server now knows about container/obj
|
# Assert the other primary server now knows about container/obj
|
||||||
objs = [o['name'] for o in direct_client.direct_get_container(
|
objs = [o['name'] for o in direct_client.direct_get_container(
|
||||||
cnode, cpart, self.account, container)[1]]
|
cnode, cpart, self.account, container)[1]]
|
||||||
self.assertTrue(obj in objs)
|
self.assertIn(obj, objs)
|
||||||
|
|
||||||
|
|
||||||
class TestUpdateOverrides(ReplProbeTest):
|
class TestUpdateOverrides(ReplProbeTest):
|
||||||
|
@ -97,7 +97,7 @@ class TestObjectExpirer(ReplProbeTest):
|
|||||||
self.account, self.container_name, self.object_name,
|
self.account, self.container_name, self.object_name,
|
||||||
acceptable_statuses=(4,),
|
acceptable_statuses=(4,),
|
||||||
headers={'X-Backend-Storage-Policy-Index': int(old_policy)})
|
headers={'X-Backend-Storage-Policy-Index': int(old_policy)})
|
||||||
self.assertTrue('x-backend-timestamp' in metadata)
|
self.assertIn('x-backend-timestamp', metadata)
|
||||||
self.assertEqual(Timestamp(metadata['x-backend-timestamp']),
|
self.assertEqual(Timestamp(metadata['x-backend-timestamp']),
|
||||||
create_timestamp)
|
create_timestamp)
|
||||||
|
|
||||||
@ -126,8 +126,8 @@ class TestObjectExpirer(ReplProbeTest):
|
|||||||
self.fail('found object in %s and also %s' %
|
self.fail('found object in %s and also %s' %
|
||||||
(found_in_policy, policy))
|
(found_in_policy, policy))
|
||||||
found_in_policy = policy
|
found_in_policy = policy
|
||||||
self.assertTrue('x-backend-timestamp' in metadata)
|
self.assertIn('x-backend-timestamp', metadata)
|
||||||
self.assertTrue(Timestamp(metadata['x-backend-timestamp']) >
|
self.assertGreater(Timestamp(metadata['x-backend-timestamp']),
|
||||||
create_timestamp)
|
create_timestamp)
|
||||||
|
|
||||||
def test_expirer_object_should_not_be_expired(self):
|
def test_expirer_object_should_not_be_expired(self):
|
||||||
|
@ -76,7 +76,7 @@ class Test(ReplProbeTest):
|
|||||||
self.object_name, i)
|
self.object_name, i)
|
||||||
if info_i:
|
if info_i:
|
||||||
obj_info.append(info_i)
|
obj_info.append(info_i)
|
||||||
self.assertTrue(len(obj_info) > 1)
|
self.assertGreater(len(obj_info), 1)
|
||||||
for other in obj_info[1:]:
|
for other in obj_info[1:]:
|
||||||
self.assertDictEqual(obj_info[0], other)
|
self.assertDictEqual(obj_info[0], other)
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class Test(ReplProbeTest):
|
|||||||
info_i = self._get_db_info(self.account, self.container_name, i)
|
info_i = self._get_db_info(self.account, self.container_name, i)
|
||||||
if info_i:
|
if info_i:
|
||||||
db_info.append(info_i)
|
db_info.append(info_i)
|
||||||
self.assertTrue(len(db_info) > 1)
|
self.assertGreater(len(db_info), 1)
|
||||||
for other in db_info[1:]:
|
for other in db_info[1:]:
|
||||||
self.assertEqual(db_info[0]['hash'], other['hash'],
|
self.assertEqual(db_info[0]['hash'], other['hash'],
|
||||||
'Container db hash mismatch: %s != %s'
|
'Container db hash mismatch: %s != %s'
|
||||||
@ -275,7 +275,7 @@ class Test(ReplProbeTest):
|
|||||||
self._put_object(headers=sysmeta)
|
self._put_object(headers=sysmeta)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in sysmeta:
|
for key in sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta[key])
|
self.assertEqual(metadata[key], sysmeta[key])
|
||||||
self.brain.start_primary_half()
|
self.brain.start_primary_half()
|
||||||
self.container_brain.start_primary_half()
|
self.container_brain.start_primary_half()
|
||||||
@ -286,15 +286,15 @@ class Test(ReplProbeTest):
|
|||||||
self._put_object(headers=sysmeta2)
|
self._put_object(headers=sysmeta2)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in sysmeta2:
|
for key in sysmeta2:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta2[key])
|
self.assertEqual(metadata[key], sysmeta2[key])
|
||||||
self._post_object(usermeta)
|
self._post_object(usermeta)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in usermeta:
|
for key in usermeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], usermeta[key])
|
self.assertEqual(metadata[key], usermeta[key])
|
||||||
for key in sysmeta2:
|
for key in sysmeta2:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta2[key])
|
self.assertEqual(metadata[key], sysmeta2[key])
|
||||||
|
|
||||||
self.brain.start_handoff_half()
|
self.brain.start_handoff_half()
|
||||||
@ -308,10 +308,10 @@ class Test(ReplProbeTest):
|
|||||||
self.container_brain.stop_primary_half()
|
self.container_brain.stop_primary_half()
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in usermeta:
|
for key in usermeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], usermeta[key])
|
self.assertEqual(metadata[key], usermeta[key])
|
||||||
for key in sysmeta2.keys():
|
for key in sysmeta2.keys():
|
||||||
self.assertTrue(key in metadata, key)
|
self.assertIn(key, metadata, key)
|
||||||
self.assertEqual(metadata[key], sysmeta2[key])
|
self.assertEqual(metadata[key], sysmeta2[key])
|
||||||
self.brain.start_primary_half()
|
self.brain.start_primary_half()
|
||||||
self.container_brain.start_primary_half()
|
self.container_brain.start_primary_half()
|
||||||
@ -321,10 +321,10 @@ class Test(ReplProbeTest):
|
|||||||
self.container_brain.stop_handoff_half()
|
self.container_brain.stop_handoff_half()
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in usermeta:
|
for key in usermeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], usermeta[key])
|
self.assertEqual(metadata[key], usermeta[key])
|
||||||
for key in sysmeta2.keys():
|
for key in sysmeta2.keys():
|
||||||
self.assertTrue(key in metadata, key)
|
self.assertIn(key, metadata, key)
|
||||||
self.assertEqual(metadata[key], sysmeta2[key])
|
self.assertEqual(metadata[key], sysmeta2[key])
|
||||||
self.brain.start_handoff_half()
|
self.brain.start_handoff_half()
|
||||||
self.container_brain.start_handoff_half()
|
self.container_brain.start_handoff_half()
|
||||||
@ -347,7 +347,7 @@ class Test(ReplProbeTest):
|
|||||||
self._put_object(headers=sysmeta)
|
self._put_object(headers=sysmeta)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in sysmeta:
|
for key in sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta[key])
|
self.assertEqual(metadata[key], sysmeta[key])
|
||||||
self.brain.start_primary_half()
|
self.brain.start_primary_half()
|
||||||
self.container_brain.start_primary_half()
|
self.container_brain.start_primary_half()
|
||||||
@ -360,10 +360,10 @@ class Test(ReplProbeTest):
|
|||||||
self._post_object(user_and_transient_sysmeta)
|
self._post_object(user_and_transient_sysmeta)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in user_and_transient_sysmeta:
|
for key in user_and_transient_sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], user_and_transient_sysmeta[key])
|
self.assertEqual(metadata[key], user_and_transient_sysmeta[key])
|
||||||
for key in sysmeta:
|
for key in sysmeta:
|
||||||
self.assertFalse(key in metadata)
|
self.assertNotIn(key, metadata)
|
||||||
self.brain.start_handoff_half()
|
self.brain.start_handoff_half()
|
||||||
self.container_brain.start_handoff_half()
|
self.container_brain.start_handoff_half()
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ class Test(ReplProbeTest):
|
|||||||
expected.update(usermeta)
|
expected.update(usermeta)
|
||||||
expected.update(transient_sysmeta)
|
expected.update(transient_sysmeta)
|
||||||
for key in expected.keys():
|
for key in expected.keys():
|
||||||
self.assertTrue(key in metadata, key)
|
self.assertIn(key, metadata, key)
|
||||||
self.assertEqual(metadata[key], expected[key])
|
self.assertEqual(metadata[key], expected[key])
|
||||||
self.brain.start_primary_half()
|
self.brain.start_primary_half()
|
||||||
self.container_brain.start_primary_half()
|
self.container_brain.start_primary_half()
|
||||||
@ -389,7 +389,7 @@ class Test(ReplProbeTest):
|
|||||||
self.container_brain.stop_handoff_half()
|
self.container_brain.stop_handoff_half()
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in expected.keys():
|
for key in expected.keys():
|
||||||
self.assertTrue(key in metadata, key)
|
self.assertIn(key, metadata, key)
|
||||||
self.assertEqual(metadata[key], expected[key])
|
self.assertEqual(metadata[key], expected[key])
|
||||||
self.brain.start_handoff_half()
|
self.brain.start_handoff_half()
|
||||||
self.container_brain.start_handoff_half()
|
self.container_brain.start_handoff_half()
|
||||||
@ -415,7 +415,7 @@ class Test(ReplProbeTest):
|
|||||||
self._post_object(user_and_transient_sysmeta)
|
self._post_object(user_and_transient_sysmeta)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in user_and_transient_sysmeta:
|
for key in user_and_transient_sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], user_and_transient_sysmeta[key])
|
self.assertEqual(metadata[key], user_and_transient_sysmeta[key])
|
||||||
self.brain.start_handoff_half()
|
self.brain.start_handoff_half()
|
||||||
self.container_brain.start_handoff_half()
|
self.container_brain.start_handoff_half()
|
||||||
@ -426,7 +426,7 @@ class Test(ReplProbeTest):
|
|||||||
self._put_object(headers=sysmeta)
|
self._put_object(headers=sysmeta)
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in sysmeta:
|
for key in sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta[key])
|
self.assertEqual(metadata[key], sysmeta[key])
|
||||||
self.brain.start_primary_half()
|
self.brain.start_primary_half()
|
||||||
self.container_brain.start_primary_half()
|
self.container_brain.start_primary_half()
|
||||||
@ -440,10 +440,10 @@ class Test(ReplProbeTest):
|
|||||||
self.container_brain.stop_primary_half()
|
self.container_brain.stop_primary_half()
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in sysmeta:
|
for key in sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta[key])
|
self.assertEqual(metadata[key], sysmeta[key])
|
||||||
for key in user_and_transient_sysmeta:
|
for key in user_and_transient_sysmeta:
|
||||||
self.assertFalse(key in metadata)
|
self.assertNotIn(key, metadata)
|
||||||
self.brain.start_primary_half()
|
self.brain.start_primary_half()
|
||||||
self.container_brain.start_primary_half()
|
self.container_brain.start_primary_half()
|
||||||
|
|
||||||
@ -453,10 +453,10 @@ class Test(ReplProbeTest):
|
|||||||
self.container_brain.stop_handoff_half()
|
self.container_brain.stop_handoff_half()
|
||||||
metadata = self._get_object_metadata()
|
metadata = self._get_object_metadata()
|
||||||
for key in sysmeta:
|
for key in sysmeta:
|
||||||
self.assertTrue(key in metadata)
|
self.assertIn(key, metadata)
|
||||||
self.assertEqual(metadata[key], sysmeta[key])
|
self.assertEqual(metadata[key], sysmeta[key])
|
||||||
for key in user_and_transient_sysmeta:
|
for key in user_and_transient_sysmeta:
|
||||||
self.assertFalse(key in metadata)
|
self.assertNotIn(key, metadata)
|
||||||
self.brain.start_handoff_half()
|
self.brain.start_handoff_half()
|
||||||
self.container_brain.start_handoff_half()
|
self.container_brain.start_handoff_half()
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class TestReconstructorPropDurable(ECProbeTest):
|
|||||||
self.container_name,
|
self.container_name,
|
||||||
self.object_name)
|
self.object_name)
|
||||||
for key in headers_post:
|
for key in headers_post:
|
||||||
self.assertTrue(key in meta)
|
self.assertIn(key, meta)
|
||||||
self.assertEqual(meta[key], headers_post[key])
|
self.assertEqual(meta[key], headers_post[key])
|
||||||
|
|
||||||
def _format_node(self, node):
|
def _format_node(self, node):
|
||||||
|
@ -122,7 +122,7 @@ class TestReconstructorRebuild(ECProbeTest):
|
|||||||
self.container_name,
|
self.container_name,
|
||||||
self.object_name)
|
self.object_name)
|
||||||
for key in headers_post:
|
for key in headers_post:
|
||||||
self.assertTrue(key in meta)
|
self.assertIn(key, meta)
|
||||||
self.assertEqual(meta[key], headers_post[key])
|
self.assertEqual(meta[key], headers_post[key])
|
||||||
|
|
||||||
def _format_node(self, node):
|
def _format_node(self, node):
|
||||||
|
@ -143,7 +143,7 @@ class TestReconstructorRevert(ECProbeTest):
|
|||||||
self.container_name,
|
self.container_name,
|
||||||
self.object_name)
|
self.object_name)
|
||||||
for key in headers_post:
|
for key in headers_post:
|
||||||
self.assertTrue(key in meta)
|
self.assertIn(key, meta)
|
||||||
self.assertEqual(meta[key], headers_post[key])
|
self.assertEqual(meta[key], headers_post[key])
|
||||||
|
|
||||||
# handoffs are empty
|
# handoffs are empty
|
||||||
|
@ -136,10 +136,10 @@ class TestReplicatorFunctions(ReplProbeTest):
|
|||||||
try:
|
try:
|
||||||
# Check replicate files and dir
|
# Check replicate files and dir
|
||||||
for files in test_node_files_list:
|
for files in test_node_files_list:
|
||||||
self.assertTrue(files in new_files_list[0])
|
self.assertIn(files, new_files_list[0])
|
||||||
|
|
||||||
for dir in test_node_dir_list:
|
for dir in test_node_dir_list:
|
||||||
self.assertTrue(dir in new_dir_list[0])
|
self.assertIn(dir, new_dir_list[0])
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
if time.time() - begin > 60:
|
if time.time() - begin > 60:
|
||||||
@ -184,10 +184,10 @@ class TestReplicatorFunctions(ReplProbeTest):
|
|||||||
|
|
||||||
# Check replicate files and dirs
|
# Check replicate files and dirs
|
||||||
for files in test_node_files_list:
|
for files in test_node_files_list:
|
||||||
self.assertTrue(files in new_files_list[0])
|
self.assertIn(files, new_files_list[0])
|
||||||
|
|
||||||
for directory in test_node_dir_list:
|
for directory in test_node_dir_list:
|
||||||
self.assertTrue(directory in new_dir_list[0])
|
self.assertIn(directory, new_dir_list[0])
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
if time.time() - begin > 60:
|
if time.time() - begin > 60:
|
||||||
|
Loading…
Reference in New Issue
Block a user