-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_custom_resource.py
57 lines (42 loc) · 1.87 KB
/
test_custom_resource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
import mock
import unittest
from mock import patch, Mock, MagicMock
import boto3
from botocore.stub import Stubber
import sys
sys.path.append("..")
import awslambda
from .lambda_helpers import MockLambdaContext, MockLambdaEvents
@patch('awslambda.utils.custom_resource.CFNCustomResource._send_response')
class TestCustomResourceHandler(unittest.TestCase):
def test_handler_create(self, mock_send_response):
"""
Test the custom resource handler creation operates as expected.
"""
test_context = MockLambdaContext()
test_event = MockLambdaEvents.cloudformation_creation
custom_resource = awslambda.utils.custom_resource.CFNCustomResource(test_event, test_context)
custom_resource.handler()
mock_send_response.assert_called_with('SUCCESS', {'Message': 'Resource creation successful!'})
return
def test_handler_update(self, mock_send_response):
"""
Test the custom resource handler update operates as expected.
"""
test_context = MockLambdaContext()
test_event = MockLambdaEvents.cloudformation_update
custom_resource = awslambda.utils.custom_resource.CFNCustomResource(test_event, test_context)
custom_resource.handler()
mock_send_response.assert_called_with('SUCCESS', {'Message': 'Resource update successful!'})
return
def test_handler_delete(self, mock_send_response):
"""
Test the custom resource handler deletion operates as expected.
"""
test_context = MockLambdaContext()
test_event = MockLambdaEvents.cloudformation_deletion
custom_resource = awslambda.utils.custom_resource.CFNCustomResource(test_event, test_context)
custom_resource.handler()
mock_send_response.assert_called_with('SUCCESS', {'Message': 'Resource deletion successful!'})
return