Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix key error in function events loop #42

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def route_mapping(self) -> None:
self.routes["ImplicitGateway"] = {}

for function in self.template.functions:
if "Events" not in function["Properties"]:
continue

code_uri = function["Properties"]["CodeUri"]
handler = function["Properties"]["Handler"]
handler_path = f"{code_uri}.{handler}".replace("/", "")
Expand Down
23 changes: 15 additions & 8 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@

class TestSAM(unittest.TestCase):
def test_initialization(self):
app = FastAPI()
template_path = "tests/fixtures/templates/example2.yml"
sam = SAM(app, template_path)
templates = [
{"template_path": "tests/fixtures/templates/example1.yml", "expected_route_count": 1},
{"template_path": "tests/fixtures/templates/example2.yml", "expected_route_count": 2},
{"template_path": "tests/fixtures/templates/example3.yml", "expected_route_count": 2},
]

self.assertIsInstance(sam, SAM)
self.assertEqual(id(app), id(sam.app))
self.assertIsInstance(sam.template, CloudformationTemplate)
self.assertIsInstance(sam.routes, dict)
self.assertGreater(len(sam.routes), 0)
for template in templates:
with self.subTest(template_path=template["template_path"]):
app = FastAPI()
sam = SAM(app, template["template_path"])

self.assertIsInstance(sam, SAM)
self.assertEqual(id(app), id(sam.app))
self.assertIsInstance(sam.template, CloudformationTemplate)
self.assertIsInstance(sam.routes, dict)
self.assertGreaterEqual(len(sam.routes), template["expected_route_count"])