Skip to content

refactor(e2e-tests): use standard collections for types + refactor code #6505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

import pytest

from tests.e2e.utils.infrastructure import call_once
from tests.e2e.utils.lambda_layer.powertools_layer import LocalLambdaPowertoolsLayer

if TYPE_CHECKING:
from collections.abc import Generator


@pytest.fixture(scope="session", autouse=True)
def lambda_layer_build(tmp_path_factory: pytest.TempPathFactory, worker_id: str) -> str:
def lambda_layer_build(tmp_path_factory: pytest.TempPathFactory, worker_id: str) -> Generator[Any, Any, Any]:
"""Build Lambda Layer once before stacks are created

Parameters
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/data_masking/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tests.e2e.data_masking.infrastructure import DataMaskingStack
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/data_masking/handlers/basic_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_masking import DataMasking
from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import AWSEncryptionSDKProvider
Expand All @@ -17,7 +19,4 @@ def lambda_handler(event, context):
data_masker = DataMasking(provider=AWSEncryptionSDKProvider(keys=[kms_key]))
value = [1, 2, "string", 4.5]
encrypted_data = data_masker.encrypt(value)
response = {}
response["encrypted_data"] = encrypted_data

return response
return {"encrypted_data": encrypted_data}
2 changes: 2 additions & 0 deletions tests/e2e/data_masking/infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import aws_cdk.aws_kms as kms
from aws_cdk import CfnOutput, Duration
from aws_cdk import aws_iam as iam
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/data_masking/test_e2e_data_masking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
from uuid import uuid4

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tests.e2e.event_handler.infrastructure import EventHandlerStack
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/handlers/alb_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools.event_handler import (
ALBResolver,
CORSConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools.event_handler import (
ALBResolver,
Response,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools.event_handler import (
APIGatewayHttpResolver,
CORSConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools.event_handler import (
APIGatewayRestResolver,
CORSConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools.event_handler import (
CORSConfig,
LambdaFunctionUrlResolver,
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/handlers/openapi_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools.event_handler import (
APIGatewayRestResolver,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/event_handler/infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Optional
from __future__ import annotations

from aws_cdk import CfnOutput, Duration
from aws_cdk import aws_apigateway as apigwv1
Expand Down Expand Up @@ -28,7 +28,7 @@ def create_resources(self):
self._create_api_gateway_http(function=functions["ApiGatewayHttpHandler"])
self._create_lambda_function_url(function=functions["LambdaFunctionUrlHandler"])

def _create_alb(self, function: List[Function]):
def _create_alb(self, function: list[Function]):
vpc = ec2.Vpc.from_lookup(
self.stack,
"VPC",
Expand Down Expand Up @@ -58,7 +58,7 @@ def _create_alb_listener(
name: str,
port: int,
function: Function,
attributes: Optional[Dict[str, str]] = None,
attributes: dict[str, str] | None = None,
):
listener = alb.add_listener(name, port=port, protocol=elbv2.ApplicationProtocol.HTTP)
target = listener.add_targets(f"ALB{name}Target", targets=[targets.LambdaTarget(function)])
Expand All @@ -82,7 +82,7 @@ def _create_api_gateway_http(self, function: Function):

CfnOutput(self.stack, "APIGatewayHTTPUrl", value=(apigw.url or ""))

def _create_api_gateway_rest(self, function: List[Function]):
def _create_api_gateway_rest(self, function: list[Function]):
apigw = apigwv1.RestApi(
self.stack,
"APIGatewayRest",
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/test_cors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest
from requests import Request

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/test_header_serializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from uuid import uuid4

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/test_openapi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest
from requests import Request

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/test_paths_ending_with_slash.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest
from requests import HTTPError, Request

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler/test_response_code.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest
from requests import Request

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler_appsync/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tests.e2e.event_handler_appsync.infrastructure import EventHandlerAppSyncStack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import List, Optional
from __future__ import annotations

from typing import TYPE_CHECKING

from pydantic import BaseModel

from aws_lambda_powertools.event_handler import AppSyncResolver
from aws_lambda_powertools.utilities.data_classes import AppSyncResolverEvent
from aws_lambda_powertools.utilities.typing import LambdaContext

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.data_classes import AppSyncResolverEvent
from aws_lambda_powertools.utilities.typing import LambdaContext

app = AppSyncResolver()

Expand Down Expand Up @@ -84,29 +88,29 @@ def get_post(post_id: str = "") -> dict:


@app.resolver(type_name="Query", field_name="allPosts")
def all_posts() -> List[dict]:
def all_posts() -> list[dict]:
return list(posts.values())


# PROCESSING BATCH WITHOUT AGGREGATION
@app.batch_resolver(type_name="Post", field_name="relatedPosts", aggregate=False)
def related_posts(event: AppSyncResolverEvent) -> Optional[list]:
def related_posts(event: AppSyncResolverEvent) -> list | None:
return posts_related[event.source["post_id"]] if event.source else None


@app.async_batch_resolver(type_name="Post", field_name="relatedPostsAsync", aggregate=False)
async def related_posts_async(event: AppSyncResolverEvent) -> Optional[list]:
async def related_posts_async(event: AppSyncResolverEvent) -> list | None:
return posts_related[event.source["post_id"]] if event.source else None


# PROCESSING BATCH WITH AGGREGATION
@app.batch_resolver(type_name="Post", field_name="relatedPostsAggregate")
def related_posts_aggregate(event: List[AppSyncResolverEvent]) -> Optional[list]:
def related_posts_aggregate(event: list[AppSyncResolverEvent]) -> list | None:
return [posts_related[record.source.get("post_id")] for record in event]


@app.async_batch_resolver(type_name="Post", field_name="relatedPostsAsyncAggregate")
async def related_posts_async_aggregate(event: List[AppSyncResolverEvent]) -> Optional[list]:
async def related_posts_async_aggregate(event: list[AppSyncResolverEvent]) -> list | None:
return [posts_related[record.source.get("post_id")] for record in event]


Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/event_handler_appsync/infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

from aws_cdk import CfnOutput, Duration, Expiration
from aws_cdk import aws_appsync_alpha as appsync
from aws_cdk.aws_lambda import Function

from tests.e2e.utils.data_builder import build_random_value
from tests.e2e.utils.infrastructure import BaseInfrastructure

if TYPE_CHECKING:
from aws_cdk.aws_lambda import Function


class EventHandlerAppSyncStack(BaseInfrastructure):
def create_resources(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/event_handler_appsync/test_appsync_resolvers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/idempotency/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tests.e2e.idempotency.infrastructure import IdempotencyDynamoDBStack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import uuid

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import time

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import uuid

Expand Down
11 changes: 8 additions & 3 deletions tests/e2e/idempotency/handlers/response_hook.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING

from aws_lambda_powertools.utilities.idempotency import (
DynamoDBPersistenceLayer,
IdempotencyConfig,
idempotent,
)
from aws_lambda_powertools.utilities.idempotency.persistence.datarecord import (
DataRecord,
)

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.idempotency.persistence.datarecord import (
DataRecord,
)

TABLE_NAME = os.getenv("IdempotencyTable", "")
persistence_layer = DynamoDBPersistenceLayer(table_name=TABLE_NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import time

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/idempotency/handlers/ttl_cache_timeout_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import time

Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/idempotency/infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from aws_cdk import CfnOutput, Duration, RemovalPolicy
from aws_cdk import aws_dynamodb as dynamodb
from aws_cdk.aws_dynamodb import Table

if TYPE_CHECKING:
from aws_cdk.aws_dynamodb import Table

from tests.e2e.utils.infrastructure import BaseInfrastructure

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/idempotency/test_idempotency_dynamodb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
from copy import deepcopy
from time import sleep
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tests.e2e.logger.infrastructure import LoggerStack
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/handlers/basic_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Logger

logger = Logger()
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/handlers/buffer_logs_with_flush.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.buffer import LoggerBufferConfig

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/handlers/buffer_logs_without_flush.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.buffer import LoggerBufferConfig

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/handlers/multiple_logger_instances.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Logger

# Instance 1
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/handlers/tz_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import time

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from tests.e2e.utils.infrastructure import BaseInfrastructure


Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/logger/test_logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import os
import time
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/metrics/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tests.e2e.metrics.infrastructure import MetricsStack
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/metrics/handlers/basic_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Metrics

my_metrics = Metrics()
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/metrics/handlers/cold_start.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from aws_lambda_powertools import Metrics

my_metrics = Metrics()
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/metrics/infrastructure.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from tests.e2e.utils.infrastructure import BaseInfrastructure


Expand Down
Loading
Loading