MCPcopy
hub / github.com/django/django / test_forward_refs

Method test_forward_refs

tests/serializers/tests.py:505–522  ·  view source on GitHub ↗

Objects ids can be referenced before they are defined in the serialization data.

(self)

Source from the content-addressed store, hash-verified

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
525def register_tests(test_class, method_name, test_func, exclude=()):

Callers

nothing calls this directly

Calls 5

deserializeMethod · 0.45
saveMethod · 0.45
countMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected