MCPcopy
hub / github.com/django/django / test_proxy_included_in_ancestors

Method test_proxy_included_in_ancestors

tests/proxy_models/tests.py:105–129  ·  view source on GitHub ↗

Proxy models are included in the ancestors for a model's DoesNotExist, MultipleObjectsReturned, and NotUpdated

(self)

Source from the content-addressed store, hash-verified

103 self.assertEqual(pp, ["Bazza del Frob", "Foo McBar", "homer"])
104
105 def test_proxy_included_in_ancestors(self):
106 """
107 Proxy models are included in the ancestors for a model's DoesNotExist,
108 MultipleObjectsReturned, and NotUpdated
109 """
110 Person.objects.create(name="Foo McBar")
111 MyPerson.objects.create(name="Bazza del Frob")
112 LowerStatusPerson.objects.create(status="low", name="homer")
113 max_id = Person.objects.aggregate(max_id=models.Max("id"))["max_id"]
114
115 with self.assertRaises(Person.DoesNotExist):
116 MyPersonProxy.objects.get(name="Zathras")
117 with self.assertRaises(Person.MultipleObjectsReturned):
118 MyPersonProxy.objects.get(id__lt=max_id + 1)
119 with self.assertRaises(Person.DoesNotExist):
120 StatusPerson.objects.get(name="Zathras")
121 with self.assertRaises(Person.NotUpdated), transaction.atomic():
122 StatusPerson(id=999).save(update_fields={"name"})
123
124 StatusPerson.objects.create(name="Bazza Jr.")
125 StatusPerson.objects.create(name="Foo Jr.")
126 max_id = Person.objects.aggregate(max_id=models.Max("id"))["max_id"]
127
128 with self.assertRaises(Person.MultipleObjectsReturned):
129 StatusPerson.objects.get(id__lt=max_id + 1)
130
131 def test_abstract_base_with_model_fields(self):
132 msg = (

Callers

nothing calls this directly

Calls 5

StatusPersonClass · 0.85
aggregateMethod · 0.80
createMethod · 0.45
getMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected