Author: russellm
Date: 2010-10-11 19:14:49 -0500 (Mon, 11 Oct 2010)
New Revision: 14163
Added:
django/trunk/tests/modeltests/m2o_recursive/tests.py
Removed:
django/trunk/tests/modeltests/m2o_recursive2/
Modified:
django/trunk/tests/modeltests/m2o_recursive/models.py
Log:
Migrated m2o_recursive and m2o_recursive2 tests, merging them into a single
package. Thanks to George Sakkis for the patches.
Modified: django/trunk/tests/modeltests/m2o_recursive/models.py
===================================================================
--- django/trunk/tests/modeltests/m2o_recursive/models.py 2010-10-11
23:57:03 UTC (rev 14162)
+++ django/trunk/tests/modeltests/m2o_recursive/models.py 2010-10-12
00:14:49 UTC (rev 14163)
@@ -19,22 +19,10 @@
def __unicode__(self):
return self.name
-__test__ = {'API_TESTS':"""
-# Create a few Category objects.
->>> r = Category(id=None, name='Root category', parent=None)
->>> r.save()
->>> c = Category(id=None, name='Child category', parent=r)
->>> c.save()
+class Person(models.Model):
+ full_name = models.CharField(max_length=20)
+ mother = models.ForeignKey('self', null=True,
related_name='mothers_child_set')
+ father = models.ForeignKey('self', null=True,
related_name='fathers_child_set')
->>> r.child_set.all()
-[<Category: Child category>]
->>> r.child_set.get(name__startswith='Child')
-<Category: Child category>
->>> print r.parent
-None
-
->>> c.child_set.all()
-[]
->>> c.parent
-<Category: Root category>
-"""}
+ def __unicode__(self):
+ return self.full_name
Added: django/trunk/tests/modeltests/m2o_recursive/tests.py
===================================================================
--- django/trunk/tests/modeltests/m2o_recursive/tests.py
(rev 0)
+++ django/trunk/tests/modeltests/m2o_recursive/tests.py 2010-10-12
00:14:49 UTC (rev 14163)
@@ -0,0 +1,38 @@
+from django.test import TestCase
+from models import Category, Person
+
+class ManyToOneRecursiveTests(TestCase):
+
+ def setUp(self):
+ self.r = Category(id=None, name='Root category', parent=None)
+ self.r.save()
+ self.c = Category(id=None, name='Child category', parent=self.r)
+ self.c.save()
+
+ def test_m2o_recursive(self):
+ self.assertQuerysetEqual(self.r.child_set.all(),
+ ['<Category: Child category>'])
+ self.assertEqual(self.r.child_set.get(name__startswith='Child').id,
self.c.id)
+ self.assertEqual(self.r.parent, None)
+ self.assertQuerysetEqual(self.c.child_set.all(), [])
+ self.assertEqual(self.c.parent.id, self.r.id)
+
+class MultipleManyToOneRecursiveTests(TestCase):
+
+ def setUp(self):
+ self.dad = Person(full_name='John Smith Senior', mother=None,
father=None)
+ self.dad.save()
+ self.mom = Person(full_name='Jane Smith', mother=None, father=None)
+ self.mom.save()
+ self.kid = Person(full_name='John Smith Junior', mother=self.mom,
father=self.dad)
+ self.kid.save()
+
+ def test_m2o_recursive2(self):
+ self.assertEqual(self.kid.mother.id, self.mom.id)
+ self.assertEqual(self.kid.father.id, self.dad.id)
+ self.assertQuerysetEqual(self.dad.fathers_child_set.all(),
+ ['<Person: John Smith Junior>'])
+ self.assertQuerysetEqual(self.mom.mothers_child_set.all(),
+ ['<Person: John Smith Junior>'])
+ self.assertQuerysetEqual(self.kid.mothers_child_set.all(), [])
+ self.assertQuerysetEqual(self.kid.fathers_child_set.all(), [])
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.