MCPcopy
hub / github.com/django/django / assert_serializer

Function assert_serializer

tests/serializers/test_data.py:422–452  ·  view source on GitHub ↗
(self, format, data)

Source from the content-addressed store, hash-verified

420
421
422def 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
455def serializerTest(self, format):

Callers 4

serializerTestFunction · 0.85
serializerTestPK0Function · 0.85

Calls 9

extendMethod · 0.80
create_objectMethod · 0.80
countMethod · 0.45
allMethod · 0.45
serializeMethod · 0.45
deserializeMethod · 0.45
saveMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected