Skip to content

Commit ea23a5f

Browse files
committed
Make _succeed function return a callable
1 parent dc6e240 commit ea23a5f

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

cfn_resource.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ def __init__(self, wrapper=wrap_user_handler):
7777
def __call__(self, event, context):
7878
request = event['RequestType']
7979
logger.debug("Received {} type event. Full parameters: {}".format(request, json.dumps(event)))
80-
return self._dispatch.get(request, self._succeed)(event, context)
81-
82-
def _succeed(self, event, context):
83-
return {
84-
'Status': SUCCESS,
85-
'PhysicalResourceId': event.get('PhysicalResourceId', 'mock-resource-id'),
86-
'Reason': 'Life is good, man',
87-
'Data': {},
88-
}
80+
return self._dispatch.get(request, self._succeed())(event, context)
81+
82+
def _succeed(self):
83+
@self._wrapper
84+
def success(event, context):
85+
return {
86+
'Status': SUCCESS,
87+
'PhysicalResourceId': event.get('PhysicalResourceId', 'mock-resource-id'),
88+
'Reason': 'Life is good, man',
89+
'Data': {},
90+
}
91+
return success
8992

9093
def create(self, wraps):
9194
self._dispatch['Create'] = self._wrapper(wraps)

test_cfn_resource.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,23 @@ def flaky_function(*args):
7171
args = urlmock.call_args
7272
sent_req = args[0][0]
7373

74-
assert sent_req.get_method() == 'PUT'
7574
reply = json.loads(sent_req.data)
75+
7676
assert reply['Status'] == cfn_resource.FAILED
7777
assert reply['StackId'] == base_event['StackId']
7878
assert reply['Reason'] == "Exception was raised while handling custom resource"
7979

80+
@mock.patch('urllib2.urlopen')
81+
def test_sends_put_request(urlmock):
82+
rsrc = cfn_resource.Resource()
83+
84+
resp = rsrc(base_event.copy(), FakeLambdaContext())
85+
86+
args = urlmock.call_args
87+
sent_req = args[0][0]
88+
89+
assert sent_req.get_method() == 'PUT'
90+
8091
### Tests for the Resource object and its decorator for wrapping
8192
### user handlers
8293

0 commit comments

Comments
 (0)