@@ -182,7 +182,10 @@ def test_resolvers_ref(name, instance, response):
182
182
],
183
183
)
184
184
def test_invalid_functions (name , instance , response ):
185
- _resolve (name , instance , response )
185
+ context = Context ()
186
+ context .mappings ["foo" ] = Map ({"first" : {"second" : "bar" }})
187
+
188
+ _resolve (name , instance , response , context = context )
186
189
187
190
188
191
@pytest .mark .parametrize (
@@ -221,6 +224,14 @@ def test_invalid_functions(name, instance, response):
221
224
{"Fn::FindInMap" : ["foo" , "bar" , "value" , {"DefaultValue" : "default" }]},
222
225
[("default" , deque ([4 , "DefaultValue" ]), None )],
223
226
),
227
+ (
228
+ "Valid FindInMap with a default value" ,
229
+ {"Fn::FindInMap" : ["foo" , "first" , "second" , {"DefaultValue" : "default" }]},
230
+ [
231
+ ("default" , deque ([4 , "DefaultValue" ]), None ),
232
+ ("bar" , deque ([2 ]), None ),
233
+ ],
234
+ ),
224
235
(
225
236
"Valid FindInMap with a bad mapping" ,
226
237
{"Fn::FindInMap" : ["bar" , "first" , "second" ]},
@@ -240,6 +251,18 @@ def test_invalid_functions(name, instance, response):
240
251
{"Fn::FindInMap" : ["bar" , "first" , "second" , {"DefaultValue" : "default" }]},
241
252
[("default" , deque ([4 , "DefaultValue" ]), None )],
242
253
),
254
+ (
255
+ "Valid FindInMap with a bad mapping and aws no value" ,
256
+ {
257
+ "Fn::FindInMap" : [
258
+ "bar" ,
259
+ "first" ,
260
+ "second" ,
261
+ {"DefaultValue" : {"Ref" : "AWS::NoValue" }},
262
+ ]
263
+ },
264
+ [],
265
+ ),
243
266
(
244
267
"Valid FindInMap with a bad top key" ,
245
268
{"Fn::FindInMap" : ["foo" , "second" , "first" ]},
@@ -298,3 +321,31 @@ def test_valid_functions(name, instance, response):
298
321
context .mappings ["foo" ] = Map ({"first" : {"second" : "bar" }})
299
322
300
323
_resolve (name , instance , response , context = context )
324
+
325
+
326
+ @pytest .mark .parametrize (
327
+ "name,instance,response" ,
328
+ [
329
+ (
330
+ "Invalid FindInMap with no mappings" ,
331
+ {"Fn::FindInMap" : [{"Ref" : "MyParameter" }, "B" , "C" ]},
332
+ [
333
+ (
334
+ None ,
335
+ deque ([]),
336
+ ValidationError (
337
+ ("{'Ref': 'MyParameter'} is not one of []" ),
338
+ path = deque (["Fn::FindInMap" , 0 ]),
339
+ ),
340
+ )
341
+ ],
342
+ ),
343
+ (
344
+ "Invalid FindInMap with no mappings and default value" ,
345
+ {"Fn::FindInMap" : ["A" , "B" , "C" , {"DefaultValue" : "default" }]},
346
+ [("default" , deque ([4 , "DefaultValue" ]), None )],
347
+ ),
348
+ ],
349
+ )
350
+ def test_no_mapping (name , instance , response ):
351
+ _resolve (name , instance , response )
0 commit comments