コード例 #1
0
    def test_handler_dispatches_resource_group_provided_resource_handler(self):

        test_resource_group_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'plugin'))

        with mock.patch.object(custom_resource,
                               'PLUGIN_DIRECTORY_PATH',
                               new=test_resource_group_dir):

            calls_file_path = os.path.join(os.path.dirname(__file__), 'plugin',
                                           'TestPlugin', 'calls')

            path_before = copy.copy(sys.path)

            if os.path.exists(calls_file_path):
                os.remove(calls_file_path)

            event = {'ResourceType': 'Custom::Test'}

            context = {}

            # We call it twice so we can verify that the module is not being reloaded on
            # every request.

            custom_resource.handler(event, context)
            custom_resource.handler(event, context)

            with open(calls_file_path, 'r') as file:
                test_handler_calls = file.read()
                self.assertEqual(test_handler_calls, "1\n2\n")

            self.assertEquals(path_before, sys.path)
コード例 #2
0
    def test_handler_dispatches_resource_group_provided_resource_handler(self):

        test_resource_group_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'plugin'))

        with mock.patch.object(custom_resource,
                               'PLUGIN_DIRECTORY_PATH',
                               new=test_resource_group_dir):

            event = {'ResourceType': 'Custom::Test'}

            context = {}

            # We don't load the TestPlugin module so as to not interfere with
            # the loading process we are testing. Instead that module will load this
            # test module and call the test_handler_called method, which we will verify.
            #
            # We call it twice so we can verify that the module is not being reloaded on
            # every request.

            custom_resource.handler(event, context)
            custom_resource.handler(event, context)

            global test_handler_calls
            self.assertEqual(test_handler_calls, [1, 2])
コード例 #3
0
    def test_handler_dispatches_LambdaConfiguration(self):

        event = {'ResourceType': 'Custom::LambdaConfiguration'}

        context = {}

        with mock.patch.object(LambdaConfigurationResourceHandler,
                               'handler') as mock_handler:
            custom_resource.handler(event, context)
            mock_handler.assert_called_with(event, context)
コード例 #4
0
    def test_handler_dispatches_AccessControl(self):

        event = {'ResourceType': 'Custom::AccessControl'}

        context = {}

        with mock.patch.object(AccessControlResourceHandler,
                               'handler') as mock_handler:
            custom_resource.handler(event, context)
            mock_handler.assert_called_with(event, context)