Objects ids can be referenced before they are defined in the serialization data.
(self)
| 503 | |
| 504 | @skipUnlessDBFeature("supports_forward_references") |
| 505 | def test_forward_refs(self): |
| 506 | """ |
| 507 | Objects ids can be referenced before they are |
| 508 | defined in the serialization data. |
| 509 | """ |
| 510 | # The deserialization process needs to run in a transaction in order |
| 511 | # to test forward reference handling. |
| 512 | with transaction.atomic(): |
| 513 | objs = serializers.deserialize(self.serializer_name, self.fwd_ref_str) |
| 514 | with connection.constraint_checks_disabled(): |
| 515 | for obj in objs: |
| 516 | obj.save() |
| 517 | |
| 518 | for model_cls in (Category, Author, Article): |
| 519 | self.assertEqual(model_cls.objects.count(), 1) |
| 520 | art_obj = Article.objects.all()[0] |
| 521 | self.assertEqual(art_obj.categories.count(), 1) |
| 522 | self.assertEqual(art_obj.author.name, "Agnes") |
| 523 | |
| 524 | |
| 525 | def register_tests(test_class, method_name, test_func, exclude=()): |
nothing calls this directly
no test coverage detected