| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from tests.models import CustomNotPrimaryUUIDModel, CustomUUIDModel |
| 6 |
|
| 7 |
|
| 8 |
class UUIDFieldTests(TestCase): |
| 9 |
|
| 10 |
def test_uuid_model_with_uuid_field_as_primary_key(self) -> None: |
| 11 |
instance = CustomUUIDModel() |
| 12 |
instance.save() |
| 13 |
self.assertEqual(instance.id.__class__.__name__, 'UUID') |
| 14 |
self.assertEqual(instance.id, instance.pk) |
| 15 |
|
| 16 |
def test_uuid_model_with_uuid_field_as_not_primary_key(self) -> None: |
| 17 |
instance = CustomNotPrimaryUUIDModel() |
| 18 |
instance.save() |
| 19 |
self.assertEqual(instance.uuid.__class__.__name__, 'UUID') |
| 20 |
self.assertNotEqual(instance.uuid, instance.pk) |