mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-06 03:20:56 +00:00
Ensure empty string values are converted to None
This commit is contained in:
@@ -733,6 +733,10 @@ class ParameterTemplateSerializer(
|
|||||||
allow_null=True,
|
allow_null=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_model_type(self, model_type):
|
||||||
|
"""Convert an empty string to None for the model_type field."""
|
||||||
|
return model_type or None
|
||||||
|
|
||||||
|
|
||||||
@register_importer()
|
@register_importer()
|
||||||
class ParameterSerializer(
|
class ParameterSerializer(
|
||||||
|
|||||||
@@ -121,6 +121,19 @@ class ParameterAPITests(InvenTreeAPITestCase):
|
|||||||
self.assertEqual(common.models.ParameterTemplate.objects.count(), N)
|
self.assertEqual(common.models.ParameterTemplate.objects.count(), N)
|
||||||
self.assertFalse(common.models.ParameterTemplate.objects.filter(pk=pk).exists())
|
self.assertFalse(common.models.ParameterTemplate.objects.filter(pk=pk).exists())
|
||||||
|
|
||||||
|
# Let's create a template which does not specify a model_type
|
||||||
|
data = {
|
||||||
|
'name': 'Universal Parameter',
|
||||||
|
'units': '',
|
||||||
|
'description': 'A parameter template for all models',
|
||||||
|
'enabled': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.post(url, data, expected_code=201)
|
||||||
|
|
||||||
|
self.assertIsNone(response.data['model_type'])
|
||||||
|
self.assertFalse(response.data['enabled'])
|
||||||
|
|
||||||
def test_template_filters(self):
|
def test_template_filters(self):
|
||||||
"""Tests for API filters against ParameterTemplate endpoint."""
|
"""Tests for API filters against ParameterTemplate endpoint."""
|
||||||
from company.models import Company
|
from company.models import Company
|
||||||
|
|||||||
@@ -3330,11 +3330,11 @@ class PartTestTemplateTest(PartAPITestBase):
|
|||||||
self.assertIn('Choices must be unique', str(response.data['choices']))
|
self.assertIn('Choices must be unique', str(response.data['choices']))
|
||||||
|
|
||||||
|
|
||||||
class PartParameterTests(PartAPITestBase):
|
class ParameterTests(PartAPITestBase):
|
||||||
"""Unit test for PartParameter API endpoints."""
|
"""Unit test for Parameter API endpoints."""
|
||||||
|
|
||||||
def test_export_data(self):
|
def test_export_data(self):
|
||||||
"""Test data export functionality for PartParameter objects."""
|
"""Test data export functionality for Parameter objects."""
|
||||||
url = reverse('api-parameter-list')
|
url = reverse('api-parameter-list')
|
||||||
|
|
||||||
response = self.options(
|
response = self.options(
|
||||||
|
|||||||
@@ -287,8 +287,8 @@ class ParameterTests(TestCase):
|
|||||||
self.assertAlmostEqual(param.data_numeric, expected, places=2)
|
self.assertAlmostEqual(param.data_numeric, expected, places=2)
|
||||||
|
|
||||||
|
|
||||||
class PartParameterTest(InvenTreeAPITestCase):
|
class ParameterTest(InvenTreeAPITestCase):
|
||||||
"""Tests for the ParParameter API."""
|
"""Tests for the Parameter API."""
|
||||||
|
|
||||||
superuser = True
|
superuser = True
|
||||||
|
|
||||||
@@ -496,7 +496,7 @@ class PartParameterTest(InvenTreeAPITestCase):
|
|||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
|
||||||
class PartParameterFilterTest(InvenTreeAPITestCase):
|
class ParameterFilterTest(InvenTreeAPITestCase):
|
||||||
"""Unit tests for filtering parts by parameter values."""
|
"""Unit tests for filtering parts by parameter values."""
|
||||||
|
|
||||||
superuser = True
|
superuser = True
|
||||||
|
|||||||
Reference in New Issue
Block a user