Skip to content

Commit

Permalink
fix: allow handlers with keyword arguments (#47)
Browse files Browse the repository at this point in the history
* fix: allow handlers with keyword arguments

Signed-off-by: heitorlessa <[email protected]>

* chore: restore old formatting

Signed-off-by: heitorlessa <[email protected]>

* fix format and ready release

---------

Signed-off-by: heitorlessa <[email protected]>
Co-authored-by: Ran Isenberg <[email protected]>
  • Loading branch information
heitorlessa and Ran Isenberg authored Oct 31, 2023
1 parent e730e92 commit a8238fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions aws_lambda_env_modeler/modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def init_environment_variables(model: Type[Model]):
def decorator(lambda_handler_function: Callable):

@wraps(lambda_handler_function)
def wrapper(event: Dict[str, Any], context):
def wrapper(event: Dict[str, Any], context, **kwargs):
__parse_model(model)
return lambda_handler_function(event, context)
return lambda_handler_function(event, context, **kwargs)

return wrapper

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aws_lambda_env_modeler"
version = "1.0.3"
version = "1.0.5"
description = "AWS-Lambda-Env-Modeler is a Python library designed to simplify the process of managing and validating environment variables in your AWS Lambda functions."
authors = ["Ran Isenberg"]
classifiers=[
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_env_vars_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ def my_handler(event, context) -> Dict[str, Any]:
return {}

my_handler({}, None)


def test_extended_handler_schema_ok(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv('POWERTOOLS_SERVICE_NAME', SERVICE_NAME)
monkeypatch.setenv('LOG_LEVEL', 'DEBUG')
monkeypatch.setenv('REST_API', 'https://www.ranthebuilder.cloud/api')

endpoint = os.environ['REST_API']

@init_environment_variables(model=MySchema)
def my_handler(event, context, endpoint=None):
return endpoint

assert my_handler({}, None, endpoint=endpoint) == endpoint

0 comments on commit a8238fa

Please sign in to comment.