summaryrefslogtreecommitdiff
path: root/tests/regressiontests/many_to_one_regress/models.py
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-08-05 17:15:33 +0000
committerJustin Bronn <jbronn@gmail.com>2008-08-05 17:15:33 +0000
commitaa239e3e5405933af6a29dac3cf587b59a099927 (patch)
treeea2cbd139c9a8cf84c09e0b2008bff70e05927ef /tests/regressiontests/many_to_one_regress/models.py
parent45b73c9a4685809236f84046cc7ffd32a50db958 (diff)
gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.archive/attic/gis
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/many_to_one_regress/models.py')
-rw-r--r--tests/regressiontests/many_to_one_regress/models.py52
1 files changed, 45 insertions, 7 deletions
diff --git a/tests/regressiontests/many_to_one_regress/models.py b/tests/regressiontests/many_to_one_regress/models.py
index 429bdd7558..b87b36cb3b 100644
--- a/tests/regressiontests/many_to_one_regress/models.py
+++ b/tests/regressiontests/many_to_one_regress/models.py
@@ -55,31 +55,46 @@ __test__ = {'API_TESTS':"""
<Child: Child object>
#
-# Tests of ForeignKey assignment and the related-object cache (see #6886)
+# Tests of ForeignKey assignment and the related-object cache (see #6886).
#
>>> p = Parent.objects.create(name="Parent")
>>> c = Child.objects.create(name="Child", parent=p)
-# Look up the object again so that we get a "fresh" object
+# Look up the object again so that we get a "fresh" object.
>>> c = Child.objects.get(name="Child")
>>> p = c.parent
-# Accessing the related object again returns the exactly same object
+# Accessing the related object again returns the exactly same object.
>>> c.parent is p
True
-# But if we kill the cache, we get a new object
+# But if we kill the cache, we get a new object.
>>> del c._parent_cache
>>> c.parent is p
False
-# Assigning a new object results in that object getting cached immediately
+# Assigning a new object results in that object getting cached immediately.
>>> p2 = Parent.objects.create(name="Parent 2")
>>> c.parent = p2
>>> c.parent is p2
True
-# Assigning None fails: Child.parent is null=False
+# Assigning None succeeds if field is null=True.
+>>> p.bestchild = None
+>>> p.bestchild is None
+True
+
+# bestchild should still be None after saving.
+>>> p.save()
+>>> p.bestchild is None
+True
+
+# bestchild should still be None after fetching the object again.
+>>> p = Parent.objects.get(name="Parent")
+>>> p.bestchild is None
+True
+
+# Assigning None fails: Child.parent is null=False.
>>> c.parent = None
Traceback (most recent call last):
...
@@ -91,8 +106,31 @@ Traceback (most recent call last):
...
ValueError: Cannot assign "<First: First object>": "Child.parent" must be a "Parent" instance.
-# Test of multiple ForeignKeys to the same model (bug #7125)
+# Creation using keyword argument should cache the related object.
+>>> p = Parent.objects.get(name="Parent")
+>>> c = Child(parent=p)
+>>> c.parent is p
+True
+
+# Creation using keyword argument and unsaved related instance (#8070).
+>>> p = Parent()
+>>> c = Child(parent=p)
+>>> c.parent is p
+True
+# Creation using attname keyword argument and an id will cause the related
+# object to be fetched.
+>>> p = Parent.objects.get(name="Parent")
+>>> c = Child(parent_id=p.id)
+>>> c.parent is p
+False
+>>> c.parent == p
+True
+
+
+#
+# Test of multiple ForeignKeys to the same model (bug #7125).
+#
>>> c1 = Category.objects.create(name='First')
>>> c2 = Category.objects.create(name='Second')
>>> c3 = Category.objects.create(name='Third')