From 52b06350c24436dda27f9b6d12782443a9d50702 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 19 Jun 2024 14:01:30 +0100 Subject: [PATCH 1/2] Adding Middlware Factory test --- noxfile.py | 6 +++- .../_aws_xray_sdk}/__init__.py | 0 .../test_middleware_factory_tracing.py | 32 +++++++++++++++++++ .../required_dependencies/__init__.py | 0 .../test_middleware_factory.py | 31 ------------------ .../tracing/_aws_xray_sdk/__init__.py | 0 .../test_tracing.py | 0 7 files changed, 37 insertions(+), 32 deletions(-) rename tests/functional/{tracing/aws_xray_sdk => middleware_factory/_aws_xray_sdk}/__init__.py (100%) create mode 100644 tests/functional/middleware_factory/_aws_xray_sdk/test_middleware_factory_tracing.py create mode 100644 tests/functional/middleware_factory/required_dependencies/__init__.py rename tests/functional/{ => middleware_factory/required_dependencies}/test_middleware_factory.py (80%) create mode 100644 tests/functional/tracing/_aws_xray_sdk/__init__.py rename tests/functional/tracing/{aws_xray_sdk => _aws_xray_sdk}/test_tracing.py (100%) diff --git a/noxfile.py b/noxfile.py index ca8c157d19b..857d9be649e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -52,11 +52,13 @@ def test_with_only_required_packages(session: nox.Session): # Logger # Metrics - Amazon CloudWatch EMF # Metrics - Base provider + # Middleware factory without tracer build_and_run_test( session, folders=[ f"{PREFIX_TESTS_FUNCTIONAL}/logger/required_dependencies/", f"{PREFIX_TESTS_FUNCTIONAL}/metrics/required_dependencies/", + f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/required_dependencies/", ], ) @@ -78,10 +80,12 @@ def test_with_datadog_as_required_package(session: nox.Session): def test_with_xray_sdk_as_required_package(session: nox.Session): """Tests that depends on AWS XRAY SDK library""" # Tracer + # Middleware factory with tracer build_and_run_test( session, folders=[ - f"{PREFIX_TESTS_FUNCTIONAL}/tracing/aws_xray_sdk/", + f"{PREFIX_TESTS_FUNCTIONAL}/tracing/_aws_xray_sdk/", + f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/_aws_xray_sdk/", ], extras="tracer", ) diff --git a/tests/functional/tracing/aws_xray_sdk/__init__.py b/tests/functional/middleware_factory/_aws_xray_sdk/__init__.py similarity index 100% rename from tests/functional/tracing/aws_xray_sdk/__init__.py rename to tests/functional/middleware_factory/_aws_xray_sdk/__init__.py diff --git a/tests/functional/middleware_factory/_aws_xray_sdk/test_middleware_factory_tracing.py b/tests/functional/middleware_factory/_aws_xray_sdk/test_middleware_factory_tracing.py new file mode 100644 index 00000000000..0e19ac39aa3 --- /dev/null +++ b/tests/functional/middleware_factory/_aws_xray_sdk/test_middleware_factory_tracing.py @@ -0,0 +1,32 @@ +from aws_lambda_powertools.middleware_factory import lambda_handler_decorator + + +def test_factory_explicit_tracing(monkeypatch): + monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true") + + @lambda_handler_decorator(trace_execution=True) + def no_op(handler, event, context): + ret = handler(event, context) + return ret + + @no_op + def lambda_handler(evt, ctx): + return True + + lambda_handler({}, {}) + + +def test_factory_explicit_tracing_env_var(monkeypatch): + monkeypatch.setenv("POWERTOOLS_TRACE_MIDDLEWARES", "true") + monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true") + + @lambda_handler_decorator + def no_op(handler, event, context): + ret = handler(event, context) + return ret + + @no_op + def lambda_handler(evt, ctx): + return True + + lambda_handler({}, {}) diff --git a/tests/functional/middleware_factory/required_dependencies/__init__.py b/tests/functional/middleware_factory/required_dependencies/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/test_middleware_factory.py b/tests/functional/middleware_factory/required_dependencies/test_middleware_factory.py similarity index 80% rename from tests/functional/test_middleware_factory.py rename to tests/functional/middleware_factory/required_dependencies/test_middleware_factory.py index fb868cef0ee..7481e2b8f6b 100644 --- a/tests/functional/test_middleware_factory.py +++ b/tests/functional/middleware_factory/required_dependencies/test_middleware_factory.py @@ -62,37 +62,6 @@ def lambda_handler(evt, ctx): lambda_handler({}, {}) -def test_factory_explicit_tracing(monkeypatch): - monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true") - - @lambda_handler_decorator(trace_execution=True) - def no_op(handler, event, context): - ret = handler(event, context) - return ret - - @no_op - def lambda_handler(evt, ctx): - return True - - lambda_handler({}, {}) - - -def test_factory_explicit_tracing_env_var(monkeypatch): - monkeypatch.setenv("POWERTOOLS_TRACE_MIDDLEWARES", "true") - monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true") - - @lambda_handler_decorator - def no_op(handler, event, context): - ret = handler(event, context) - return ret - - @no_op - def lambda_handler(evt, ctx): - return True - - lambda_handler({}, {}) - - def test_factory_decorator_with_kwarg_params(capsys): @lambda_handler_decorator def log_event(handler, event, context, log_event=False): diff --git a/tests/functional/tracing/_aws_xray_sdk/__init__.py b/tests/functional/tracing/_aws_xray_sdk/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/tracing/aws_xray_sdk/test_tracing.py b/tests/functional/tracing/_aws_xray_sdk/test_tracing.py similarity index 100% rename from tests/functional/tracing/aws_xray_sdk/test_tracing.py rename to tests/functional/tracing/_aws_xray_sdk/test_tracing.py From d11d9313451fe36405c1c6478a5ec11e20c9ce71 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 19 Jun 2024 14:09:48 +0100 Subject: [PATCH 2/2] Addressing Heitor's feedback --- noxfile.py | 2 +- tests/functional/{tracing => tracer}/__init__.py | 0 tests/functional/{tracing => tracer}/_aws_xray_sdk/__init__.py | 0 .../{tracing => tracer}/_aws_xray_sdk/test_tracing.py | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename tests/functional/{tracing => tracer}/__init__.py (100%) rename tests/functional/{tracing => tracer}/_aws_xray_sdk/__init__.py (100%) rename tests/functional/{tracing => tracer}/_aws_xray_sdk/test_tracing.py (100%) diff --git a/noxfile.py b/noxfile.py index 857d9be649e..56f56b8b63f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -84,7 +84,7 @@ def test_with_xray_sdk_as_required_package(session: nox.Session): build_and_run_test( session, folders=[ - f"{PREFIX_TESTS_FUNCTIONAL}/tracing/_aws_xray_sdk/", + f"{PREFIX_TESTS_FUNCTIONAL}/tracer/_aws_xray_sdk/", f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/_aws_xray_sdk/", ], extras="tracer", diff --git a/tests/functional/tracing/__init__.py b/tests/functional/tracer/__init__.py similarity index 100% rename from tests/functional/tracing/__init__.py rename to tests/functional/tracer/__init__.py diff --git a/tests/functional/tracing/_aws_xray_sdk/__init__.py b/tests/functional/tracer/_aws_xray_sdk/__init__.py similarity index 100% rename from tests/functional/tracing/_aws_xray_sdk/__init__.py rename to tests/functional/tracer/_aws_xray_sdk/__init__.py diff --git a/tests/functional/tracing/_aws_xray_sdk/test_tracing.py b/tests/functional/tracer/_aws_xray_sdk/test_tracing.py similarity index 100% rename from tests/functional/tracing/_aws_xray_sdk/test_tracing.py rename to tests/functional/tracer/_aws_xray_sdk/test_tracing.py