@@ -18,19 +18,19 @@ def test_polymorphism_on_detail_relations(single_company, client):
1818 response = client .get (reverse ("company-detail" , kwargs = {'pk' : single_company .pk }))
1919 content = load_json (response .content )
2020 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" ])
2323
2424
2525def test_polymorphism_on_included_relations (single_company , client ):
2626 response = client .get (reverse ("company-detail" , kwargs = {'pk' : single_company .pk }) +
2727 '?include=current_project,future_projects' )
2828 content = load_json (response .content )
2929 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'
3434 # Ensure that the child fields are present.
3535 assert content .get ('included' )[0 ].get ('attributes' ).get ('artist' ) is not None
3636 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
4747 content ['data' ]['attributes' ]['artist' ] = test_artist
4848 response = client .patch (url , data = json .dumps (content ), content_type = 'application/vnd.api+json' )
4949 new_content = load_json (response .content )
50- assert new_content [" data" ][ " type" ] == "artProjects"
50+ assert new_content [' data' ][ ' type' ] == "artProjects"
5151 assert new_content ['data' ]['attributes' ]['topic' ] == test_topic
5252 assert new_content ['data' ]['attributes' ]['artist' ] == test_artist
5353
@@ -68,7 +68,7 @@ def test_polymorphism_on_polymorphic_model_list_post(client):
6868 response = client .post (url , data = json .dumps (data ), content_type = 'application/vnd.api+json' )
6969 content = load_json (response .content )
7070 assert content ['data' ]['id' ] is not None
71- assert content [" data" ][ " type" ] == "artProjects"
71+ assert content [' data' ][ ' type' ] == "artProjects"
7272 assert content ['data' ]['attributes' ]['topic' ] == test_topic
7373 assert content ['data' ]['attributes' ]['artist' ] == test_artist
7474
@@ -91,9 +91,15 @@ def test_invalid_type_on_polymorphic_model(client):
9191 content = load_json (response .content )
9292 assert len (content ["errors" ]) is 1
9393 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])."
97103
98104
99105def 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
131137 content = load_json (response .content )
132138 assert len (content ["errors" ]) is 1
133139 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