MCPcopy
hub / github.com/django/django / natural_key_serializer_test

Function natural_key_serializer_test

tests/serializers/test_natural.py:26–57  ·  view source on GitHub ↗
(self, format)

Source from the content-addressed store, hash-verified

24
25
26def natural_key_serializer_test(self, format):
27 # Create all the objects defined in the test data
28 with connection.constraint_checks_disabled():
29 objects = [
30 NaturalKeyAnchor.objects.create(id=1100, data="Natural Key Anghor"),
31 FKDataNaturalKey.objects.create(id=1101, data_id=1100),
32 FKDataNaturalKey.objects.create(id=1102, data_id=None),
33 ]
34 # Serialize the test database
35 serialized_data = serializers.serialize(
36 format, objects, indent=2, use_natural_foreign_keys=True
37 )
38
39 for obj in serializers.deserialize(format, serialized_data):
40 obj.save()
41
42 # Assert that the deserialized data is the same
43 # as the original source
44 for obj in objects:
45 instance = obj.__class__.objects.get(id=obj.pk)
46 self.assertEqual(
47 obj.data,
48 instance.data,
49 "Objects with PK=%s not equal; expected '%s' (%s), got '%s' (%s)"
50 % (
51 obj.pk,
52 obj.data,
53 type(obj.data),
54 instance,
55 type(instance.data),
56 ),
57 )
58
59
60def natural_key_test(self, format):

Callers

nothing calls this directly

Calls 6

createMethod · 0.45
serializeMethod · 0.45
deserializeMethod · 0.45
saveMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected