2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-15 16:58:14 +00:00

More unit test tweaks

This commit is contained in:
Oliver Walters
2025-11-26 06:00:33 +00:00
parent a4d16f3621
commit 5408898145
2 changed files with 13 additions and 4 deletions

View File

@@ -343,7 +343,10 @@ def parameter(
Returns:
A Parameter object, or None if not found
"""
if not hasattr(instance, 'parameters'):
if instance is None:
raise ValueError('parameter tag requires a valid Model instance')
if not isinstance(instance, Model) or not hasattr(instance, 'parameters'):
raise TypeError("parameter tag requires a Model with 'parameters' attribute")
return (
@@ -354,7 +357,7 @@ def parameter(
@register.simple_tag()
def part_parametr(instance, parameter_name):
def part_parameter(instance, parameter_name):
"""Included for backwards compatibility - use 'parameter' tag instead.
Ref: https://github.com/inventree/InvenTree/pull/10699

View File

@@ -419,8 +419,14 @@ class ReportTagTest(PartImageTestMixin, InvenTreeTestCase):
# Note, use the 'parameter' and 'part_parameter' tags interchangeably here
self.assertEqual(report_tags.part_parameter(part, 'name'), None)
self.assertEqual(report_tags.parameter(part, 'Template 1'), parameter)
# Test with an invalid part
self.assertEqual(report_tags.parameter(None, 'name'), None)
# Test with a null part
with self.assertRaises(ValueError):
report_tags.parameter(None, 'name')
# Test with an invalid model type
with self.assertRaises(TypeError):
report_tags.parameter(parameter, 'name')
def test_render_currency(self):
"""Test the render_currency template tag."""