diff --git a/awslambdaric/bootstrap.py b/awslambdaric/bootstrap.py index a43078e..73f2679 100644 --- a/awslambdaric/bootstrap.py +++ b/awslambdaric/bootstrap.py @@ -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( diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 15ed6f7..b6f4b23 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -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: @@ -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): diff --git a/tests/test_built_in_module_name/sys.py b/tests/test_built_in_module_name/sys.py new file mode 100644 index 0000000..3008676 --- /dev/null +++ b/tests/test_built_in_module_name/sys.py @@ -0,0 +1,2 @@ +def my_handler(): + return "Same name as Built in module, but different path" diff --git a/tests/test_handler_with_slash/test_handler.py b/tests/test_handler_with_slash/test_handler.py new file mode 100644 index 0000000..45a5035 --- /dev/null +++ b/tests/test_handler_with_slash/test_handler.py @@ -0,0 +1,2 @@ +def my_handler(): + return "Good with slash"