| 261 | |
| 262 | |
| 263 | class DeletionSignalsTest(TestCase): |
| 264 | |
| 265 | senders = (FooFile, FooFileProxy,) |
| 266 | |
| 267 | def setUp(self): |
| 268 | self.clear_received_senders() |
| 269 | for sender in self.senders: |
| 270 | models.signals.pre_delete.connect(self.pre_delete_receiver, sender) |
| 271 | models.signals.post_delete.connect(self.post_delete_receiver, sender) |
| 272 | |
| 273 | def tearDown(self): |
| 274 | for sender in self.senders: |
| 275 | models.signals.pre_delete.disconnect(self.pre_delete_receiver, sender) |
| 276 | models.signals.post_delete.disconnect(self.post_delete_receiver, sender) |
| 277 | |
| 278 | def clear_received_senders(self): |
| 279 | self.pre_delete_senders = [] |
| 280 | self.post_delete_senders = [] |
| 281 | |
| 282 | def pre_delete_receiver(self, sender, **kwargs): |
| 283 | self.pre_delete_senders.append(sender) |
| 284 | |
| 285 | def post_delete_receiver(self, sender, **kwargs): |
| 286 | self.post_delete_senders.append(sender) |
| 287 | |
| 288 | def test_delete_deferred_model(self): |
| 289 | """ |
| 290 | Model with deferred fields are actually proxy models under the hood. |
| 291 | Make sure deletion signals are correctly sent when fields are deferred |
| 292 | on a concrete model and on a proxy. |
| 293 | |
| 294 | Refs #18100 |
| 295 | """ |
| 296 | my_file = File.objects.create() |
| 297 | |
| 298 | obj = FooFile.objects.create(my_file=my_file) |
| 299 | FooFile.objects.only('id').get(id=obj.id).delete() |
| 300 | self.assertEqual(self.pre_delete_senders, [FooFile]) |
| 301 | self.assertEqual(self.post_delete_senders, [FooFile]) |
| 302 | |
| 303 | self.clear_received_senders() |
| 304 | |
| 305 | obj = FooFileProxy.objects.create(my_file=my_file) |
| 306 | FooFileProxy.objects.only('id').get(id=obj.id).delete() |
| 307 | self.assertEqual(self.pre_delete_senders, [FooFileProxy]) |
| 308 | self.assertEqual(self.post_delete_senders, [FooFileProxy]) |
| 309 | |