mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #15321 -- Honored ancestors unique checks.
Thanks to Tim for the review.
This commit is contained in:
committed by
Simon Charette
parent
1fc458b5a3
commit
79f27f2b61
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from operator import attrgetter
|
||||
|
||||
from django.core.exceptions import FieldError
|
||||
from django.core.exceptions import FieldError, ValidationError
|
||||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
from django.test import TestCase, TransactionTestCase
|
||||
@@ -12,7 +12,7 @@ from django.utils import six
|
||||
from .models import (
|
||||
Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, Post,
|
||||
Restaurant, Student, Supplier, Worker, MixinModel,
|
||||
Title, Copy, Base, SubBase)
|
||||
Title, Copy, Base, SubBase, GrandParent, GrandChild)
|
||||
|
||||
|
||||
class ModelInheritanceTests(TestCase):
|
||||
@@ -423,3 +423,33 @@ class InheritanceSameModelNameTests(TransactionTestCase):
|
||||
def test_related_name_attribute_exists(self):
|
||||
# The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'.
|
||||
self.assertFalse(hasattr(self.title, 'attached_%(app_label)s_%(class)s_set'))
|
||||
|
||||
|
||||
class InheritanceUniqueTests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.grand_parent = GrandParent.objects.create(
|
||||
email='grand_parent@example.com',
|
||||
first_name='grand',
|
||||
last_name='parent',
|
||||
)
|
||||
|
||||
def test_unique(self):
|
||||
grand_child = GrandChild(
|
||||
email=self.grand_parent.email,
|
||||
first_name='grand',
|
||||
last_name='child',
|
||||
)
|
||||
msg = 'Grand parent with this Email already exists.'
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
grand_child.validate_unique()
|
||||
|
||||
def test_unique_together(self):
|
||||
grand_child = GrandChild(
|
||||
email='grand_child@example.com',
|
||||
first_name=self.grand_parent.first_name,
|
||||
last_name=self.grand_parent.last_name,
|
||||
)
|
||||
msg = 'Grand parent with this First name and Last name already exists.'
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
grand_child.validate_unique()
|
||||
|
||||
Reference in New Issue
Block a user