Use more specific asserts

Many places, there are more specific asserts which can be used.
I replaced the generic assert with more specific ones, where
it was possible.

This change enhances readibility, and on fail, more useful
message is displayed

Change-Id: I86a6baeae2cd36610a2be10ae5085555246c368a
This commit is contained in:
Gábor Antal
2016-08-02 14:39:19 +02:00
parent b2656b92c4
commit cc2e805780
6 changed files with 11 additions and 10 deletions

View File

@@ -529,7 +529,7 @@ class TestPost(api_base.FunctionalTest):
expected_error_msg = ('The audit template UUID or name specified is '
'invalid')
self.assertTrue(response.json['error_message'])
self.assertTrue(expected_error_msg in response.json['error_message'])
self.assertIn(expected_error_msg, response.json['error_message'])
@mock.patch.object(deapi.DecisionEngineAPI, 'trigger_audit')
def test_create_audit_doesnt_contain_id(self, mock_trigger_audit):
@@ -598,7 +598,7 @@ class TestPost(api_base.FunctionalTest):
expected_error_msg = ('Interval of audit must be specified '
'for CONTINUOUS.')
self.assertTrue(response.json['error_message'])
self.assertTrue(expected_error_msg in response.json['error_message'])
self.assertIn(expected_error_msg, response.json['error_message'])
@mock.patch.object(deapi.DecisionEngineAPI, 'trigger_audit')
def test_create_oneshot_audit_with_period(self, mock_trigger_audit):
@@ -615,7 +615,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
expected_error_msg = 'Interval of audit must not be set for ONESHOT.'
self.assertTrue(response.json['error_message'])
self.assertTrue(expected_error_msg in response.json['error_message'])
self.assertIn(expected_error_msg, response.json['error_message'])
def test_create_audit_trigger_decision_engine(self):
with mock.patch.object(deapi.DecisionEngineAPI,
@@ -653,7 +653,7 @@ class TestPost(api_base.FunctionalTest):
'strategy for audit template, or no '
'parameter spec in predefined strategy')
self.assertTrue(response.json['error_message'])
self.assertTrue(expected_error_msg in response.json['error_message'])
self.assertIn(expected_error_msg, response.json['error_message'])
assert not mock_trigger_audit.called
@mock.patch.object(deapi.DecisionEngineAPI, 'trigger_audit')
@@ -673,7 +673,7 @@ class TestPost(api_base.FunctionalTest):
'strategy for audit template, or no '
'parameter spec in predefined strategy')
self.assertTrue(response.json['error_message'])
self.assertTrue(expected_error_msg in response.json['error_message'])
self.assertIn(expected_error_msg, response.json['error_message'])
assert not mock_trigger_audit.called

View File

@@ -82,7 +82,7 @@ class TestListGoal(api_base.FunctionalTest):
name='GOAL_{0}'.format(idx))
goal_list.append(goal.uuid)
response = self.get_json('/goals')
self.assertTrue(len(response['goals']) > 2)
self.assertGreater(len(response['goals']), 2)
def test_many_without_soft_deleted(self):
goal_list = []

View File

@@ -111,7 +111,7 @@ class TestUniformAirflow(base.BaseTestCase):
vms = model.get_all_vms()
vms.clear()
vm_to_mig = self.strategy.choose_vm_to_migrate(h1)
self.assertEqual(vm_to_mig, None)
self.assertIsNone(vm_to_mig)
def test_filter_destination_hosts(self):
model = self.fake_cluster.generate_scenario_7_with_2_hypervisors()

View File

@@ -102,7 +102,7 @@ class TestWorkloadBalance(base.BaseTestCase):
vms = model.get_all_vms()
vms.clear()
vm_to_mig = self.strategy.choose_vm_to_migrate(h1, avg, w_map)
self.assertEqual(vm_to_mig, None)
self.assertIsNone(vm_to_mig)
def test_filter_destination_hosts(self):
model = self.fake_cluster.generate_scenario_6_with_2_hypervisors()

View File

@@ -376,7 +376,8 @@ class TestSyncer(base.DbTestCase):
self.assertEqual(2, strategy2.goal_id)
self.assertIn(strategy2.name, created_strategies)
self.assertTrue(strategy2.id != created_strategies[strategy2.name].id)
self.assertNotEqual(strategy2.id,
created_strategies[strategy2.name].id)
self.assertEqual(set([audit_template2.id,
audit_template3.id,

View File

@@ -293,7 +293,7 @@ class TestObjectSerializer(test_base.TestCase):
ser = base.WatcherObjectSerializer()
obj = MyObj(self.context)
primitive = ser.serialize_entity(self.context, obj)
self.assertTrue('watcher_object.name' in primitive)
self.assertIn('watcher_object.name', primitive)
obj2 = ser.deserialize_entity(self.context, primitive)
self.assertIsInstance(obj2, MyObj)
self.assertEqual(self.context, obj2._context)