Skip to content

Commit

Permalink
Add tests for proxy resource and path params of API Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
53ningen committed Jul 11, 2019
1 parent e0eb0ce commit 9e9a71a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/model/eventsources/test_api_event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ def test_get_permission_with_trailing_slash(self):

self.assertEqual(arn, "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/foo")

@patch("boto3.session.Session.region_name", "eu-west-2")
def test_get_permission_with_path_parameter(self):
self.api_event_source.Path = "/foo/{userId}/bar"
cfn = self.api_event_source.to_cloudformation(function=self.func, explicit_api={})

perm = cfn[0]
self.assertIsInstance(perm, LambdaPermission)

try:
arn = self._extract_path_from_arn("{}PermissionTest".format(self.logical_id), perm)
except AttributeError:
self.fail("Permission class isn't valid")

self.assertEqual(arn, "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/foo/*/bar")

@patch("boto3.session.Session.region_name", "eu-west-2")
def test_get_permission_with_proxy_resource(self):
self.api_event_source.Path = "/foo/{proxy+}"
cfn = self.api_event_source.to_cloudformation(function=self.func, explicit_api={})

perm = cfn[0]
self.assertIsInstance(perm, LambdaPermission)

try:
arn = self._extract_path_from_arn("{}PermissionTest".format(self.logical_id), perm)
except AttributeError:
self.fail("Permission class isn't valid")

self.assertEqual(arn, "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/foo/*")

@patch("boto3.session.Session.region_name", "eu-west-2")
def test_get_permission_with_just_slash(self):
self.api_event_source.Path = "/"
Expand Down

0 comments on commit 9e9a71a

Please sign in to comment.