def test_provider_get_all_with_no_apis(self): template = {} provider = SamApiProvider(template) result = [f for f in provider.get_all()] self.assertEquals(result, [])
def test_provider_get_all(self): template = { "Resources": { "SamFunc1": { "Type": "AWS::Serverless::Function", "Properties": { "CodeUri": "/usr/foo/bar", "Runtime": "nodejs4.3", "Handler": "index.handler", "Events": { "Event1": { "Type": "Api", "Properties": { "Path": "/path", "Method": "GET" } } } } }, "SamFunc2": { "Type": "AWS::Serverless::Function", "Properties": { "CodeUri": "/usr/foo/bar", "Runtime": "nodejs4.3", "Handler": "index.handler", "Events": { "Event1": { "Type": "Api", "Properties": { "Path": "/path", "Method": "POST" } } } } } } } provider = SamApiProvider(template) result = [f for f in provider.get_all()] api1 = Api(path="/path", method="GET", function_name="SamFunc1") api2 = Api(path="/path", method="POST", function_name="SamFunc2") self.assertIn(api1, result) self.assertIn(api2, result)
def test_provider_get_all(self): template = { "Resources": { "SamFunc1": { "Type": "AWS::Serverless::Function", "Properties": { "CodeUri": "/usr/foo/bar", "Runtime": "nodejs4.3", "Handler": "index.handler", "Events": { "Event1": { "Type": "Api", "Properties": { "Path": "/path", "Method": "GET" } } } } }, "SamFunc2": { "Type": "AWS::Serverless::Function", "Properties": { "CodeUri": "/usr/foo/bar", "Runtime": "nodejs4.3", "Handler": "index.handler", "Events": { "Event1": { "Type": "Api", "Properties": { "Path": "/path", "Method": "POST" } } } } } } } provider = SamApiProvider(template) result = [f for f in provider.get_all()] api1 = Api(path="/path", method="GET", function_name="SamFunc1", stage_name="Prod") api2 = Api(path="/path", method="POST", function_name="SamFunc2", stage_name="Prod") self.assertIn(api1, result) self.assertIn(api2, result)
def test_multi_stage_get_all(self): template = { "Resources": { "TestApi": { "Type": "AWS::Serverless::Api", "Properties": { "StageName": "dev", "Variables": { "vis": "data", "random": "test", "foo": "bar" }, "DefinitionBody": { "paths": { "/path2": { "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": {}, }, } } } } } }, "ProductionApi": { "Type": "AWS::Serverless::Api", "Properties": { "StageName": "Production", "Variables": { "vis": "prod data", "random": "test", "foo": "bar" }, "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": {}, }, } }, "/anotherpath": { "post": { "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 = SamApiProvider(template) result = [f for f in provider.get_all()] api1 = Api(path='/path2', method='GET', function_name='NoApiEventFunction', cors=None, binary_media_types=[], stage_name='dev', stage_variables={ "vis": "data", "random": "test", "foo": "bar" }) api2 = Api(path='/path', method='GET', function_name='NoApiEventFunction', cors=None, binary_media_types=[], stage_name='Production', stage_variables={'vis': 'prod data', 'random': 'test', 'foo': 'bar'}) api3 = Api(path='/anotherpath', method='POST', function_name='NoApiEventFunction', cors=None, binary_media_types=[], stage_name='Production', stage_variables={ "vis": "prod data", "random": "test", "foo": "bar" }) self.assertEquals(len(result), 3) self.assertIn(api1, result) self.assertIn(api2, result) self.assertIn(api3, result)