This commit is contained in:
Arthur 2026-07-07 16:42:39 -07:00
parent 3f077df77f
commit 6fece9cfc2
1 changed files with 5 additions and 1 deletions

View File

@ -6,7 +6,7 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.fields import ArrayField, RangeField
from django.core.exceptions import FieldDoesNotExist
from django.db import transaction
from django.db.models import JSONField, ManyToManyField, ManyToManyRel
from django.db.models import DateField, JSONField, ManyToManyField, ManyToManyRel
from django.forms.models import model_to_dict
from django.test import Client
from django.test import TestCase as _TestCase
@ -214,6 +214,10 @@ class ModelTestCase(TestCase):
elif type(value) is IPNetwork:
model_dict[key] = str(value)
# Convert date values to ISO 8601 strings (as rendered by the REST API)
elif type(field) is DateField and value is not None:
model_dict[key] = value.isoformat()
# Normalize arrays of numeric ranges (e.g. VLAN IDs or port ranges).
# DB uses canonical half-open [lo, hi) via NumericRange; API uses inclusive [lo, hi].
# Convert to inclusive pairs for stable API comparisons.