(self, format)
| 24 | |
| 25 | |
| 26 | def 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 | |
| 60 | def natural_key_test(self, format): |
nothing calls this directly
no test coverage detected