Author: PaulM
Date: 2010-08-23 20:03:51 -0500 (Mon, 23 Aug 2010)
New Revision: 13635

Added:
   
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/tests.py
Modified:
   
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/models.py
Log:
[soc2010/test-refactor] converted custom_managers_regress


Modified: 
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/models.py
===================================================================
--- 
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/models.py
       2010-08-23 13:51:49 UTC (rev 13634)
+++ 
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/models.py
       2010-08-24 01:03:51 UTC (rev 13635)
@@ -38,45 +38,3 @@
 
     def __unicode__(self):
         return self.name
-
-__test__ = {"tests": """
-Even though the default manager filters out some records, we must still be able
-to save (particularly, save by updating existing records) those filtered
-instances. This is a regression test for #8990, #9527
->>> related = RelatedModel.objects.create(name="xyzzy")
->>> obj = RestrictedModel.objects.create(name="hidden", related=related)
->>> obj.name = "still hidden"
->>> obj.save()
-
-# If the hidden object wasn't seen during the save process, there would now be
-# two objects in the database.
->>> RestrictedModel.plain_manager.count()
-1
-
-Deleting related objects should also not be distracted by a restricted manager
-on the related object. This is a regression test for #2698.
->>> RestrictedModel.plain_manager.all().delete()
->>> for name, public in (('one', True), ('two', False), ('three', False)):
-...     _ = RestrictedModel.objects.create(name=name, is_public=public, 
related=related)
-
-# Reload the RelatedModel instance, just to avoid any instance artifacts.
->>> obj = RelatedModel.objects.get(name="xyzzy")
->>> obj.delete()
-
-# All of the RestrictedModel instances should have been deleted, since they
-# *all* pointed to the RelatedModel. If the default manager is used, only the
-# public one will be deleted.
->>> RestrictedModel.plain_manager.all()
-[]
-
-# The same test case as the last one, but for one-to-one models, which are
-# implemented slightly different internally, so it's a different code path.
->>> obj = RelatedModel.objects.create(name="xyzzy")
->>> _ = OneToOneRestrictedModel.objects.create(name="foo", is_public=False, 
related=obj)
->>> obj = RelatedModel.objects.get(name="xyzzy")
->>> obj.delete()
->>> OneToOneRestrictedModel.plain_manager.all()
-[]
-
-"""
-}

Added: 
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/tests.py
===================================================================
--- 
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/tests.py
                                (rev 0)
+++ 
django/branches/soc2010/test-refactor/tests/regressiontests/custom_managers_regress/tests.py
        2010-08-24 01:03:51 UTC (rev 13635)
@@ -0,0 +1,47 @@
+from django.test import TestCase
+
+from models import RelatedModel, RestrictedModel, OneToOneRestrictedModel
+
+class CustomManagersRegressTestCase(TestCase):
+    def test_filtered_default_manager(self):
+        """Even though the default manager filters out some records,
+        we must still be able to save (particularly, save by updating
+        existing records) those filtered instances. This is a
+        regression test for #8990, #9527"""
+        related = RelatedModel.objects.create(name="xyzzy")
+        obj = RestrictedModel.objects.create(name="hidden", related=related)
+        obj.name = "still hidden"
+        obj.save()
+
+        # If the hidden object wasn't seen during the save process,
+        # there would now be two objects in the database.
+        self.assertEqual(RestrictedModel.plain_manager.count(), 1)
+
+    def test_delete_related_on_filtered_manager(self):
+        """Deleting related objects should also not be distracted by a
+        restricted manager on the related object. This is a regression
+        test for #2698."""
+        related = RelatedModel.objects.create(name="xyzzy")
+
+        for name, public in (('one', True), ('two', False), ('three', False)):
+            RestrictedModel.objects.create(name=name, is_public=public, 
related=related)
+
+        obj = RelatedModel.objects.get(name="xyzzy")
+        obj.delete()
+
+        # All of the RestrictedModel instances should have been
+        # deleted, since they *all* pointed to the RelatedModel. If
+        # the default manager is used, only the public one will be
+        # deleted.
+        self.assertEqual(len(RestrictedModel.plain_manager.all()), 0)
+
+    def test_delete_one_to_one_manager(self):
+        # The same test case as the last one, but for one-to-one
+        # models, which are implemented slightly different internally,
+        # so it's a different code path.
+        obj = RelatedModel.objects.create(name="xyzzy")
+        OneToOneRestrictedModel.objects.create(name="foo", is_public=False, 
related=obj)
+        obj = RelatedModel.objects.get(name="xyzzy")
+        obj.delete()
+        self.assertEqual(len(OneToOneRestrictedModel.plain_manager.all()), 0)
+

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to