summaryrefslogtreecommitdiff
path: root/tests/bulk_create
diff options
context:
space:
mode:
authoracrefoot <acrefoot@dropbox.com>2015-08-20 22:38:58 -0700
committerTim Graham <timograham@gmail.com>2016-03-02 14:29:09 -0500
commit04240b23658f8935bbfebacccc23b5e47a1d6c22 (patch)
treef420c8d19fd94bd5317be22366e911d8064b97c8 /tests/bulk_create
parent60633ef3dec8421706c610d8238af2cd679fc915 (diff)
downloaddjango-04240b23658f8935bbfebacccc23b5e47a1d6c22.tar.gz
Refs #19527 -- Allowed QuerySet.bulk_create() to set the primary key of its objects.
PostgreSQL support only. Thanks Vladislav Manchev and alesasnouski for working on the patch.
Diffstat (limited to 'tests/bulk_create')
-rw-r--r--tests/bulk_create/tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py
index f59f335ce0..a7eb725f55 100644
--- a/tests/bulk_create/tests.py
+++ b/tests/bulk_create/tests.py
@@ -198,3 +198,22 @@ class BulkCreateTests(TestCase):
])
bbb = Restaurant.objects.filter(name="betty's beetroot bar")
self.assertEqual(bbb.count(), 1)
+
+ @skipUnlessDBFeature('can_return_ids_from_bulk_insert')
+ def test_set_pk_and_insert_single_item(self):
+ countries = []
+ with self.assertNumQueries(1):
+ countries = Country.objects.bulk_create([self.data[0]])
+ self.assertEqual(len(countries), 1)
+ self.assertEqual(Country.objects.get(pk=countries[0].pk), countries[0])
+
+ @skipUnlessDBFeature('can_return_ids_from_bulk_insert')
+ def test_set_pk_and_query_efficiency(self):
+ countries = []
+ with self.assertNumQueries(1):
+ countries = Country.objects.bulk_create(self.data)
+ self.assertEqual(len(countries), 4)
+ self.assertEqual(Country.objects.get(pk=countries[0].pk), countries[0])
+ self.assertEqual(Country.objects.get(pk=countries[1].pk), countries[1])
+ self.assertEqual(Country.objects.get(pk=countries[2].pk), countries[2])
+ self.assertEqual(Country.objects.get(pk=countries[3].pk), countries[3])