summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_util
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-02-26 13:17:43 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-02-26 13:17:43 +0000
commite12b3199d0c01694ca6b09add5e0f27cadffc8ad (patch)
tree4e5eca74ba0e412830f8a5f51020c623564e4ea5 /tests/regressiontests/admin_util
parent126ca330e230034081182ec8a4bf1f47260b6cb9 (diff)
Fixed #6191, #11296 -- Modified the admin deletion confirmation page to use the same object collection scheme as the actual deletion. This ensures that all objects that may be deleted are actually deleted, and that cyclic display problems are avoided. Thanks to carljm for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12598 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/admin_util')
-rw-r--r--tests/regressiontests/admin_util/models.py3
-rw-r--r--tests/regressiontests/admin_util/tests.py57
2 files changed, 58 insertions, 2 deletions
diff --git a/tests/regressiontests/admin_util/models.py b/tests/regressiontests/admin_util/models.py
index 0c2af585cd..e81f7bbc25 100644
--- a/tests/regressiontests/admin_util/models.py
+++ b/tests/regressiontests/admin_util/models.py
@@ -17,3 +17,6 @@ class Article(models.Model):
def test_from_model_with_override(self):
return "nothing"
test_from_model_with_override.short_description = "not what you expect"
+
+class Count(models.Model):
+ num = models.PositiveSmallIntegerField()
diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py
index 479cfdcb52..43d7057783 100644
--- a/tests/regressiontests/admin_util/tests.py
+++ b/tests/regressiontests/admin_util/tests.py
@@ -2,15 +2,68 @@ from datetime import datetime
import unittest
from django.db import models
+from django.utils.formats import localize
+from django.test import TestCase
from django.contrib import admin
from django.contrib.admin.util import display_for_field, label_for_field, lookup_field
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
from django.contrib.sites.models import Site
-from django.utils.formats import localize
+from django.contrib.admin.util import NestedObjects
+
+from models import Article, Count
+
+
+class NestedObjectsTests(TestCase):
+ """
+ Tests for ``NestedObject`` utility collection.
+
+ """
+ def setUp(self):
+ self.n = NestedObjects()
+ self.objs = [Count.objects.create(num=i) for i in range(5)]
+
+ def _check(self, target):
+ self.assertEquals(self.n.nested(lambda obj: obj.num), target)
+
+ def _add(self, obj, parent=None):
+ # don't bother providing the extra args that NestedObjects ignores
+ self.n.add(None, None, obj, None, parent)
+
+ def test_unrelated_roots(self):
+ self._add(self.objs[0])
+ self._add(self.objs[1])
+ self._add(self.objs[2], self.objs[1])
+
+ self._check([0, 1, [2]])
+
+ def test_siblings(self):
+ self._add(self.objs[0])
+ self._add(self.objs[1], self.objs[0])
+ self._add(self.objs[2], self.objs[0])
+
+ self._check([0, [1, 2]])
+
+ def test_duplicate_instances(self):
+ self._add(self.objs[0])
+ self._add(self.objs[1])
+ dupe = Count.objects.get(num=1)
+ self._add(dupe, self.objs[0])
+
+ self._check([0, 1])
+
+ def test_non_added_parent(self):
+ self._add(self.objs[0], self.objs[1])
+
+ self._check([0])
-from models import Article
+ def test_cyclic(self):
+ self._add(self.objs[0], self.objs[2])
+ self._add(self.objs[1], self.objs[0])
+ self._add(self.objs[2], self.objs[1])
+ self._add(self.objs[0], self.objs[2])
+ self._check([0, [1, [2]]])
class UtilTests(unittest.TestCase):