@@ -281,18 +281,54 @@ class TestHttpApiDescription(TestCase):
281
281
@patch ("boto3.session.Session.region_name" , "eu-central-1" )
282
282
def test_with_no_description (self ):
283
283
sam_http_api = SamHttpApi ("foo" )
284
- sam_http_api .DefinitionUri = "s3://foobar/foo.zip"
284
+ sam_http_api .DefinitionBody = {
285
+ "openapi" : "3.0.1" ,
286
+ "paths" : {"/foo" : {}, "/bar" : {}},
287
+ "info" : {"description" : "existing description" },
288
+ }
285
289
286
290
resources = sam_http_api .to_cloudformation (** self .kwargs )
287
- rest_api = [x for x in resources if isinstance (x , ApiGatewayV2HttpApi )]
288
- self .assertEqual (rest_api [0 ].Description , None )
291
+ http_api = [x for x in resources if isinstance (x , ApiGatewayV2HttpApi )]
292
+ self .assertEqual (http_api [0 ].Body . get ( "info" , {}). get ( "description" ), "existing description" )
289
293
290
294
@patch ("boto3.session.Session.region_name" , "eu-central-1" )
291
- def test_with_description (self ):
295
+ def test_with_no_definition_body (self ):
292
296
sam_http_api = SamHttpApi ("foo" )
293
- sam_http_api .DefinitionUri = "s3://foobar/foo.zip"
294
297
sam_http_api .Description = "my description"
295
298
299
+ with self .assertRaises (InvalidResourceException ) as context :
300
+ sam_http_api .to_cloudformation (** self .kwargs )
301
+ self .assertEqual (
302
+ context .exception .message ,
303
+ "Resource with id [foo] is invalid. "
304
+ "Description works only with inline OpenApi specified in the 'DefinitionBody' property." ,
305
+ )
306
+
307
+ @patch ("boto3.session.Session.region_name" , "eu-central-1" )
308
+ def test_with_description_defined_in_definition_body (self ):
309
+ sam_http_api = SamHttpApi ("foo" )
310
+ sam_http_api .DefinitionBody = {
311
+ "openapi" : "3.0.1" ,
312
+ "paths" : {"/foo" : {}, "/bar" : {}},
313
+ "info" : {"description" : "existing description" },
314
+ }
315
+ sam_http_api .Description = "new description"
316
+
317
+ with self .assertRaises (InvalidResourceException ) as context :
318
+ sam_http_api .to_cloudformation (** self .kwargs )
319
+ self .assertEqual (
320
+ context .exception .message ,
321
+ "Resource with id [foo] is invalid. "
322
+ "Unable to set Description because it is already defined within inline OpenAPI specified in the "
323
+ "'DefinitionBody' property." ,
324
+ )
325
+
326
+ @patch ("boto3.session.Session.region_name" , "eu-central-1" )
327
+ def test_with_description_not_defined_in_definition_body (self ):
328
+ sam_http_api = SamHttpApi ("foo" )
329
+ sam_http_api .DefinitionBody = {"openapi" : "3.0.1" , "paths" : {"/foo" : {}}, "info" : {}}
330
+ sam_http_api .Description = "new description"
331
+
296
332
resources = sam_http_api .to_cloudformation (** self .kwargs )
297
- rest_api = [x for x in resources if isinstance (x , ApiGatewayV2HttpApi )]
298
- self .assertEqual (rest_api [0 ].Description , "my description" )
333
+ http_api = [x for x in resources if isinstance (x , ApiGatewayV2HttpApi )]
334
+ self .assertEqual (http_api [0 ].Body . get ( "info" , {}). get ( "description" ), "new description" )
0 commit comments