mirror of
https://github.com/django/django.git
synced 2025-10-27 15:46:10 +00:00
Fixed #21961 -- Added support for database-level delete options for ForeignKey.
Thanks Simon Charette for pair programming. Co-authored-by: Nick Stefan <NickStefan12@gmail.com> Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com> Co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
@@ -26,7 +26,17 @@ from django.test.utils import isolate_apps
|
||||
from django.utils.formats import localize
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from .models import Article, Car, Count, Event, EventGuide, Location, Site, Vehicle
|
||||
from .models import (
|
||||
Article,
|
||||
Car,
|
||||
Cascade,
|
||||
DBCascade,
|
||||
Event,
|
||||
EventGuide,
|
||||
Location,
|
||||
Site,
|
||||
Vehicle,
|
||||
)
|
||||
|
||||
|
||||
class NestedObjectsTests(TestCase):
|
||||
@@ -34,10 +44,12 @@ class NestedObjectsTests(TestCase):
|
||||
Tests for ``NestedObject`` utility collection.
|
||||
"""
|
||||
|
||||
cascade_model = Cascade
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.n = NestedObjects(using=DEFAULT_DB_ALIAS)
|
||||
cls.objs = [Count.objects.create(num=i) for i in range(5)]
|
||||
cls.objs = [cls.cascade_model.objects.create(num=i) for i in range(5)]
|
||||
|
||||
def _check(self, target):
|
||||
self.assertEqual(self.n.nested(lambda obj: obj.num), target)
|
||||
@@ -103,6 +115,15 @@ class NestedObjectsTests(TestCase):
|
||||
n.collect([Vehicle.objects.first()])
|
||||
|
||||
|
||||
class DBNestedObjectsTests(NestedObjectsTests):
|
||||
"""
|
||||
Exercise NestedObjectsTests but with a model that makes use of DB_CASCADE
|
||||
instead of CASCADE to ensure proper collection of objects takes place.
|
||||
"""
|
||||
|
||||
cascade_model = DBCascade
|
||||
|
||||
|
||||
class UtilsTests(SimpleTestCase):
|
||||
empty_value = "-empty-"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user