mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Partial revert of 165f44aa
.
That commit didn't always improve readability. See discussion on django-developers for details.
This commit is contained in:
parent
222460a994
commit
ee0ef1b094
6 changed files with 195 additions and 168 deletions
|
@ -141,10 +141,12 @@ class OneToOneRegressionTests(TestCase):
|
|||
"""
|
||||
p = Place(name='Zombie Cats', address='Not sure')
|
||||
p.save()
|
||||
with self.assertNumQueries(1), self.assertRaises(Restaurant.DoesNotExist):
|
||||
p.restaurant
|
||||
with self.assertNumQueries(0), self.assertRaises(Restaurant.DoesNotExist):
|
||||
p.restaurant
|
||||
with self.assertNumQueries(1):
|
||||
with self.assertRaises(Restaurant.DoesNotExist):
|
||||
p.restaurant
|
||||
with self.assertNumQueries(0):
|
||||
with self.assertRaises(Restaurant.DoesNotExist):
|
||||
p.restaurant
|
||||
|
||||
def test_reverse_object_cached_when_related_is_accessed(self):
|
||||
"""
|
||||
|
@ -197,8 +199,9 @@ class OneToOneRegressionTests(TestCase):
|
|||
self.assertEqual(self.p1.undergroundbar, b)
|
||||
b.place = None
|
||||
b.save()
|
||||
with self.assertNumQueries(0), self.assertRaises(UndergroundBar.DoesNotExist):
|
||||
self.p1.undergroundbar
|
||||
with self.assertNumQueries(0):
|
||||
with self.assertRaises(UndergroundBar.DoesNotExist):
|
||||
self.p1.undergroundbar
|
||||
|
||||
def test_get_reverse_on_unsaved_object(self):
|
||||
"""
|
||||
|
@ -210,21 +213,24 @@ class OneToOneRegressionTests(TestCase):
|
|||
p = Place()
|
||||
|
||||
# When there's no instance of the origin of the one-to-one
|
||||
with self.assertNumQueries(0), self.assertRaises(UndergroundBar.DoesNotExist):
|
||||
p.undergroundbar
|
||||
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), self.assertRaises(UndergroundBar.DoesNotExist):
|
||||
p.undergroundbar
|
||||
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), self.assertRaises(UndergroundBar.DoesNotExist):
|
||||
p.undergroundbar
|
||||
with self.assertNumQueries(0):
|
||||
with self.assertRaises(UndergroundBar.DoesNotExist):
|
||||
p.undergroundbar
|
||||
|
||||
def test_set_reverse_on_unsaved_object(self):
|
||||
"""
|
||||
|
@ -233,8 +239,9 @@ class OneToOneRegressionTests(TestCase):
|
|||
"""
|
||||
p = Place()
|
||||
b = UndergroundBar.objects.create()
|
||||
with self.assertNumQueries(0), self.assertRaises(ValueError):
|
||||
p.undergroundbar = b
|
||||
with self.assertNumQueries(0):
|
||||
with self.assertRaises(ValueError):
|
||||
p.undergroundbar = b
|
||||
|
||||
def test_nullable_o2o_delete(self):
|
||||
u = UndergroundBar.objects.create(place=self.p1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue