Arthur 1 月之前
父節點
當前提交
6fece9cfc2
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      netbox/utilities/testing/base.py

+ 5 - 1
netbox/utilities/testing/base.py

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