diff options
author | William Schwartz <wkschwartz@gmail.com> | 2015-06-18 10:12:07 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-07-02 13:53:51 -0400 |
commit | 9a5cfa05a0d889db9daa7872a9697daa883f3609 (patch) | |
tree | 49a9eaecdde0c2d36d39803ce3e73672fd1636ea /tests/bulk_create | |
parent | fedef7b2c6e80e1e58b028cf9c03267a8950bf6f (diff) | |
download | django-9a5cfa05a0d889db9daa7872a9697daa883f3609.tar.gz |
Fixed #24997 -- Enabled bulk_create() on proxy models
Diffstat (limited to 'tests/bulk_create')
-rw-r--r-- | tests/bulk_create/models.py | 19 | ||||
-rw-r--r-- | tests/bulk_create/tests.py | 46 |
2 files changed, 51 insertions, 14 deletions
diff --git a/tests/bulk_create/models.py b/tests/bulk_create/models.py index fcc4b4177e..22d16e75e5 100644 --- a/tests/bulk_create/models.py +++ b/tests/bulk_create/models.py @@ -6,6 +6,25 @@ class Country(models.Model): iso_two_letter = models.CharField(max_length=2) +class ProxyCountry(Country): + class Meta: + proxy = True + + +class ProxyProxyCountry(ProxyCountry): + class Meta: + proxy = True + + +class ProxyMultiCountry(ProxyCountry): + pass + + +class ProxyMultiProxyCountry(ProxyMultiCountry): + class Meta: + proxy = True + + class Place(models.Model): name = models.CharField(max_length=100) diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py index 924e69e0a5..3a0c654112 100644 --- a/tests/bulk_create/tests.py +++ b/tests/bulk_create/tests.py @@ -7,7 +7,10 @@ from django.test import ( TestCase, override_settings, skipIfDBFeature, skipUnlessDBFeature, ) -from .models import Country, Pizzeria, Restaurant, State, TwoFields +from .models import ( + Country, Pizzeria, ProxyCountry, ProxyMultiCountry, ProxyMultiProxyCountry, + ProxyProxyCountry, Restaurant, State, TwoFields, +) class BulkCreateTests(TestCase): @@ -35,21 +38,36 @@ class BulkCreateTests(TestCase): with self.assertNumQueries(1): Country.objects.bulk_create(self.data) - def test_inheritance(self): - Restaurant.objects.bulk_create([ - Restaurant(name="Nicholas's") - ]) - self.assertQuerysetEqual(Restaurant.objects.all(), [ - "Nicholas's", - ], attrgetter("name")) - with self.assertRaises(ValueError): + def test_multi_table_inheritance_unsupported(self): + expected_message = "Can't bulk create a multi-table inherited model" + with self.assertRaisesMessage(ValueError, expected_message): Pizzeria.objects.bulk_create([ - Pizzeria(name="The Art of Pizza") + Pizzeria(name="The Art of Pizza"), ]) - self.assertQuerysetEqual(Pizzeria.objects.all(), []) - self.assertQuerysetEqual(Restaurant.objects.all(), [ - "Nicholas's", - ], attrgetter("name")) + with self.assertRaisesMessage(ValueError, expected_message): + ProxyMultiCountry.objects.bulk_create([ + ProxyMultiCountry(name="Fillory", iso_two_letter="FL"), + ]) + with self.assertRaisesMessage(ValueError, expected_message): + ProxyMultiProxyCountry.objects.bulk_create([ + ProxyMultiProxyCountry(name="Fillory", iso_two_letter="FL"), + ]) + + def test_proxy_inheritance_supported(self): + ProxyCountry.objects.bulk_create([ + ProxyCountry(name="Qwghlm", iso_two_letter="QW"), + Country(name="Tortall", iso_two_letter="TA"), + ]) + self.assertQuerysetEqual(ProxyCountry.objects.all(), { + "Qwghlm", "Tortall" + }, attrgetter("name"), ordered=False) + + ProxyProxyCountry.objects.bulk_create([ + ProxyProxyCountry(name="Neitherlands", iso_two_letter="NT"), + ]) + self.assertQuerysetEqual(ProxyProxyCountry.objects.all(), { + "Qwghlm", "Tortall", "Neitherlands", + }, attrgetter("name"), ordered=False) def test_non_auto_increment_pk(self): State.objects.bulk_create([ |