Skip to content

Commit 7d5908f

Browse files
tbartelmesskhornberg
authored andcommitted
add a test for including many objects from a related serializer
1 parent a416516 commit 7d5908f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

example/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, *args, **kwargs):
3535
'authors': 'example.serializers.AuthorSerializer',
3636
'comments': 'example.serializers.CommentSerializer',
3737
'featured': 'example.serializers.EntrySerializer',
38+
'suggested': 'example.serializers.EntrySerializer',
3839
}
3940

4041
body_format = serializers.SerializerMethodField()

example/tests/integration/test_includes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def test_dynamic_related_data_is_included(single_entry, entry_factory, client):
3838
assert len(included) == 1, 'The dynamically included blog entries are of an incorrect count'
3939

4040

41+
def test_dynamic_many_related_data_is_included(single_entry, entry_factory, client):
42+
entry_factory()
43+
response = client.get(reverse("entry-detail", kwargs={'pk': single_entry.pk}) + '?include=suggested')
44+
included = load_json(response.content).get('included')
45+
46+
assert included
47+
assert [x.get('type') for x in included] == ['entries'], 'Dynamic included types are incorrect'
48+
49+
4150
def test_missing_field_not_included(author_bio_factory, author_factory, client):
4251
# First author does not have a bio
4352
author = author_factory(bio=None)

0 commit comments

Comments
 (0)