Skip to content
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

fix: add missing tests, correct calls to DictWrapper constructor and improve metrics type hints #168

Merged
merged 4 commits into from
Sep 21, 2020
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
6 changes: 3 additions & 3 deletions aws_lambda_powertools/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MetricManager:

def __init__(
self,
metric_set: Dict[str, str] = None,
metric_set: Dict[str, Any] = None,
dimension_set: Dict = None,
namespace: str = None,
metadata_set: Dict[str, Any] = None,
Expand Down Expand Up @@ -125,7 +125,7 @@ def add_metric(self, name: str, unit: Union[MetricUnit, str], value: float):
raise MetricValueError(f"{value} is not a valid number")

unit = self.__extract_metric_unit_value(unit=unit)
metric = self.metric_set.get(name, defaultdict(list))
metric: Dict = self.metric_set.get(name, defaultdict(list))
metric["Unit"] = unit
metric["Value"].append(float(value))
logger.debug(f"Adding metric: {name} with {metric}")
Expand Down Expand Up @@ -185,7 +185,7 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
logger.debug({"details": "Serializing metrics", "metrics": metrics, "dimensions": dimensions})

metric_names_and_units: List[Dict[str, str]] = [] # [ { "Name": "metric_name", "Unit": "Count" } ]
metric_names_and_values: Dict[str, str] = {} # { "metric_name": 1.0 }
metric_names_and_values: Dict[str, float] = {} # { "metric_name": 1.0 }

for metric_name in metrics:
metric: dict = metrics[metric_name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ALBEvent(BaseProxyEvent):

@property
def request_context(self) -> ALBEventRequestContext:
return ALBEventRequestContext(self)
return ALBEventRequestContext(self._data)

@property
def http_method(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def multi_value_query_string_parameters(self) -> Optional[Dict[str, List[str]]]:

@property
def request_context(self) -> APIGatewayEventRequestContext:
return APIGatewayEventRequestContext(self)
return APIGatewayEventRequestContext(self._data)

@property
def path_parameters(self) -> Optional[Dict[str, str]]:
Expand Down Expand Up @@ -371,7 +371,7 @@ def cookies(self) -> Optional[List[str]]:

@property
def request_context(self) -> RequestContextV2:
return RequestContextV2(self)
return RequestContextV2(self._data)

@property
def path_parameters(self) -> Optional[Dict[str, str]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def user_name(self) -> str:
@property
def caller_context(self) -> CallerContext:
"""The caller context"""
return CallerContext(self)
return CallerContext(self._data)


class PreSignUpTriggerEventRequest(DictWrapper):
Expand Down Expand Up @@ -119,11 +119,11 @@ class PreSignUpTriggerEvent(BaseTriggerEvent):

@property
def request(self) -> PreSignUpTriggerEventRequest:
return PreSignUpTriggerEventRequest(self)
return PreSignUpTriggerEventRequest(self._data)

@property
def response(self) -> PreSignUpTriggerEventResponse:
return PreSignUpTriggerEventResponse(self)
return PreSignUpTriggerEventResponse(self._data)


class PostConfirmationTriggerEventRequest(DictWrapper):
Expand Down Expand Up @@ -156,7 +156,7 @@ class PostConfirmationTriggerEvent(BaseTriggerEvent):

@property
def request(self) -> PostConfirmationTriggerEventRequest:
return PostConfirmationTriggerEventRequest(self)
return PostConfirmationTriggerEventRequest(self._data)


class UserMigrationTriggerEventRequest(DictWrapper):
Expand Down Expand Up @@ -257,11 +257,11 @@ class UserMigrationTriggerEvent(BaseTriggerEvent):

@property
def request(self) -> UserMigrationTriggerEventRequest:
return UserMigrationTriggerEventRequest(self)
return UserMigrationTriggerEventRequest(self._data)

@property
def response(self) -> UserMigrationTriggerEventResponse:
return UserMigrationTriggerEventResponse(self)
return UserMigrationTriggerEventResponse(self._data)


class CustomMessageTriggerEventRequest(DictWrapper):
Expand Down Expand Up @@ -342,11 +342,11 @@ class CustomMessageTriggerEvent(BaseTriggerEvent):

@property
def request(self) -> CustomMessageTriggerEventRequest:
return CustomMessageTriggerEventRequest(self)
return CustomMessageTriggerEventRequest(self._data)

@property
def response(self) -> CustomMessageTriggerEventResponse:
return CustomMessageTriggerEventResponse(self)
return CustomMessageTriggerEventResponse(self._data)


class PreAuthenticationTriggerEventRequest(DictWrapper):
Expand Down Expand Up @@ -386,7 +386,7 @@ class PreAuthenticationTriggerEvent(BaseTriggerEvent):
@property
def request(self) -> PreAuthenticationTriggerEventRequest:
"""Pre Authentication Request Parameters"""
return PreAuthenticationTriggerEventRequest(self)
return PreAuthenticationTriggerEventRequest(self._data)


class PostAuthenticationTriggerEventRequest(DictWrapper):
Expand Down Expand Up @@ -428,7 +428,7 @@ class PostAuthenticationTriggerEvent(BaseTriggerEvent):
@property
def request(self) -> PostAuthenticationTriggerEventRequest:
"""Post Authentication Request Parameters"""
return PostAuthenticationTriggerEventRequest(self)
return PostAuthenticationTriggerEventRequest(self._data)


class GroupOverrideDetails(DictWrapper):
Expand Down Expand Up @@ -552,9 +552,9 @@ class PreTokenGenerationTriggerEvent(BaseTriggerEvent):
@property
def request(self) -> PreTokenGenerationTriggerEventRequest:
"""Pre Token Generation Request Parameters"""
return PreTokenGenerationTriggerEventRequest(self)
return PreTokenGenerationTriggerEventRequest(self._data)

@property
def response(self) -> PreTokenGenerationTriggerEventResponse:
"""Pre Token Generation Response Parameters"""
return PreTokenGenerationTriggerEventResponse(self)
return PreTokenGenerationTriggerEventResponse(self._data)
8 changes: 8 additions & 0 deletions tests/functional/validator/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def lambda_handler(evt, context):
lambda_handler(raw_event, {})


def test_validator_incoming_envelope(schema, apigateway_event):
@validator(inbound_schema=schema, envelope=envelopes.API_GATEWAY_REST)
def lambda_handler(evt, context):
pass

lambda_handler(apigateway_event, {})


def test_validator_outgoing(schema_response, raw_response):
@validator(outbound_schema=schema_response)
def lambda_handler(evt, context):
Expand Down