Skip to content

Commit a82e959

Browse files
author
Michal Ploski
committed
Add missing tests
1 parent 862c67e commit a82e959

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/functional/idempotency/test_idempotency.py

+23
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,29 @@ def test_data_record_invalid_status_value():
648648
assert e.value.args[0] == "UNSUPPORTED_STATUS"
649649

650650

651+
def test_data_record_json_to_dict_mapping():
652+
# GIVEN a data record with status "COMPLETED" and provided response data
653+
data_record = DataRecord(
654+
"key", status="INPROGRESS", response_data='{"body": "execution finished","statusCode": "200"}'
655+
)
656+
657+
# WHEN translating response data to dictionary
658+
response_data = data_record.response_json_as_dict()
659+
660+
# THEN return dictionary
661+
assert isinstance(response_data, dict)
662+
663+
664+
def test_data_record_json_to_dict_mapping_when_response_data_none():
665+
# GIVEN a data record with status "INPROGRESS" and not set response data
666+
data_record = DataRecord("key", status="INPROGRESS", response_data=None)
667+
# WHEN translating response data to dictionary
668+
response_data = data_record.response_json_as_dict()
669+
670+
# THEN return null value
671+
assert response_data is None
672+
673+
651674
@pytest.mark.parametrize("idempotency_config", [{"use_local_cache": True}], indirect=True)
652675
def test_in_progress_never_saved_to_cache(
653676
idempotency_config: IdempotencyConfig, persistence_store: DynamoDBPersistenceLayer

tests/functional/test_metrics.py

+20
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,29 @@ def lambda_handler(evt, context):
493493

494494
output = capture_metrics_output(capsys)
495495

496+
# THEN ColdStart metric and function_name and service dimension should be logged
497+
assert output["ColdStart"] == [1.0]
498+
assert output["function_name"] == "example_fn"
499+
assert output['service'] == service
500+
501+
def test_log_metrics_capture_cold_start_metric_no_service(capsys, namespace):
502+
# GIVEN Metrics is initialized without service
503+
my_metrics = Metrics(namespace=namespace)
504+
505+
# WHEN log_metrics is used with capture_cold_start_metric
506+
@my_metrics.log_metrics(capture_cold_start_metric=True)
507+
def lambda_handler(evt, context):
508+
pass
509+
510+
LambdaContext = namedtuple("LambdaContext", "function_name")
511+
lambda_handler({}, LambdaContext("example_fn"))
512+
513+
output = capture_metrics_output(capsys)
514+
496515
# THEN ColdStart metric and function_name dimension should be logged
497516
assert output["ColdStart"] == [1.0]
498517
assert output["function_name"] == "example_fn"
518+
assert output.get('service') is None
499519

500520

501521
def test_emit_cold_start_metric_only_once(capsys, namespace, service, metric):

0 commit comments

Comments
 (0)