Skip to content

Add Support for / in handler name #44

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

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions awslambdaric/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _get_handler(handler):
"Cannot use built-in module {} as a handler module".format(modname),
)
return make_fault_handler(fault)
modname = modname.replace("/", ".")
m = importlib.import_module(modname)
except ImportError as e:
fault = FaultException(
Expand Down
18 changes: 18 additions & 0 deletions tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,12 @@ def test_get_event_handler_missing_error(self):
returned_exception,
)

def test_get_event_handler_slash(self):
importlib.invalidate_caches()
handler_name = "tests/test_handler_with_slash/test_handler.my_handler"
response_handler = bootstrap._get_handler(handler_name)
response_handler()

def test_get_event_handler_build_in_conflict(self):
response_handler = bootstrap._get_handler("sys.hello")
with self.assertRaises(FaultException) as cm:
Expand All @@ -793,6 +799,18 @@ def test_get_event_handler_build_in_conflict(self):
returned_exception,
)

def test_get_event_handler_doesnt_throw_build_in_module_name_slash(self):
response_handler = bootstrap._get_handler(
"tests/test_built_in_module_name/sys.my_handler"
)
response_handler()

def test_get_event_handler_doent_throw_build_in_module_name(self):
response_handler = bootstrap._get_handler(
"tests.test_built_in_module_name.sys.my_handler"
)
response_handler()


class TestContentType(unittest.TestCase):
def setUp(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_built_in_module_name/sys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def my_handler():
return "Same name as Built in module, but different path"
2 changes: 2 additions & 0 deletions tests/test_handler_with_slash/test_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def my_handler():
return "Good with slash"