mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #26521 -- Validated CreateModel bases, fields and managers for duplicates.
This commit is contained in:
committed by
Simon Charette
parent
6729b96d8a
commit
417e083e55
@@ -10,7 +10,7 @@ from django.db.transaction import atomic
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import override_settings, skipUnlessDBFeature
|
||||
|
||||
from .models import FoodManager, FoodQuerySet
|
||||
from .models import FoodManager, FoodQuerySet, UnicodeModel
|
||||
from .test_base import MigrationTestBase
|
||||
|
||||
try:
|
||||
@@ -200,6 +200,60 @@ class OperationTests(OperationTestBase):
|
||||
definition = operation.deconstruct()
|
||||
self.assertNotIn('managers', definition[2])
|
||||
|
||||
def test_create_model_with_duplicate_field_name(self):
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate field in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
[
|
||||
("id", models.AutoField(primary_key=True)),
|
||||
("pink", models.TextField()),
|
||||
("pink", models.IntegerField(default=1)),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_with_duplicate_base(self):
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate base in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=("test_crmo.Pony", "test_crmo.Pony",),
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate base in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=(UnicodeModel, UnicodeModel,),
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate base in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=("test_crmo.Pony", "test_crmo.pony",),
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate base in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=(UnicodeModel, 'migrations.unicodemodel',),
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate base in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
bases=(UnicodeModel, 'migrations.UnicodeModel',),
|
||||
)
|
||||
|
||||
def test_create_model_with_duplicate_manager_name(self):
|
||||
with self.assertRaisesMessage(ValueError, "Found duplicate manager in CreateModel operation."):
|
||||
migrations.CreateModel(
|
||||
"Pony",
|
||||
fields=[],
|
||||
managers=[
|
||||
("objects", models.Manager()),
|
||||
("objects", models.Manager()),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_with_unique_after(self):
|
||||
"""
|
||||
Tests the CreateModel operation directly followed by an
|
||||
|
||||
Reference in New Issue
Block a user