Skip to content

Commit

Permalink
Merge pull request #45 from preearor/main
Browse files Browse the repository at this point in the history
Add Support for / in handler name
  • Loading branch information
preearor authored Jun 25, 2021
2 parents a772d90 + 484d932 commit 7b3d0f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
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"

0 comments on commit 7b3d0f8

Please sign in to comment.