@@ -665,66 +665,6 @@ def _delete_children(resource_to_delete: str):
665
665
parent_id = moto_resource .parent_id
666
666
api_resources [parent_id ].remove (resource_id )
667
667
668
- def update_integration_response (
669
- self ,
670
- context : RequestContext ,
671
- rest_api_id : String ,
672
- resource_id : String ,
673
- http_method : String ,
674
- status_code : StatusCode ,
675
- patch_operations : ListOfPatchOperation = None ,
676
- ** kwargs ,
677
- ) -> IntegrationResponse :
678
- # XXX: THIS IS NOT A COMPLETE IMPLEMENTATION, just the minimum required to get tests going
679
- # TODO: validate patch operations
680
-
681
- moto_rest_api = get_moto_rest_api (context , rest_api_id )
682
- moto_resource = moto_rest_api .resources .get (resource_id )
683
- if not moto_resource :
684
- raise NotFoundException ("Invalid Resource identifier specified" )
685
-
686
- moto_method = moto_resource .resource_methods .get (http_method )
687
- if not moto_method :
688
- raise NotFoundException ("Invalid Method identifier specified" )
689
-
690
- integration_response = moto_method .method_integration .integration_responses .get (status_code )
691
- if not integration_response :
692
- raise NotFoundException ("Invalid Integration Response identifier specified" )
693
-
694
- for patch_operation in patch_operations :
695
- op = patch_operation .get ("op" )
696
- path = patch_operation .get ("path" )
697
-
698
- # for path "/responseTemplates/application~1json"
699
- if "/responseTemplates" in path :
700
- integration_response .response_templates = (
701
- integration_response .response_templates or {}
702
- )
703
- value = patch_operation .get ("value" )
704
- if not isinstance (value , str ):
705
- raise BadRequestException (
706
- f"Invalid patch value '{ value } ' specified for op '{ op } '. Must be a string"
707
- )
708
- param = path .removeprefix ("/responseTemplates/" )
709
- param = param .replace ("~1" , "/" )
710
- if op == "remove" :
711
- integration_response .response_templates .pop (param )
712
- elif op in ("add" , "replace" ):
713
- integration_response .response_templates [param ] = value
714
-
715
- elif "/contentHandling" in path and op == "replace" :
716
- integration_response .content_handling = patch_operation .get ("value" )
717
-
718
- elif "/selectionPattern" in path and op == "replace" :
719
- integration_response .selection_pattern = patch_operation .get ("value" )
720
-
721
- response : IntegrationResponse = integration_response .to_json ()
722
- # in case it's empty, we still want to pass it on as ""
723
- # TODO: add a test case for this
724
- response ["selectionPattern" ] = integration_response .selection_pattern
725
-
726
- return response
727
-
728
668
def update_resource (
729
669
self ,
730
670
context : RequestContext ,
@@ -2307,6 +2247,93 @@ def put_integration_response(
2307
2247
2308
2248
return response
2309
2249
2250
+ def update_integration_response (
2251
+ self ,
2252
+ context : RequestContext ,
2253
+ rest_api_id : String ,
2254
+ resource_id : String ,
2255
+ http_method : String ,
2256
+ status_code : StatusCode ,
2257
+ patch_operations : ListOfPatchOperation = None ,
2258
+ ** kwargs ,
2259
+ ) -> IntegrationResponse :
2260
+ # XXX: THIS IS NOT A COMPLETE IMPLEMENTATION, just the minimum required to get tests going
2261
+ # TODO: validate patch operations
2262
+
2263
+ moto_rest_api = get_moto_rest_api (context , rest_api_id )
2264
+ moto_resource = moto_rest_api .resources .get (resource_id )
2265
+ if not moto_resource :
2266
+ raise NotFoundException ("Invalid Resource identifier specified" )
2267
+
2268
+ moto_method = moto_resource .resource_methods .get (http_method )
2269
+ if not moto_method :
2270
+ raise NotFoundException ("Invalid Method identifier specified" )
2271
+
2272
+ integration_response = moto_method .method_integration .integration_responses .get (status_code )
2273
+ if not integration_response :
2274
+ raise NotFoundException ("Invalid Integration Response identifier specified" )
2275
+
2276
+ for patch_operation in patch_operations :
2277
+ op = patch_operation .get ("op" )
2278
+ path = patch_operation .get ("path" )
2279
+
2280
+ # for path "/responseTemplates/application~1json"
2281
+ if "/responseTemplates" in path :
2282
+ integration_response .response_templates = (
2283
+ integration_response .response_templates or {}
2284
+ )
2285
+ value = patch_operation .get ("value" )
2286
+ if not isinstance (value , str ):
2287
+ raise BadRequestException (
2288
+ f"Invalid patch value '{ value } ' specified for op '{ op } '. Must be a string"
2289
+ )
2290
+ param = path .removeprefix ("/responseTemplates/" )
2291
+ param = param .replace ("~1" , "/" )
2292
+ if op == "remove" :
2293
+ integration_response .response_templates .pop (param )
2294
+ elif op in ("add" , "replace" ):
2295
+ integration_response .response_templates [param ] = value
2296
+
2297
+ elif "/contentHandling" in path and op == "replace" :
2298
+ integration_response .content_handling = patch_operation .get ("value" )
2299
+
2300
+ elif "/selectionPattern" in path and op == "replace" :
2301
+ integration_response .selection_pattern = patch_operation .get ("value" )
2302
+
2303
+ response : IntegrationResponse = integration_response .to_json ()
2304
+ # in case it's empty, we still want to pass it on as ""
2305
+ # TODO: add a test case for this
2306
+ response ["selectionPattern" ] = integration_response .selection_pattern
2307
+
2308
+ return response
2309
+
2310
+ def delete_integration_response (
2311
+ self ,
2312
+ context : RequestContext ,
2313
+ rest_api_id : String ,
2314
+ resource_id : String ,
2315
+ http_method : String ,
2316
+ status_code : StatusCode ,
2317
+ ** kwargs ,
2318
+ ) -> None :
2319
+ moto_backend = apigw_models .apigateway_backends [context .account_id ][context .region ]
2320
+ moto_rest_api = moto_backend .apis .get (rest_api_id )
2321
+ if not moto_rest_api :
2322
+ raise NotFoundException ("Invalid Resource identifier specified" )
2323
+
2324
+ if not (moto_resource := moto_rest_api .resources .get (resource_id )):
2325
+ raise NotFoundException ("Invalid Resource identifier specified" )
2326
+
2327
+ if not (moto_method := moto_resource .resource_methods .get (http_method )):
2328
+ raise NotFoundException ("Invalid Integration identifier specified" )
2329
+
2330
+ if not moto_method .method_integration :
2331
+ raise NotFoundException ("Invalid Integration identifier specified" )
2332
+ if not (
2333
+ integration_responses := moto_method .method_integration .integration_responses
2334
+ ) or not integration_responses .pop (status_code , None ):
2335
+ raise NotFoundException ("Invalid Response status code specified" )
2336
+
2310
2337
def get_export (
2311
2338
self ,
2312
2339
context : RequestContext ,
0 commit comments