@@ -947,3 +947,214 @@ def test_adding_resource_with_lid_relationship(self):
947947
948948 self .assertDictEqual (expected_result ,
949949 json .loads (response .content ))
950+
951+ def test_view_processing_with_include_request (self ):
952+ operations = [
953+ {
954+ "op" : "add" ,
955+ "data" : {
956+ "type" : "BasicModel" ,
957+ "attributes" : {
958+ "text" : "JSON API paints my bikeshed!"
959+ }
960+ }
961+ }, {
962+ "op" : "add" ,
963+ "data" : {
964+ "type" : "RelatedModel" ,
965+ "attributes" : {
966+ "text" : "JSON API paints my bikeshed!"
967+ }
968+ }
969+ }, {
970+ "op" : "add" ,
971+ "data" : {
972+ "type" : "RelatedModelTwo" ,
973+ "attributes" : {
974+ "text" : "JSON API paints my bikeshed!"
975+ }
976+ }
977+ }, {
978+ "op" : "update" ,
979+ "ref" : {
980+ "id" : "1" ,
981+ "type" : "BasicModel" ,
982+ "relationship" : "to_one"
983+ },
984+ "data" : {"type" : "RelatedModel" , "id" : "1" },
985+ }, {
986+ "op" : "update" ,
987+ "data" : {
988+ "id" : "1" ,
989+ "type" : "BasicModel" ,
990+ "relationships" : {
991+ "to_many" : {
992+ "data" : [
993+ {
994+ "type" : "RelatedModelTwo" ,
995+ "id" : "1"
996+ }
997+ ]
998+ }
999+ }
1000+ },
1001+ "meta" : {
1002+ "include" : ["to_one" ]
1003+ }
1004+ }
1005+ ]
1006+
1007+ data = {
1008+ ATOMIC_OPERATIONS : operations
1009+ }
1010+
1011+ response = self .client .post (
1012+ path = "/" ,
1013+ data = data ,
1014+ content_type = ATOMIC_CONTENT_TYPE ,
1015+
1016+ ** {"HTTP_ACCEPT" : ATOMIC_CONTENT_TYPE }
1017+ )
1018+
1019+ # check response
1020+ self .assertEqual (200 , response .status_code )
1021+
1022+ expected_result = {
1023+ ATOMIC_RESULTS : [
1024+ {
1025+ "data" : {
1026+ "id" : "1" ,
1027+
1028+ "type" : "BasicModel" ,
1029+ "attributes" : {
1030+ "text" : "JSON API paints my bikeshed!"
1031+ },
1032+ "relationships" : {
1033+ "to_one" : {"data" : None },
1034+ "to_many" : {"data" : [], "meta" : {"count" : 0 }},
1035+ }
1036+ }
1037+ },
1038+ {
1039+ "data" : {
1040+ "id" : "1" ,
1041+ "type" : "RelatedModel" ,
1042+ "attributes" : {
1043+ "text" : "JSON API paints my bikeshed!"
1044+ }
1045+ }
1046+ },
1047+ {
1048+ "data" : {
1049+ "id" : "1" ,
1050+ "type" : "RelatedModelTwo" ,
1051+ "attributes" : {
1052+ "text" : "JSON API paints my bikeshed!"
1053+ }
1054+ }
1055+ },
1056+ {
1057+ "data" : {
1058+ "id" : "1" ,
1059+ "type" : "BasicModel" ,
1060+ "attributes" : {
1061+ "text" : "JSON API paints my bikeshed!"
1062+ },
1063+ "relationships" : {
1064+ "to_many" : {
1065+ "data" : [
1066+ {
1067+ "id" : "1" ,
1068+ "type" : "RelatedModelTwo"
1069+ }
1070+ ],
1071+ "meta" : {
1072+ "count" : 1
1073+ }
1074+ },
1075+ "to_one" : {
1076+ "data" : {
1077+ "id" :"1" ,
1078+ "type" :"RelatedModel"
1079+ }
1080+ },
1081+ }
1082+
1083+ },
1084+ "included" : [
1085+ {"id" : "1" ,"type" :"RelatedModel" ,"attributes" :{"text" :"JSON API paints my bikeshed!" }},
1086+ ]
1087+ },
1088+ ]
1089+ }
1090+
1091+ self .assertDictEqual (expected_result ,
1092+ json .loads (response .content ))
1093+
1094+ def test_view_processing_with_invalid_include_request (self ):
1095+ operations = [
1096+ {
1097+ "op" : "add" ,
1098+ "data" : {
1099+ "type" : "BasicModel" ,
1100+ "attributes" : {
1101+ "text" : "JSON API paints my bikeshed!"
1102+ }
1103+ }
1104+ }, {
1105+ "op" : "add" ,
1106+ "data" : {
1107+ "id" : "1" ,
1108+ "type" : "RelatedModelTwo" ,
1109+ "attributes" : {
1110+ "text" : "JSON API paints my bikeshed!"
1111+ }
1112+ }
1113+ }, {
1114+ "op" : "update" ,
1115+ "data" : {
1116+ "id" : "1" ,
1117+ "type" : "BasicModel" ,
1118+ "relationships" : {
1119+ "to_many" : {
1120+ "data" : [
1121+ {
1122+ "type" : "RelatedModelTwo" ,
1123+ "id" : "1"
1124+ }
1125+ ]
1126+ }
1127+ }
1128+ },
1129+ "meta" : {
1130+ "include" : ["to_many" ]
1131+ }
1132+ }
1133+ ]
1134+ data = {
1135+ ATOMIC_OPERATIONS : operations
1136+ }
1137+
1138+ response = self .client .post (
1139+ path = "/" ,
1140+ data = data ,
1141+ content_type = ATOMIC_CONTENT_TYPE ,
1142+
1143+ ** {"HTTP_ACCEPT" : ATOMIC_CONTENT_TYPE }
1144+ )
1145+
1146+ # check response
1147+ self .assertEqual (400 , response .status_code )
1148+
1149+ expected_result = {
1150+ "errors" : [
1151+ {
1152+ "code" : "parse_error" ,
1153+ "detail" :"This endpoint does not support the include parameter for path to_many" ,
1154+ "source" : { "pointer" :"/data" },
1155+ "status" :"400"
1156+ }
1157+ ]
1158+ }
1159+ self .assertDictEqual (expected_result ,
1160+ json .loads (response .content ))
0 commit comments