Skip to content

Commit 6f8b2d1

Browse files
ngnpopejacobtylerwalls
authored andcommitted
Refs #33579 -- Added extra tests for NotUpdated exception.
When `NotUpdated` was added in ab148c0, these additional tests that have equivalents for the `DoesNotExist` and `MultipleObjectsReturned` exceptions were missed.
1 parent 13299a6 commit 6f8b2d1

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

tests/model_inheritance/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ def test_inherited_multiple_objects_returned_exception(self):
449449
with self.assertRaises(Place.MultipleObjectsReturned):
450450
Restaurant.objects.get()
451451

452+
def test_inherited_not_updated_exception(self):
453+
# NotUpdated is also inherited.
454+
obj = Restaurant(id=999)
455+
with self.assertRaises(Place.NotUpdated):
456+
obj.save(update_fields={"name"})
457+
452458
def test_related_objects_for_inherited_models(self):
453459
# Related objects work just as they normally do.
454460
s1 = Supplier.objects.create(name="Joe's Chickens", address="123 Sesame St")

tests/proxy_models/tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.contrib.auth.models import User as AuthUser
33
from django.contrib.contenttypes.models import ContentType
44
from django.core import checks, management
5-
from django.db import DEFAULT_DB_ALIAS, models
5+
from django.db import DEFAULT_DB_ALIAS, models, transaction
66
from django.db.models import signals
77
from django.test import TestCase, override_settings
88
from django.test.utils import isolate_apps
@@ -104,8 +104,8 @@ def test_correct_type_proxy_of_proxy(self):
104104

105105
def test_proxy_included_in_ancestors(self):
106106
"""
107-
Proxy models are included in the ancestors for a model's DoesNotExist
108-
and MultipleObjectsReturned
107+
Proxy models are included in the ancestors for a model's DoesNotExist,
108+
MultipleObjectsReturned, and NotUpdated
109109
"""
110110
Person.objects.create(name="Foo McBar")
111111
MyPerson.objects.create(name="Bazza del Frob")
@@ -118,6 +118,8 @@ def test_proxy_included_in_ancestors(self):
118118
MyPersonProxy.objects.get(id__lt=max_id + 1)
119119
with self.assertRaises(Person.DoesNotExist):
120120
StatusPerson.objects.get(name="Zathras")
121+
with self.assertRaises(Person.NotUpdated), transaction.atomic():
122+
StatusPerson(id=999).save(update_fields={"name"})
121123

122124
StatusPerson.objects.create(name="Bazza Jr.")
123125
StatusPerson.objects.create(name="Foo Jr.")

tests/queryset_pickle/tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def test_multipleobjectsreturned_class(self):
7070
klass = Event.MultipleObjectsReturned
7171
self.assertIs(pickle.loads(pickle.dumps(klass)), klass)
7272

73+
def test_not_updated_class(self):
74+
klass = Event.NotUpdated
75+
self.assertIs(pickle.loads(pickle.dumps(klass)), klass)
76+
7377
def test_forward_relatedobjectdoesnotexist_class(self):
7478
# ForwardManyToOneDescriptor
7579
klass = Event.group.RelatedObjectDoesNotExist

0 commit comments

Comments
 (0)