summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnssi Kääriäinen <anssi.kaariainen@thl.fi>2015-01-28 13:40:48 +0200
committerTim Graham <timograham@gmail.com>2015-02-03 09:23:44 -0500
commit8adc59038cdc6ce4f9170e4de2d716d940e136b3 (patch)
treee9a868fd51f6c4d5d9be17391573053ab544c721 /tests
parent118b11221f7f632b4d0e6e976c87f563746ec211 (diff)
Fixed #23617 -- Added get_pk_value_on_save()
The method is mainly intended for use with UUIDField. For UUIDField we want to call the field's default even when primary key value is explicitly set to None to match the behavior of AutoField. Thanks to Marc Tamlyn and Tim Graham for review.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_fields/test_uuid.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/model_fields/test_uuid.py b/tests/model_fields/test_uuid.py
index b5bc37a48d..13fe245be3 100644
--- a/tests/model_fields/test_uuid.py
+++ b/tests/model_fields/test_uuid.py
@@ -87,3 +87,20 @@ class TestAsPrimaryKey(TestCase):
PrimaryKeyUUIDModel.objects.create()
loaded = PrimaryKeyUUIDModel.objects.get()
self.assertIsInstance(loaded.pk, uuid.UUID)
+
+ def test_uuid_pk_on_save(self):
+ saved = PrimaryKeyUUIDModel.objects.create(id=None)
+ loaded = PrimaryKeyUUIDModel.objects.get()
+ self.assertIsNotNone(loaded.id, None)
+ self.assertEqual(loaded.id, saved.id)
+
+ def test_uuid_pk_on_bulk_create(self):
+ u1 = PrimaryKeyUUIDModel()
+ u2 = PrimaryKeyUUIDModel(id=None)
+ PrimaryKeyUUIDModel.objects.bulk_create([u1, u2])
+ # Check that the two objects were correctly created.
+ u1_found = PrimaryKeyUUIDModel.objects.filter(id=u1.id).exists()
+ u2_found = PrimaryKeyUUIDModel.objects.exclude(id=u1.id).exists()
+ self.assertTrue(u1_found)
+ self.assertTrue(u2_found)
+ self.assertEqual(PrimaryKeyUUIDModel.objects.count(), 2)