summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-10-09 21:36:35 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-10-09 21:36:35 +0200
commit3190abcd75b1fcd660353da4001885ef82cbc596 (patch)
treedc9af6fa169696833f92897c82db2f9c9750111c /tests/regressiontests
parentc9b4e9ac3a6c56f2b006b723972e77722d3ac937 (diff)
Fixed #18153 -- Reverse OneToOne lookups on unsaved instances.
Thanks David Hatch and Anssi Kääriäinen for their inputs.
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/one_to_one_regress/tests.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/regressiontests/one_to_one_regress/tests.py b/tests/regressiontests/one_to_one_regress/tests.py
index eced88598b..615536ba38 100644
--- a/tests/regressiontests/one_to_one_regress/tests.py
+++ b/tests/regressiontests/one_to_one_regress/tests.py
@@ -202,3 +202,43 @@ class OneToOneRegressionTests(TestCase):
with self.assertNumQueries(0):
with self.assertRaises(UndergroundBar.DoesNotExist):
self.p1.undergroundbar
+
+ def test_get_reverse_on_unsaved_object(self):
+ """
+ Regression for #18153 and #19089.
+
+ Accessing the reverse relation on an unsaved object
+ always raises an exception.
+ """
+ p = Place()
+
+ # When there's no instance of the origin of the one-to-one
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ p.undergroundbar
+
+ UndergroundBar.objects.create()
+
+ # When there's one instance of the origin
+ # (p.undergroundbar used to return that instance)
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ p.undergroundbar
+
+ UndergroundBar.objects.create()
+
+ # When there are several instances of the origin
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ p.undergroundbar
+
+ def test_set_reverse_on_unsaved_object(self):
+ """
+ Writing to the reverse relation on an unsaved object
+ is impossible too.
+ """
+ p = Place()
+ b = UndergroundBar.objects.create()
+ with self.assertNumQueries(0):
+ with self.assertRaises(ValueError):
+ p.undergroundbar = b