Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Migrated the custom_managers_regress doctests. Thanks to Paul McMillan.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13866 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e2ff11c6a365e5c96d1157876d4bc01ed5ecb8da 1 parent 9d6eeee
Russell Keith-Magee authored September 26, 2010
42  tests/regressiontests/custom_managers_regress/models.py
@@ -38,45 +38,3 @@ class OneToOneRestrictedModel(models.Model):
38 38
 
39 39
     def __unicode__(self):
40 40
         return self.name
41  
-
42  
-__test__ = {"tests": """
43  
-Even though the default manager filters out some records, we must still be able
44  
-to save (particularly, save by updating existing records) those filtered
45  
-instances. This is a regression test for #8990, #9527
46  
->>> related = RelatedModel.objects.create(name="xyzzy")
47  
->>> obj = RestrictedModel.objects.create(name="hidden", related=related)
48  
->>> obj.name = "still hidden"
49  
->>> obj.save()
50  
-
51  
-# If the hidden object wasn't seen during the save process, there would now be
52  
-# two objects in the database.
53  
->>> RestrictedModel.plain_manager.count()
54  
-1
55  
-
56  
-Deleting related objects should also not be distracted by a restricted manager
57  
-on the related object. This is a regression test for #2698.
58  
->>> RestrictedModel.plain_manager.all().delete()
59  
->>> for name, public in (('one', True), ('two', False), ('three', False)):
60  
-...     _ = RestrictedModel.objects.create(name=name, is_public=public, related=related)
61  
-
62  
-# Reload the RelatedModel instance, just to avoid any instance artifacts.
63  
->>> obj = RelatedModel.objects.get(name="xyzzy")
64  
->>> obj.delete()
65  
-
66  
-# All of the RestrictedModel instances should have been deleted, since they
67  
-# *all* pointed to the RelatedModel. If the default manager is used, only the
68  
-# public one will be deleted.
69  
->>> RestrictedModel.plain_manager.all()
70  
-[]
71  
-
72  
-# The same test case as the last one, but for one-to-one models, which are
73  
-# implemented slightly different internally, so it's a different code path.
74  
->>> obj = RelatedModel.objects.create(name="xyzzy")
75  
->>> _ = OneToOneRestrictedModel.objects.create(name="foo", is_public=False, related=obj)
76  
->>> obj = RelatedModel.objects.get(name="xyzzy")
77  
->>> obj.delete()
78  
->>> OneToOneRestrictedModel.plain_manager.all()
79  
-[]
80  
-
81  
-"""
82  
-}
47  tests/regressiontests/custom_managers_regress/tests.py
... ...
@@ -0,0 +1,47 @@
  1
+from django.test import TestCase
  2
+
  3
+from models import RelatedModel, RestrictedModel, OneToOneRestrictedModel
  4
+
  5
+class CustomManagersRegressTestCase(TestCase):
  6
+    def test_filtered_default_manager(self):
  7
+        """Even though the default manager filters out some records,
  8
+        we must still be able to save (particularly, save by updating
  9
+        existing records) those filtered instances. This is a
  10
+        regression test for #8990, #9527"""
  11
+        related = RelatedModel.objects.create(name="xyzzy")
  12
+        obj = RestrictedModel.objects.create(name="hidden", related=related)
  13
+        obj.name = "still hidden"
  14
+        obj.save()
  15
+
  16
+        # If the hidden object wasn't seen during the save process,
  17
+        # there would now be two objects in the database.
  18
+        self.assertEqual(RestrictedModel.plain_manager.count(), 1)
  19
+
  20
+    def test_delete_related_on_filtered_manager(self):
  21
+        """Deleting related objects should also not be distracted by a
  22
+        restricted manager on the related object. This is a regression
  23
+        test for #2698."""
  24
+        related = RelatedModel.objects.create(name="xyzzy")
  25
+
  26
+        for name, public in (('one', True), ('two', False), ('three', False)):
  27
+            RestrictedModel.objects.create(name=name, is_public=public, related=related)
  28
+
  29
+        obj = RelatedModel.objects.get(name="xyzzy")
  30
+        obj.delete()
  31
+
  32
+        # All of the RestrictedModel instances should have been
  33
+        # deleted, since they *all* pointed to the RelatedModel. If
  34
+        # the default manager is used, only the public one will be
  35
+        # deleted.
  36
+        self.assertEqual(len(RestrictedModel.plain_manager.all()), 0)
  37
+
  38
+    def test_delete_one_to_one_manager(self):
  39
+        # The same test case as the last one, but for one-to-one
  40
+        # models, which are implemented slightly different internally,
  41
+        # so it's a different code path.
  42
+        obj = RelatedModel.objects.create(name="xyzzy")
  43
+        OneToOneRestrictedModel.objects.create(name="foo", is_public=False, related=obj)
  44
+        obj = RelatedModel.objects.get(name="xyzzy")
  45
+        obj.delete()
  46
+        self.assertEqual(len(OneToOneRestrictedModel.plain_manager.all()), 0)
  47
+

0 notes on commit e2ff11c

Please sign in to comment.
Something went wrong with that request. Please try again.