Skip to content

Commit dc6e240

Browse files
committed
Add mock test for main wrapper
1 parent 12a8b0d commit dc6e240

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test_cfn_resource.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import 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

0 commit comments

Comments
 (0)