Use more specific asserts in test/unit/account tests

I changed asserts with more specific assert methods.
e.g.: from assertTrue(x in y) to assertIn(x, y).

The code gets more readable, and a better description will be shown on fail

Change-Id: Ic20fbff8a7bb2e870c1609d4fa6e6255eabbeced
This commit is contained in:
Alex Szarka 2017-06-22 13:57:11 +02:00
parent 2d18ecdf4b
commit fea24d0a06
3 changed files with 11 additions and 11 deletions

View File

@ -252,9 +252,9 @@ class TestAuditorRealBroker(unittest.TestCase):
error_lines = test_auditor.logger.get_lines_for_level('error')
self.assertEqual(len(error_lines), 1)
error_message = error_lines[0]
self.assertTrue(broker.db_file in error_message)
self.assertTrue('container_count' in error_message)
self.assertTrue('does not match' in error_message)
self.assertIn(broker.db_file, error_message)
self.assertIn('container_count', error_message)
self.assertIn('does not match', error_message)
self.assertEqual(test_auditor.logger.get_increment_counts(),
{'failures': 1})

View File

@ -1062,7 +1062,7 @@ class TestAccountBrokerBeforeMetadata(TestAccountBroker):
conn.execute('SELECT metadata FROM account_stat')
except BaseException as err:
exc = err
self.assertTrue('no such column: metadata' in str(exc))
self.assertIn('no such column: metadata', str(exc))
def tearDown(self):
AccountBroker.create_account_stat_table = \
@ -1149,12 +1149,12 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker):
conn.execute('SELECT storage_policy_index FROM container')
except BaseException as err:
exc = err
self.assertTrue('no such column: storage_policy_index' in str(exc))
self.assertIn('no such column: storage_policy_index', str(exc))
with broker.get() as conn:
try:
conn.execute('SELECT * FROM policy_stat')
except sqlite3.OperationalError as err:
self.assertTrue('no such table: policy_stat' in str(err))
self.assertIn('no such table: policy_stat', str(err))
else:
self.fail('database created with policy_stat table')
@ -1181,7 +1181,7 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker):
''').fetchone()[0]
except sqlite3.OperationalError as err:
# confirm that the table really isn't there
self.assertTrue('no such table: policy_stat' in str(err))
self.assertIn('no such table: policy_stat', str(err))
else:
self.fail('broker did not raise sqlite3.OperationalError '
'trying to select from policy_stat table!')
@ -1330,7 +1330,7 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker):
self.fail('mock exception was not raised')
self.assertEqual(len(called), 1)
self.assertTrue('CREATE TABLE policy_stat' in called[0])
self.assertIn('CREATE TABLE policy_stat', called[0])
# nothing was committed
broker = AccountBroker(db_path, account='a')
@ -1338,7 +1338,7 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker):
try:
conn.execute('SELECT * FROM policy_stat')
except sqlite3.OperationalError as err:
self.assertTrue('no such table: policy_stat' in str(err))
self.assertIn('no such table: policy_stat', str(err))
else:
self.fail('half upgraded database!')
container_count = conn.execute(
@ -1503,7 +1503,7 @@ class AccountBrokerPreTrackContainerCountSetup(object):
''').fetchone()[0]
except sqlite3.OperationalError as err:
# confirm that the column really isn't there
self.assertTrue('no such column: container_count' in str(err))
self.assertIn('no such column: container_count', str(err))
else:
self.fail('broker did not raise sqlite3.OperationalError '
'trying to select container_count from policy_stat!')

View File

@ -2046,7 +2046,7 @@ class TestAccountController(unittest.TestCase):
self.assertEqual(resp.status_int // 100, 2)
for key in resp.headers:
if 'storage-policy' in key.lower():
self.assertTrue(policy.name.lower() in key.lower())
self.assertIn(policy.name.lower(), key.lower())
def test_multiple_policies_in_use(self):
ts = itertools.count()