def test_api_provider_sam_function(self): resources = { "TestApi": { "Type": "AWS::Serverless::Function", "Properties": { "StageName": "dev", "DefinitionBody": { "paths": { "/path": { "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31" "/functions/${NoApiEventFunction.Arn}/invocations" }, "responses": {}, } } } } }, }, } } provider = ApiProvider.find_api_provider(resources) self.assertTrue(isinstance(provider, SamApiProvider))
def test_api_provider_cloud_formation(self): resources = { "TestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "StageName": "dev", "Body": { "paths": { "/path": { "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31" "/functions/${NoApiEventFunction.Arn}/invocations" }, "responses": {}, } } } } }, }, } } provider = ApiProvider.find_api_provider(self.make_mock_stacks_with_resources(resources)) self.assertTrue(isinstance(provider, CfnApiProvider))
def test_provider_with_valid_template(self, extract_api_mock): extract_api_mock.return_value = Api(routes={"set", "of", "values"}) template = {"Resources": {"a": "b"}} stack_mock = Mock(template_dict=template, resources=template["Resources"]) provider = ApiProvider([stack_mock]) self.assertEqual(len(provider.routes), 3) self.assertEqual(provider.routes, set(["set", "of", "values"]))
def test_provider_with_valid_template(self, SamBaseProviderMock, extract_api_mock): extract_api_mock.return_value = Api(routes={"set", "of", "values"}) template = {"Resources": {"a": "b"}} SamBaseProviderMock.get_template.return_value = template provider = ApiProvider(template) self.assertEqual(len(provider.routes), 3) self.assertEqual(provider.routes, set(["set", "of", "values"])) self.assertEqual(provider.template_dict, {"Resources": {"a": "b"}}) self.assertEqual(provider.resources, {"a": "b"})
def __init__(self, lambda_invoke_context, port, host, static_dir): """ Initialize the local API service. :param samcli.commands.local.cli_common.invoke_context.InvokeContext lambda_invoke_context: Context object that can help with Lambda invocation :param int port: Port to listen on :param string host: Local hostname or IP address to bind to :param string static_dir: Optional, directory from which static files will be mounted """ self.port = port self.host = host self.static_dir = static_dir self.cwd = lambda_invoke_context.get_cwd() self.api_provider = ApiProvider(lambda_invoke_context.stacks, cwd=self.cwd) self.lambda_runner = lambda_invoke_context.local_lambda_runner self.stderr_stream = lambda_invoke_context.stderr