2023-03-21 13:21:03 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2019-02-26 16:36:35 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
2020-11-29 20:58:00 +00:00
|
|
|
from tests.models import CustomNotPrimaryUUIDModel, CustomUUIDModel
|
2019-02-26 16:36:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class UUIDFieldTests(TestCase):
|
|
|
|
|
|
2023-03-22 17:50:18 +00:00
|
|
|
def test_uuid_model_with_uuid_field_as_primary_key(self) -> None:
|
2019-02-26 16:36:35 +00:00
|
|
|
instance = CustomUUIDModel()
|
|
|
|
|
instance.save()
|
|
|
|
|
self.assertEqual(instance.id.__class__.__name__, 'UUID')
|
|
|
|
|
self.assertEqual(instance.id, instance.pk)
|
|
|
|
|
|
2023-03-22 17:50:18 +00:00
|
|
|
def test_uuid_model_with_uuid_field_as_not_primary_key(self) -> None:
|
2019-02-26 16:36:35 +00:00
|
|
|
instance = CustomNotPrimaryUUIDModel()
|
|
|
|
|
instance.save()
|
|
|
|
|
self.assertEqual(instance.uuid.__class__.__name__, 'UUID')
|
|
|
|
|
self.assertNotEqual(instance.uuid, instance.pk)
|