2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-10-25 02:17:37 +00:00

simplify tests

This commit is contained in:
Matthias Mair
2025-10-13 23:55:57 +02:00
parent 3718b5e12c
commit acfe575822
2 changed files with 28 additions and 51 deletions

View File

@@ -1191,29 +1191,16 @@ class BuildListTest(BuildAPITest):
def test_output_options(self): def test_output_options(self):
"""Test the output options for BuildOrderList list.""" """Test the output options for BuildOrderList list."""
url = self.url self.run_output_test(
test_cases = [ self.url,
[
('project_code_detail', 'project_code'), ('project_code_detail', 'project_code'),
('project_code_detail', 'project_code_detail'), 'project_code_detail',
('user_detail', 'responsible_detail'), ('user_detail', 'responsible_detail'),
('user_detail', 'issued_by_detail'), ('user_detail', 'issued_by_detail'),
] ],
additional_params={'limit': 1},
for param, field in test_cases: assert_fnc=lambda x: x.data['results'][0],
# Test with parameter set to 'true'
response = self.get(url, {param: 'true', 'limit': 1}, expected_code=200)
self.assertIn(
field,
response.data['results'][0],
f"Field '{field}' should be present when {param}='true'",
)
# Test with parameter set to 'false'
response = self.get(url, {param: 'false', 'limit': 1}, expected_code=200)
self.assertNotIn(
field,
response.data['results'][0],
f"Field '{field}' should not be present when {param}='false'",
) )

View File

@@ -1397,30 +1397,15 @@ class PartAPITest(PartAPITestBase):
def test_output_options(self): def test_output_options(self):
"""Test the output options for PartList list.""" """Test the output options for PartList list."""
url = reverse('api-part-list') self.run_output_test(
test_cases = [ reverse('api-part-list')[
('location_detail', 'default_location_detail'), ('location_detail', 'default_location_detail'),
('parameters', 'parameters'), 'parameters',
('path_detail', 'category_path'), ('path_detail', 'category_path'),
('pricing', 'pricing_min'), ('pricing', 'pricing_min'),
('pricing', 'pricing_updated'), ('pricing', 'pricing_updated'),
] ],
assert_fnc=lambda x: x.data['results'][0],
for param, field in test_cases:
# Test with parameter set to 'true'
response = self.get(url, {param: 'true', 'limit': 1}, expected_code=200)
self.assertIn(
field,
response.data['results'][0],
f"Field '{field}' should be present when {param}='true'",
)
# Test with parameter set to 'false'
response = self.get(url, {param: 'false', 'limit': 1}, expected_code=200)
self.assertNotIn(
field,
response.data['results'][0],
f"Field '{field}' should not be present when {param}='false'",
) )
@@ -2692,12 +2677,17 @@ class BomItemTest(InvenTreeAPITestCase):
self.assertEqual(int(float(response.data['quantity'])), 57) self.assertEqual(int(float(response.data['quantity'])), 57)
self.assertEqual(response.data['note'], 'Added a note') self.assertEqual(response.data['note'], 'Added a note')
# TODO add test for (pricing, pricing_min)
def test_output_options(self): def test_output_options(self):
"""Test that various output options work as expected.""" """Test that various output options work as expected."""
self.run_output_test( self.run_output_test(
reverse('api-bom-item-detail', kwargs={'pk': 3}), reverse('api-bom-item-detail', kwargs={'pk': 3}),
['can_build', 'part_detail', 'sub_part_detail', 'substitutes'], [
'can_build',
'part_detail',
'sub_part_detail',
'substitutes',
('pricing', 'pricing_min'),
],
) )
def test_add_bom_item(self): def test_add_bom_item(self):