mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 03:50:11 +03:00
Use ForeignKeyTargetWithSourcesSerializer
in relations/pk tests
When checking the expected data, we now must ensure that the nested models are serialized correctly also.
This commit is contained in:
parent
c36e2eabe9
commit
c1cc3ada7b
|
@ -227,9 +227,13 @@ class PKForeignKeyTests(TestCase):
|
|||
|
||||
def test_reverse_foreign_key_retrieve(self):
|
||||
queryset = ForeignKeyTarget.objects.all()
|
||||
serializer = ForeignKeyTargetSerializer(queryset, many=True)
|
||||
serializer = ForeignKeyTargetWithSourcesSerializer(queryset, many=True)
|
||||
expected = [
|
||||
{'id': 1, 'name': 'target-1', 'sources': [1, 2, 3]},
|
||||
{'id': 1, 'name': 'target-1', 'sources': [
|
||||
{'id': 1, 'name': 'source-1', 'target': 1},
|
||||
{'id': 2, 'name': 'source-2', 'target': 1},
|
||||
{'id': 3, 'name': 'source-3', 'target': 1},
|
||||
]},
|
||||
{'id': 2, 'name': 'target-2', 'sources': []},
|
||||
]
|
||||
with self.assertNumQueries(3):
|
||||
|
@ -237,7 +241,7 @@ class PKForeignKeyTests(TestCase):
|
|||
|
||||
def test_reverse_foreign_key_retrieve_prefetch_related(self):
|
||||
queryset = ForeignKeyTarget.objects.all().prefetch_related('sources')
|
||||
serializer = ForeignKeyTargetSerializer(queryset, many=True)
|
||||
serializer = ForeignKeyTargetWithSourcesSerializer(queryset, many=True)
|
||||
with self.assertNumQueries(2):
|
||||
serializer.data
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user