diff options
Diffstat (limited to 'tests/bulk_create/tests.py')
| -rw-r--r-- | tests/bulk_create/tests.py | 46 |
1 files changed, 32 insertions, 14 deletions
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([ |
