3
3
import pytest
4
4
from django .urls import reverse
5
5
6
+ from example .factories import ArtProjectFactory , ProjectTypeFactory
7
+
6
8
pytestmark = pytest .mark .django_db
7
9
8
10
@@ -57,13 +59,22 @@ def test_polymorphism_on_polymorphic_model_detail_patch(single_art_project, clie
57
59
def test_polymorphism_on_polymorphic_model_list_post (client ):
58
60
test_topic = 'New test topic {}' .format (random .randint (0 , 999999 ))
59
61
test_artist = 'test-{}' .format (random .randint (0 , 999999 ))
62
+ test_project_type = ProjectTypeFactory ()
60
63
url = reverse ('project-list' )
61
64
data = {
62
65
'data' : {
63
66
'type' : 'artProjects' ,
64
67
'attributes' : {
65
68
'topic' : test_topic ,
66
69
'artist' : test_artist
70
+ },
71
+ 'relationships' : {
72
+ 'projectType' : {
73
+ 'data' : {
74
+ 'type' : 'projectTypes' ,
75
+ 'id' : test_project_type .pk
76
+ }
77
+ }
67
78
}
68
79
}
69
80
}
@@ -73,6 +84,22 @@ def test_polymorphism_on_polymorphic_model_list_post(client):
73
84
assert content ['data' ]['type' ] == "artProjects"
74
85
assert content ['data' ]['attributes' ]['topic' ] == test_topic
75
86
assert content ['data' ]['attributes' ]['artist' ] == test_artist
87
+ assert content ['data' ]['relationships' ]['projectType' ]['data' ]['id' ] == \
88
+ str (test_project_type .pk )
89
+
90
+
91
+ def test_polymorphism_on_polymorphic_model_w_included_serializers (client ):
92
+ test_project = ArtProjectFactory ()
93
+ query = '?include=projectType'
94
+ url = reverse ('project-list' )
95
+ response = client .get (url + query )
96
+ content = response .json ()
97
+ assert content ['data' ][0 ]['id' ] == str (test_project .pk )
98
+ assert content ['data' ][0 ]['type' ] == 'artProjects'
99
+ assert content ['data' ][0 ]['relationships' ]['projectType' ]['data' ]['id' ] == \
100
+ str (test_project .project_type .pk )
101
+ assert content ['included' ][0 ]['type' ] == 'projectTypes'
102
+ assert content ['included' ][0 ]['id' ] == str (test_project .project_type .pk )
76
103
77
104
78
105
def test_polymorphic_model_without_any_instance (client ):
0 commit comments