Proxy models are included in the ancestors for a model's DoesNotExist, MultipleObjectsReturned, and NotUpdated
(self)
| 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 = ( |
nothing calls this directly
no test coverage detected