Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add support for / in handler name
  • Loading branch information
preearor committed Jun 25, 2021
commit 484d932cdbbb98097e51e3eb2b3fabf96efeebb7
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"