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

feat: change api route class to receive endpoint as a string path #31

Merged
merged 1 commit into from
Nov 29, 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
7 changes: 4 additions & 3 deletions src/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def import_handler(path: str) -> Handler:


class APIRoute(routing.APIRoute):
def __init__(self, lambda_handler: Handler, *args, **kwargs):
super().__init__(endpoint=default_endpoint, *args, **kwargs)
self.lambda_handler = lambda_handler
def __init__(self, path: str, endpoint: str, *args, **kwargs):
handler_path = endpoint
handler_func = import_handler(handler_path)
super().__init__(path=path, endpoint=handler(handler_func), *args, **kwargs)
9 changes: 3 additions & 6 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@ def test_default_endpoint(self):
self.assertEqual(logs.output, expected_logs)

def test_route(self):
def handler(event, context):
print(f"event: {event}\ncontext: {context}")
return {"statusCode": 200, "body": ""}
endpoint = "tests.fixtures.handlers.lambda_handler.handler"

route = routing.APIRoute(path="/test", name="test", lambda_handler=handler)
route = routing.APIRoute(path="/test", name="test", endpoint=endpoint)

self.assertEqual(route.path, "/test")
self.assertEqual(route.name, "test")
self.assertEqual(route.methods, {"GET"})
self.assertIsInstance(route.endpoint, routing.default_endpoint.__class__)
self.assertIsInstance(route.lambda_handler, handler.__class__)
self.assertTrue(callable(route.endpoint))


class TestImportHandler(unittest.TestCase):
Expand Down