File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import json
12import cfn_resource
23
34
@@ -53,6 +54,29 @@ def wrapper(*args):
5354 "LogicalResourceId" : "FakeThing"
5455}
5556
57+ ### Tests for the wrapper function
58+
59+ import mock
60+
61+ @mock .patch ('urllib2.urlopen' )
62+ def test_client_code_failure (urlmock ):
63+ rsrc = cfn_resource .Resource ()
64+
65+ @rsrc .delete
66+ def flaky_function (* args ):
67+ raise KeyError ('Oopsie' )
68+
69+ resp = rsrc (base_event .copy (), FakeLambdaContext ())
70+
71+ args = urlmock .call_args
72+ sent_req = args [0 ][0 ]
73+
74+ assert sent_req .get_method () == 'PUT'
75+ reply = json .loads (sent_req .data )
76+ assert reply ['Status' ] == cfn_resource .FAILED
77+ assert reply ['StackId' ] == base_event ['StackId' ]
78+ assert reply ['Reason' ] == "Exception was raised while handling custom resource"
79+
5680### Tests for the Resource object and its decorator for wrapping
5781### user handlers
5882
You can’t perform that action at this time.
0 commit comments