2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-10-14 21:22:20 +00:00

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 ef6d9bd99d.

* fix message
This commit is contained in:
Matthias Mair
2025-10-04 13:59:38 +02:00
committed by GitHub
parent 4f6256011b
commit c070f25d7c
2 changed files with 16 additions and 5 deletions

View File

@@ -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(

View File

@@ -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,