From fc194fc35672cb06bf8d5a30694593703f5c72d5 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 6 Oct 2016 15:19:37 +0100 Subject: [PATCH] fixed API test fragility The base test class `LocalTestCase` will setup base objects for all tests to use but because this is called for each test the IDs of the objects will change between tests. One of the child test classes `TestAPI` has a some static data used to check the response of API calls, however these IDs were hard coded meaning that if the order of the tests changed for any reason the test would fail. To fix this the IDs of the static data have been replaced with the object ID meaning they will always be correct. --- cabot/cabotapp/tests/tests_basic.py | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/cabot/cabotapp/tests/tests_basic.py b/cabot/cabotapp/tests/tests_basic.py index e457430..1c50054 100644 --- a/cabot/cabotapp/tests/tests_basic.py +++ b/cabot/cabotapp/tests/tests_basic.py @@ -536,11 +536,15 @@ class TestAPI(LocalTestCase): 'name': u'Service', 'users_to_notify': [], 'alerts_enabled': True, - 'status_checks': [5, 6, 7], + 'status_checks': [ + self.graphite_check.id, + self.jenkins_check.id, + self.http_check.id + ], 'alerts': [], 'hackpad_id': None, 'instances': [], - 'id': 2, + 'id': self.service.id, 'url': u'', 'overall_status': u'PASSING' }, @@ -550,11 +554,11 @@ class TestAPI(LocalTestCase): 'name': u'Hello', 'users_to_notify': [], 'alerts_enabled': True, - 'status_checks': [8], + 'status_checks': [pingcheck.id], 'alerts': [], 'hackpad_id': None, 'address': u'192.168.0.1', - 'id': 2, + 'id': self.instance.id, 'overall_status': u'PASSING' }, ], @@ -565,7 +569,7 @@ class TestAPI(LocalTestCase): 'importance': u'ERROR', 'frequency': 5, 'debounce': 0, - 'id': 5, + 'id': self.graphite_check.id, 'calculated_status': u'passing', }, { @@ -574,7 +578,7 @@ class TestAPI(LocalTestCase): 'importance': u'ERROR', 'frequency': 5, 'debounce': 0, - 'id': 6, + 'id': self.jenkins_check.id, 'calculated_status': u'passing', }, { @@ -583,7 +587,7 @@ class TestAPI(LocalTestCase): 'importance': u'CRITICAL', 'frequency': 5, 'debounce': 0, - 'id': 7, + 'id': self.http_check.id, 'calculated_status': u'passing', }, { @@ -592,7 +596,7 @@ class TestAPI(LocalTestCase): 'importance': u'ERROR', 'frequency': 5, 'debounce': 0, - 'id': 8, + 'id': pingcheck.id, 'calculated_status': u'passing', }, ], @@ -608,7 +612,7 @@ class TestAPI(LocalTestCase): 'value': u'9.0', 'expected_num_hosts': 0, 'allowed_num_failures': 0, - 'id': 5, + 'id': self.graphite_check.id, 'calculated_status': u'passing', }, ], @@ -626,7 +630,7 @@ class TestAPI(LocalTestCase): 'status_code': u'200', 'timeout': 10, 'verify_ssl_certificate': True, - 'id': 7, + 'id': self.http_check.id, 'calculated_status': u'passing', }, ], @@ -638,7 +642,7 @@ class TestAPI(LocalTestCase): 'frequency': 5, 'debounce': 0, 'max_queued_build_time': 10, - 'id': 6, + 'id': self.jenkins_check.id, 'calculated_status': u'passing', }, ], @@ -649,7 +653,7 @@ class TestAPI(LocalTestCase): 'importance': u'ERROR', 'frequency': 5, 'debounce': 0, - 'id': 8, + 'id': pingcheck.id, 'calculated_status': u'passing', }, ], @@ -664,7 +668,7 @@ class TestAPI(LocalTestCase): 'alerts': [], 'hackpad_id': None, 'instances': [], - 'id': 2, + 'id': self.service.id, 'url': u'', 'overall_status': u'PASSING', }, @@ -678,7 +682,7 @@ class TestAPI(LocalTestCase): 'alerts': [], 'hackpad_id': None, 'address': u'255.255.255.255', - 'id': 2, + 'id': self.instance.id, 'overall_status': u'PASSING', }, ], @@ -694,7 +698,7 @@ class TestAPI(LocalTestCase): 'value': u'2', 'expected_num_hosts': 0, 'allowed_num_failures': 0, - 'id': 5, + 'id': self.graphite_check.id, 'calculated_status': u'passing', }, ], @@ -712,7 +716,7 @@ class TestAPI(LocalTestCase): 'status_code': u'201', 'timeout': 30, 'verify_ssl_certificate': True, - 'id': 7, + 'id': self.http_check.id, 'calculated_status': u'passing', }, ], @@ -724,7 +728,7 @@ class TestAPI(LocalTestCase): 'frequency': 5, 'debounce': 0, 'max_queued_build_time': 37, - 'id': 6, + 'id': self.jenkins_check.id, 'calculated_status': u'passing', }, ], @@ -735,7 +739,7 @@ class TestAPI(LocalTestCase): 'importance': u'CRITICAL', 'frequency': 5, 'debounce': 0, - 'id': 8, + 'id': pingcheck.id, 'calculated_status': u'passing', }, ],