diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2026-03-10 18:46:30 +0100 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-03-13 10:49:38 -0400 |
| commit | 21a16f6af0d12a937093c1b6a95d40708ddaa9a1 (patch) | |
| tree | 665d17c05f2ed342f4f710ba3a90f28760dae2b9 /tests/db_functions | |
| parent | d43bd466e93aad7df13bb94fda4d01bc63b76a45 (diff) | |
Refs #36735 -- Adjusted UUID7 assertions for timezone shifts.
Thanks Simon Charette and Jacob Walls for reviews.
Diffstat (limited to 'tests/db_functions')
| -rw-r--r-- | tests/db_functions/test_uuid.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/db_functions/test_uuid.py b/tests/db_functions/test_uuid.py index 4071071d2d..601c5abe8d 100644 --- a/tests/db_functions/test_uuid.py +++ b/tests/db_functions/test_uuid.py @@ -34,21 +34,27 @@ class TestUUID(TestCase): @skipUnlessDBFeature("supports_uuid7_function_shift") def test_uuid7_shift(self): + shift = timedelta(minutes=1) now = datetime.now(timezone.utc) - past = datetime(2005, 11, 16, tzinfo=timezone.utc) - shift = past - now m = UUIDModel.objects.create(uuid=UUID7(shift)) - self.assertTrue(str(m.uuid).startswith("0107965e-e40"), m.uuid) + ts = int.from_bytes(m.uuid.bytes[:6]) + uuid_timestamp = datetime.fromtimestamp(ts / 1000, tz=timezone.utc) + self.assertAlmostEqual( + (uuid_timestamp - now).total_seconds(), shift.total_seconds(), places=1 + ) @skipUnlessDBFeature("supports_uuid7_function_shift") def test_uuid7_shift_duration_field(self): - now = datetime.now(timezone.utc) - past = datetime(2005, 11, 16, tzinfo=timezone.utc) - shift = past - now + shift = timedelta(minutes=1) m = UUIDModel.objects.create(shift=shift) + now = datetime.now(timezone.utc) UUIDModel.objects.update(uuid=UUID7("shift")) m.refresh_from_db() - self.assertTrue(str(m.uuid).startswith("0107965e-e40"), m.uuid) + ts = int.from_bytes(m.uuid.bytes[:6]) + uuid_timestamp = datetime.fromtimestamp(ts / 1000, tz=timezone.utc) + self.assertAlmostEqual( + (uuid_timestamp - now).total_seconds(), shift.total_seconds(), places=1 + ) @skipIfDBFeature("supports_uuid4_function") def test_uuid4_unsupported(self): |
