Use more specific asserts in test/unit/account 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: Icdbf3c63fe8dd6db1129023885655a9f7032d4a7
This commit is contained in:
parent
daea9932d4
commit
87340e5f29
@ -87,7 +87,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
raise Exception('OMG')
|
raise Exception('OMG')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.assertTrue(broker.conn is None)
|
self.assertIsNone(broker.conn)
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
# Test AccountBroker.empty
|
# Test AccountBroker.empty
|
||||||
@ -96,7 +96,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
self.assertTrue(broker.empty())
|
self.assertTrue(broker.empty())
|
||||||
broker.put_container('o', Timestamp.now().internal, 0, 0, 0,
|
broker.put_container('o', Timestamp.now().internal, 0, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
self.assertTrue(not broker.empty())
|
self.assertFalse(broker.empty())
|
||||||
sleep(.00001)
|
sleep(.00001)
|
||||||
broker.put_container('o', 0, Timestamp.now().internal, 0, 0,
|
broker.put_container('o', 0, Timestamp.now().internal, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
@ -106,7 +106,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
# Test AccountBroker.is_status_deleted
|
# Test AccountBroker.is_status_deleted
|
||||||
broker1 = AccountBroker(':memory:', account='a')
|
broker1 = AccountBroker(':memory:', account='a')
|
||||||
broker1.initialize(Timestamp.now().internal)
|
broker1.initialize(Timestamp.now().internal)
|
||||||
self.assertTrue(not broker1.is_status_deleted())
|
self.assertFalse(broker1.is_status_deleted())
|
||||||
broker1.delete_db(Timestamp.now().internal)
|
broker1.delete_db(Timestamp.now().internal)
|
||||||
self.assertTrue(broker1.is_status_deleted())
|
self.assertTrue(broker1.is_status_deleted())
|
||||||
broker2 = AccountBroker(':memory:', account='a')
|
broker2 = AccountBroker(':memory:', account='a')
|
||||||
@ -180,7 +180,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
broker.initialize(start)
|
broker.initialize(start)
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
self.assertEqual(info['put_timestamp'], Timestamp(start).internal)
|
self.assertEqual(info['put_timestamp'], Timestamp(start).internal)
|
||||||
self.assertTrue(Timestamp(info['created_at']) >= start)
|
self.assertGreaterEqual(Timestamp(info['created_at']), start)
|
||||||
self.assertEqual(info['delete_timestamp'], '0')
|
self.assertEqual(info['delete_timestamp'], '0')
|
||||||
if self.__class__ == TestAccountBrokerBeforeMetadata:
|
if self.__class__ == TestAccountBrokerBeforeMetadata:
|
||||||
self.assertEqual(info['status_changed_at'], '0')
|
self.assertEqual(info['status_changed_at'], '0')
|
||||||
@ -193,7 +193,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
broker.delete_db(delete_timestamp)
|
broker.delete_db(delete_timestamp)
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
self.assertEqual(info['put_timestamp'], Timestamp(start).internal)
|
self.assertEqual(info['put_timestamp'], Timestamp(start).internal)
|
||||||
self.assertTrue(Timestamp(info['created_at']) >= start)
|
self.assertGreaterEqual(Timestamp(info['created_at']), start)
|
||||||
self.assertEqual(info['delete_timestamp'], delete_timestamp)
|
self.assertEqual(info['delete_timestamp'], delete_timestamp)
|
||||||
self.assertEqual(info['status_changed_at'], delete_timestamp)
|
self.assertEqual(info['status_changed_at'], delete_timestamp)
|
||||||
|
|
||||||
@ -1217,8 +1217,8 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker):
|
|||||||
''').fetchone()[0]
|
''').fetchone()[0]
|
||||||
except sqlite3.OperationalError as err:
|
except sqlite3.OperationalError as err:
|
||||||
# confirm that the table doesn't have this column
|
# confirm that the table doesn't have this column
|
||||||
self.assertTrue('no such column: storage_policy_index' in
|
self.assertIn('no such column: storage_policy_index',
|
||||||
str(err))
|
str(err))
|
||||||
else:
|
else:
|
||||||
self.fail('broker did not raise sqlite3.OperationalError '
|
self.fail('broker did not raise sqlite3.OperationalError '
|
||||||
'trying to select from storage_policy_index '
|
'trying to select from storage_policy_index '
|
||||||
@ -1591,7 +1591,7 @@ class TestAccountBrokerBeforePerPolicyContainerTrack(
|
|||||||
self.assertEqual(stats['object_count'], 0)
|
self.assertEqual(stats['object_count'], 0)
|
||||||
self.assertEqual(stats['bytes_used'], 0)
|
self.assertEqual(stats['bytes_used'], 0)
|
||||||
# un-migrated dbs should not return container_count
|
# un-migrated dbs should not return container_count
|
||||||
self.assertFalse('container_count' in stats)
|
self.assertNotIn('container_count', stats)
|
||||||
|
|
||||||
# now force the migration
|
# now force the migration
|
||||||
policy_stats = self.broker.get_policy_stats(do_migrations=True)
|
policy_stats = self.broker.get_policy_stats(do_migrations=True)
|
||||||
|
@ -66,8 +66,7 @@ class TestAccountController(unittest.TestCase):
|
|||||||
resp = server_handler.OPTIONS(req)
|
resp = server_handler.OPTIONS(req)
|
||||||
self.assertEqual(200, resp.status_int)
|
self.assertEqual(200, resp.status_int)
|
||||||
for verb in 'OPTIONS GET POST PUT DELETE HEAD REPLICATE'.split():
|
for verb in 'OPTIONS GET POST PUT DELETE HEAD REPLICATE'.split():
|
||||||
self.assertTrue(
|
self.assertIn(verb, resp.headers['Allow'].split(', '))
|
||||||
verb in resp.headers['Allow'].split(', '))
|
|
||||||
self.assertEqual(len(resp.headers['Allow'].split(', ')), 7)
|
self.assertEqual(len(resp.headers['Allow'].split(', ')), 7)
|
||||||
self.assertEqual(resp.headers['Server'],
|
self.assertEqual(resp.headers['Server'],
|
||||||
(server_handler.server_type + '/' + swift_version))
|
(server_handler.server_type + '/' + swift_version))
|
||||||
|
Loading…
Reference in New Issue
Block a user