Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 184ab5f

Browse files
add a test for including many objects from a related serializer
1 parent c93dea1 commit 184ab5f

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
@@ -50,6 +50,15 @@ def test_dynamic_related_data_is_included(single_entry, entry_factory, client):
5050
assert len(included) == 1, 'The dynamically included blog entries are of an incorrect count'
5151

5252

53+
def test_dynamic_many_related_data_is_included(single_entry, entry_factory, client):
54+
entry_factory()
55+
response = client.get(reverse("entry-detail", kwargs={'pk': single_entry.pk}) + '?include=suggested')
56+
included = load_json(response.content).get('included')
57+
58+
assert included
59+
assert [x.get('type') for x in included] == ['entries'], 'Dynamic included types are incorrect'
60+
61+
5362
def test_missing_field_not_included(author_bio_factory, author_factory, client):
5463
# First author does not have a bio
5564
author = author_factory(bio=None)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /