|
4 | 4 | pytestmark = pytest.mark.django_db
|
5 | 5 |
|
6 | 6 |
|
7 | | -def test_included_data_on_list(multiple_entries, client): |
8 | | - response = client.get( |
9 | | - reverse("entry-list"), data={"include": "comments", "page[size]": 5} |
10 | | - ) |
11 | | - included = response.json().get("included") |
12 | | - |
13 | | - assert len(response.json()["data"]) == len( |
14 | | - multiple_entries |
15 | | - ), "Incorrect entry count" |
16 | | - assert [x.get("type") for x in included] == [ |
17 | | - "comments", |
18 | | - "comments", |
19 | | - ], "List included types are incorrect" |
20 | | - |
21 | | - comment_count = len( |
22 | | - [resource for resource in included if resource["type"] == "comments"] |
23 | | - ) |
24 | | - expected_comment_count = sum(entry.comments.count() for entry in multiple_entries) |
25 | | - assert comment_count == expected_comment_count, "List comment count is incorrect" |
26 | | - |
27 | | - |
28 | | -def test_included_data_on_list_with_one_to_one_relations(multiple_entries, client): |
29 | | - response = client.get( |
30 | | - reverse("entry-list"), data={"include": "authors.bio.metadata", "page[size]": 5} |
31 | | - ) |
32 | | - included = response.json().get("included") |
33 | | - |
34 | | - assert len(response.json()["data"]) == len( |
35 | | - multiple_entries |
36 | | - ), "Incorrect entry count" |
37 | | - expected_include_types = [ |
38 | | - "authorBioMetadata", |
39 | | - "authorBioMetadata", |
40 | | - "authorBios", |
41 | | - "authorBios", |
42 | | - "authors", |
43 | | - "authors", |
44 | | - ] |
45 | | - include_types = [x.get("type") for x in included] |
46 | | - assert include_types == expected_include_types, "List included types are incorrect" |
47 | | - |
48 | | - |
49 | | -def test_default_included_data_on_detail(single_entry, client): |
50 | | - return test_included_data_on_detail( |
51 | | - single_entry=single_entry, client=client, query="" |
52 | | - ) |
53 | | - |
54 | | - |
55 | | -def test_included_data_on_detail(single_entry, client, query="?include=comments"): |
56 | | - response = client.get( |
57 | | - reverse("entry-detail", kwargs={"pk": single_entry.pk}) + query |
58 | | - ) |
59 | | - included = response.json().get("included") |
60 | | - |
61 | | - assert [x.get("type") for x in included] == [ |
62 | | - "comments" |
63 | | - ], "Detail included types are incorrect" |
64 | | - |
65 | | - comment_count = len( |
66 | | - [resource for resource in included if resource["type"] == "comments"] |
67 | | - ) |
68 | | - expected_comment_count = single_entry.comments.count() |
69 | | - assert comment_count == expected_comment_count, "Detail comment count is incorrect" |
70 | | - |
71 | | - |
72 | 7 | def test_dynamic_related_data_is_included(single_entry, entry_factory, client):
|
73 | 8 | entry_factory()
|
74 | 9 | response = client.get(
|
|
0 commit comments