(self, format, data)
| 420 | |
| 421 | |
| 422 | def assert_serializer(self, format, data): |
| 423 | # Create all the objects defined in the test data. |
| 424 | objects = [] |
| 425 | for test_helper, pk, model, data_value in data: |
| 426 | with connection.constraint_checks_disabled(): |
| 427 | objects.extend(test_helper.create_object(pk, model, data_value)) |
| 428 | |
| 429 | # Get a count of the number of objects created for each model class. |
| 430 | instance_counts = {} |
| 431 | for _, _, model, _ in data: |
| 432 | if model not in instance_counts: |
| 433 | instance_counts[model] = model.objects.count() |
| 434 | |
| 435 | # Add the generic tagged objects to the object list. |
| 436 | objects.extend(Tag.objects.all()) |
| 437 | |
| 438 | # Serialize the test database. |
| 439 | serialized_data = serializers.serialize(format, objects, indent=2) |
| 440 | |
| 441 | for obj in serializers.deserialize(format, serialized_data): |
| 442 | obj.save() |
| 443 | |
| 444 | # Assert that the deserialized data is the same as the original source. |
| 445 | for test_helper, pk, model, data_value in data: |
| 446 | with self.subTest(model=model, data_value=data_value): |
| 447 | test_helper.compare_object(self, pk, model, data_value) |
| 448 | |
| 449 | # Assert no new objects were created. |
| 450 | for model, count in instance_counts.items(): |
| 451 | with self.subTest(model=model, count=count): |
| 452 | self.assertEqual(count, model.objects.count()) |
| 453 | |
| 454 | |
| 455 | def serializerTest(self, format): |
no test coverage detected