Use more specific asserts in tests
Instead of assertTrue and assertFalse use more specific asserts. They are compatible with Python 2.7[1] and 3.4[2] [1]: https://docs.python.org/2.7/library/unittest.html [2]: https://docs.python.org/3.4/library/unittest.html Change-Id: Id9f73e90f0786ef7576edd2f97aa31b1503c14dd
This commit is contained in:
parent
5628e24de3
commit
ffd2fea754
@ -259,7 +259,7 @@ class BaseNotificationTest(test_v3.RestfulTestCase):
|
||||
# return since this assertion is not valid.
|
||||
if CONF.notification_format != 'basic':
|
||||
return
|
||||
self.assertTrue(len(self._notifications) > 0)
|
||||
self.assertGreater(len(self._notifications), 0)
|
||||
note = self._notifications[-1]
|
||||
self.assertEqual(operation, note['operation'])
|
||||
self.assertEqual(resource_id, note['resource_id'])
|
||||
@ -276,7 +276,7 @@ class BaseNotificationTest(test_v3.RestfulTestCase):
|
||||
# return since this assertion is not valid.
|
||||
if CONF.notification_format != 'cadf':
|
||||
return
|
||||
self.assertTrue(len(self._audits) > 0)
|
||||
self.assertGreater(len(self._audits), 0)
|
||||
audit = self._audits[-1]
|
||||
payload = audit['payload']
|
||||
self.assertEqual(resource_id, payload['resource_info'])
|
||||
@ -289,7 +289,7 @@ class BaseNotificationTest(test_v3.RestfulTestCase):
|
||||
self.assertTrue(audit['send_notification_called'])
|
||||
|
||||
def _assert_initiator_data_is_set(self, operation, resource_type, typeURI):
|
||||
self.assertTrue(len(self._audits) > 0)
|
||||
self.assertGreater(len(self._audits), 0)
|
||||
audit = self._audits[-1]
|
||||
payload = audit['payload']
|
||||
self.assertEqual(self.user_id, payload['initiator']['id'])
|
||||
|
@ -826,7 +826,7 @@ class TestCase(BaseTestCase):
|
||||
|
||||
msg = '%s != %s within %s delta' % (a, b, delta)
|
||||
|
||||
self.assertTrue(abs(a - b).seconds <= delta, msg)
|
||||
self.assertLessEqual(abs(a - b).seconds, delta, msg)
|
||||
|
||||
def assertTimestampEqual(self, expected, value):
|
||||
# Compare two timestamps but ignore the microseconds part
|
||||
|
@ -1311,7 +1311,7 @@ class LimitTests(filtering.FilterTests):
|
||||
# return at least the 20 entries we created (there may be other
|
||||
# entities lying around created by other tests/setup).
|
||||
entities = self._list_entities(entity)()
|
||||
self.assertTrue(len(entities) >= 20)
|
||||
self.assertGreaterEqual(len(entities), 20)
|
||||
self._match_with_list(self.entity_lists[entity], entities)
|
||||
|
||||
def test_list_users_filtered_and_limited(self):
|
||||
|
@ -931,7 +931,7 @@ class SqlFilterTests(SqlTests, identity_tests.FilterTests):
|
||||
"""
|
||||
# Check we have some users
|
||||
users = self.identity_api.list_users()
|
||||
self.assertTrue(len(users) > 0)
|
||||
self.assertGreater(len(users), 0)
|
||||
|
||||
hints = driver_hints.Hints()
|
||||
hints.add_filter('name', "anything' or 'x'='x")
|
||||
@ -949,7 +949,7 @@ class SqlFilterTests(SqlTests, identity_tests.FilterTests):
|
||||
self.assertEqual(0, len(groups))
|
||||
|
||||
groups = self.identity_api.list_groups()
|
||||
self.assertTrue(len(groups) > 0)
|
||||
self.assertGreater(len(groups), 0)
|
||||
|
||||
|
||||
class SqlLimitTests(SqlTests, identity_tests.LimitTests):
|
||||
|
@ -676,7 +676,7 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase,
|
||||
self.assertIsNotNone(token.get('issued_at'))
|
||||
issued_at = self.assertValidISO8601ExtendedFormatDatetime(
|
||||
token['issued_at'])
|
||||
self.assertTrue(issued_at < expires_at)
|
||||
self.assertLess(issued_at, expires_at)
|
||||
|
||||
self.assertIn('user', token)
|
||||
self.assertIn('id', token['user'])
|
||||
@ -831,13 +831,13 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase,
|
||||
|
||||
def assertValidCatalog(self, entity):
|
||||
self.assertIsInstance(entity, list)
|
||||
self.assertTrue(len(entity) > 0)
|
||||
self.assertGreater(len(entity), 0)
|
||||
for service in entity:
|
||||
self.assertIsNotNone(service.get('id'))
|
||||
self.assertIsNotNone(service.get('name'))
|
||||
self.assertIsNotNone(service.get('type'))
|
||||
self.assertNotIn('enabled', service)
|
||||
self.assertTrue(len(service['endpoints']) > 0)
|
||||
self.assertGreater(len(service['endpoints']), 0)
|
||||
for endpoint in service['endpoints']:
|
||||
self.assertIsNotNone(endpoint.get('id'))
|
||||
self.assertIsNotNone(endpoint.get('interface'))
|
||||
|
@ -324,7 +324,7 @@ class IdentityTestFilteredCase(filtering.FilterTests,
|
||||
# Check group table is still there...
|
||||
url_by_name = "/groups"
|
||||
r = self.get(url_by_name, auth=self.auth)
|
||||
self.assertTrue(len(r.result.get('groups')) > 0)
|
||||
self.assertGreater(len(r.result.get('groups')), 0)
|
||||
|
||||
|
||||
class IdentityTestListLimitCase(IdentityTestFilteredCase):
|
||||
|
@ -54,13 +54,13 @@ class OSRevokeTests(test_v3.RestfulTestCase, test_v3.JsonHomeTestMixin):
|
||||
after_time = timeutils.utcnow()
|
||||
event_issued_before = timeutils.normalize_time(
|
||||
timeutils.parse_isotime(event['issued_before']))
|
||||
self.assertTrue(
|
||||
before_time <= event_issued_before,
|
||||
self.assertLessEqual(
|
||||
before_time, event_issued_before,
|
||||
'invalid event issued_before time; %s is not later than %s.' % (
|
||||
utils.isotime(event_issued_before, subsecond=True),
|
||||
utils.isotime(before_time, subsecond=True)))
|
||||
self.assertTrue(
|
||||
event_issued_before <= after_time,
|
||||
self.assertLessEqual(
|
||||
event_issued_before, after_time,
|
||||
'invalid event issued_before time; %s is not earlier than %s.' % (
|
||||
utils.isotime(event_issued_before, subsecond=True),
|
||||
utils.isotime(after_time, subsecond=True)))
|
||||
|
@ -85,8 +85,8 @@ class TrustTests(object):
|
||||
self.assertEqual(new_id, trust_data['id'])
|
||||
self.assertEqual(self.trustee['id'], trust_data['trustee_user_id'])
|
||||
self.assertEqual(self.trustor['id'], trust_data['trustor_user_id'])
|
||||
self.assertTrue(timeutils.normalize_time(trust_data['expires_at']) >
|
||||
timeutils.utcnow())
|
||||
self.assertGreater(timeutils.normalize_time(trust_data['expires_at']),
|
||||
timeutils.utcnow())
|
||||
|
||||
self.assertEqual([{'id': 'member'},
|
||||
{'id': 'other'},
|
||||
|
Loading…
Reference in New Issue
Block a user