@@ -18,19 +18,19 @@ def test_polymorphism_on_detail_relations(single_company, client):
18
18
response = client .get (reverse ("company-detail" , kwargs = {'pk' : single_company .pk }))
19
19
content = load_json (response .content )
20
20
assert content ["data" ]["relationships" ]["currentProject" ]["data" ]["type" ] == "artProjects"
21
- assert [rel ["type" ] for rel in content ["data" ]["relationships" ]["futureProjects" ]["data" ]] == [
22
- "researchProjects" , "artProjects" ]
21
+ assert set ( [rel ["type" ] for rel in content ["data" ]["relationships" ]["futureProjects" ]["data" ]]) == set ( [
22
+ "researchProjects" , "artProjects" ])
23
23
24
24
25
25
def test_polymorphism_on_included_relations (single_company , client ):
26
26
response = client .get (reverse ("company-detail" , kwargs = {'pk' : single_company .pk }) +
27
27
'?include=current_project,future_projects' )
28
28
content = load_json (response .content )
29
29
assert content ["data" ]["relationships" ]["currentProject" ]["data" ]["type" ] == "artProjects"
30
- assert [rel ["type" ] for rel in content ["data" ]["relationships" ]["futureProjects" ]["data" ]] == [
31
- "researchProjects" , "artProjects" ]
32
- assert [x .get ('type' ) for x in content .get ('included' )] == [
33
- 'artProjects' , 'artProjects' , 'researchProjects' ], 'Detail included types are incorrect'
30
+ assert set ( [rel ["type" ] for rel in content ["data" ]["relationships" ]["futureProjects" ]["data" ]]) == set ( [
31
+ "researchProjects" , "artProjects" ])
32
+ assert set ( [x .get ('type' ) for x in content .get ('included' )]) == set ( [
33
+ 'artProjects' , 'artProjects' , 'researchProjects' ]) , 'Detail included types are incorrect'
34
34
# Ensure that the child fields are present.
35
35
assert content .get ('included' )[0 ].get ('attributes' ).get ('artist' ) is not None
36
36
assert content .get ('included' )[1 ].get ('attributes' ).get ('artist' ) is not None
@@ -47,7 +47,7 @@ def test_polymorphism_on_polymorphic_model_detail_patch(single_art_project, clie
47
47
content ['data' ]['attributes' ]['artist' ] = test_artist
48
48
response = client .patch (url , data = json .dumps (content ), content_type = 'application/vnd.api+json' )
49
49
new_content = load_json (response .content )
50
- assert new_content [" data" ][ " type" ] == "artProjects"
50
+ assert new_content [' data' ][ ' type' ] == "artProjects"
51
51
assert new_content ['data' ]['attributes' ]['topic' ] == test_topic
52
52
assert new_content ['data' ]['attributes' ]['artist' ] == test_artist
53
53
@@ -68,7 +68,7 @@ def test_polymorphism_on_polymorphic_model_list_post(client):
68
68
response = client .post (url , data = json .dumps (data ), content_type = 'application/vnd.api+json' )
69
69
content = load_json (response .content )
70
70
assert content ['data' ]['id' ] is not None
71
- assert content [" data" ][ " type" ] == "artProjects"
71
+ assert content [' data' ][ ' type' ] == "artProjects"
72
72
assert content ['data' ]['attributes' ]['topic' ] == test_topic
73
73
assert content ['data' ]['attributes' ]['artist' ] == test_artist
74
74
@@ -91,9 +91,15 @@ def test_invalid_type_on_polymorphic_model(client):
91
91
content = load_json (response .content )
92
92
assert len (content ["errors" ]) is 1
93
93
assert content ["errors" ][0 ]["status" ] == "409"
94
- assert content ["errors" ][0 ]["detail" ] == \
95
- "The resource object's type (invalidProjects) is not the type that constitute the " \
96
- "collection represented by the endpoint (one of [researchProjects, artProjects])."
94
+ try :
95
+ assert content ["errors" ][0 ]["detail" ] == \
96
+ "The resource object's type (invalidProjects) is not the type that constitute the " \
97
+ "collection represented by the endpoint (one of [researchProjects, artProjects])."
98
+ except AssertionError :
99
+ # Available type list order isn't enforced
100
+ assert content ["errors" ][0 ]["detail" ] == \
101
+ "The resource object's type (invalidProjects) is not the type that constitute the " \
102
+ "collection represented by the endpoint (one of [artProjects, researchProjects])."
97
103
98
104
99
105
def test_polymorphism_relations_update (single_company , research_project_factory , client ):
@@ -131,6 +137,12 @@ def test_invalid_type_on_polymorphic_relation(single_company, research_project_f
131
137
content = load_json (response .content )
132
138
assert len (content ["errors" ]) is 1
133
139
assert content ["errors" ][0 ]["status" ] == "409"
134
- assert content ["errors" ][0 ]["detail" ] == \
135
- "Incorrect relation type. Expected one of [researchProjects, artProjects], " \
136
- "received invalidProjects."
140
+ try :
141
+ assert content ["errors" ][0 ]["detail" ] == \
142
+ "Incorrect relation type. Expected one of [researchProjects, artProjects], " \
143
+ "received invalidProjects."
144
+ except AssertionError :
145
+ # Available type list order isn't enforced
146
+ assert content ["errors" ][0 ]["detail" ] == \
147
+ "Incorrect relation type. Expected one of [artProjects, researchProjects], " \
148
+ "received invalidProjects."
0 commit comments