From c070f25d7c92ff602c7b2f3b34009b1fe612c8e6 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Sat, 4 Oct 2025 13:59:38 +0200 Subject: [PATCH] chore(backend): improve error message in api tests (#10464) * fix mysql apply order * improve error message capabilites for InvenTreeAPITestCase * Revert "fix mysql apply order" This reverts commit ef6d9bd99d0e90d06233d1a7a176ed9a4b916e09. * fix message --- src/backend/InvenTree/InvenTree/unit_test.py | 7 ++++--- src/backend/InvenTree/build/test_api.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/unit_test.py b/src/backend/InvenTree/InvenTree/unit_test.py index b2dfacdad1..7479694132 100644 --- a/src/backend/InvenTree/InvenTree/unit_test.py +++ b/src/backend/InvenTree/InvenTree/unit_test.py @@ -452,7 +452,7 @@ class InvenTreeAPITestCase( ): """Base class for running InvenTree API tests.""" - def check_response(self, url, response, expected_code=None): + def check_response(self, url, response, expected_code=None, msg=None): """Debug output for an unexpected response.""" # Check that the response returned the expected status code @@ -469,7 +469,7 @@ class InvenTreeAPITestCase( if hasattr(response, 'content'): print('content:', response.content) - self.assertEqual(response.status_code, expected_code) + self.assertEqual(response.status_code, expected_code, msg) def getActions(self, url): """Return a dict of the 'actions' available at a given endpoint. @@ -490,6 +490,7 @@ class InvenTreeAPITestCase( kwargs['format'] = kwargs.get('format', 'json') expected_code = kwargs.pop('expected_code', None) + msg = kwargs.pop('msg', None) max_queries = kwargs.pop('max_query_count', self.MAX_QUERY_COUNT) max_query_time = kwargs.pop('max_query_time', self.MAX_QUERY_TIME) @@ -501,7 +502,7 @@ class InvenTreeAPITestCase( t2 = time.time() dt = t2 - t1 - self.check_response(url, response, expected_code=expected_code) + self.check_response(url, response, expected_code=expected_code, msg=msg) if dt > max_query_time: print( diff --git a/src/backend/InvenTree/build/test_api.py b/src/backend/InvenTree/build/test_api.py index 46a2321376..da8ea3c4c9 100644 --- a/src/backend/InvenTree/build/test_api.py +++ b/src/backend/InvenTree/build/test_api.py @@ -1389,7 +1389,12 @@ class BuildLineTests(BuildAPITest): for param, field in test_cases: # Test with parameter set to 'true' - response = self.get(url, {param: 'true'}, expected_code=200) + response = self.get( + url, + {param: 'true'}, + expected_code=200, + msg=f'Testing {param}=true returns anything but 200', + ) self.assertIn( field, response.data, @@ -1397,7 +1402,12 @@ class BuildLineTests(BuildAPITest): ) # Test with parameter set to 'false' - response = self.get(url, {param: 'false'}, expected_code=200) + response = self.get( + url, + {param: 'false'}, + expected_code=200, + msg=f'Testing {param}=false returns anything but 200', + ) self.assertNotIn( field, response.data,