mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Fix Expression test compatibility for Django 6.0+ (#759)
* Skip incompatible tests on Django 6.0+ refs: - #635 - #646 - https://code.djangoproject.com/ticket/27222 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove skipif * Add changelog --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
572aeebec7
commit
4de16fbd40
2 changed files with 21 additions and 4 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#### Improvements
|
||||
|
||||
- feat: Add audit log history view to Django Admin. ([#743](https://github.com/jazzband/django-auditlog/pull/743))
|
||||
- Fix Expression test compatibility for Django 6.0+ ([#759](https://github.com/jazzband/django-auditlog/pull/759))
|
||||
|
||||
## 3.2.1 (2025-07-03)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from unittest.mock import patch
|
|||
|
||||
import freezegun
|
||||
from dateutil.tz import gettz
|
||||
from django import VERSION as DJANGO_VERSION
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
|
|
@ -1229,15 +1230,30 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.naive_dt = Now()
|
||||
self.assertEqual(dtm.naive_dt, Now())
|
||||
dtm.save()
|
||||
self.assertEqual(dtm.naive_dt, Now())
|
||||
|
||||
# Django 6.0+ evaluates expressions during save (django ticket #27222)
|
||||
if DJANGO_VERSION >= (6, 0, 0):
|
||||
with self.subTest("After save Django 6.0+"):
|
||||
self.assertIsInstance(dtm.naive_dt, datetime.datetime)
|
||||
else:
|
||||
with self.subTest("After save Django < 6.0"):
|
||||
self.assertEqual(dtm.naive_dt, Now())
|
||||
|
||||
def test_json_field_value_none(self):
|
||||
json_model = NullableJSONModel(json=Value(None, JSONField()))
|
||||
json_model.save()
|
||||
self.assertEqual(json_model.history.count(), 1)
|
||||
self.assertEqual(
|
||||
json_model.history.latest().changes_dict["json"][1], "Value(None)"
|
||||
)
|
||||
changes_dict = json_model.history.latest().changes_dict
|
||||
|
||||
# Django 6.0+ evaluates expressions during save (django ticket #27222)
|
||||
if DJANGO_VERSION >= (6, 0, 0):
|
||||
with self.subTest("Django 6.0+"):
|
||||
# Value(None) gets evaluated to "null"
|
||||
self.assertEqual(changes_dict["json"][1], "null")
|
||||
else:
|
||||
with self.subTest("Django < 6.0"):
|
||||
# Value(None) is preserved as string representation
|
||||
self.assertEqual(changes_dict["json"][1], "Value(None)")
|
||||
|
||||
|
||||
class UnregisterTest(TestCase):
|
||||
|
|
|
|||
Loading…
Reference in a new issue