From 62bda598a7b8fb95124806cef29f113887c16b67 Mon Sep 17 00:00:00 2001 From: Rio Knightley Date: Wed, 23 Oct 2024 10:35:55 +0100 Subject: [PATCH] Update unit test formatting --- lambdas/tests/unit/enums/test_edge_presign_values.py | 3 ++- .../tests/unit/handlers/test_edge_presign_handler.py | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lambdas/tests/unit/enums/test_edge_presign_values.py b/lambdas/tests/unit/enums/test_edge_presign_values.py index 0a261f2fb..b5cea1d54 100644 --- a/lambdas/tests/unit/enums/test_edge_presign_values.py +++ b/lambdas/tests/unit/enums/test_edge_presign_values.py @@ -5,6 +5,7 @@ TABLE_NAME = "CloudFrontEdgeReference" NHS_DOMAIN = "example.gov.uk" +S3_DOMAIN = "example.gov.uk" EXPECTED_EDGE_NO_CLIENT_ERROR_MESSAGE = LambdaError.EdgeNoClient.value["message"] EXPECTED_EDGE_NO_CLIENT_ERROR_CODE = LambdaError.EdgeNoClient.value["err_code"] @@ -49,7 +50,7 @@ "authorization": [ {"key": "Authorization", "value": "Bearer token"} ], - "host": [{"key": "Host", "value": NHS_DOMAIN}], + "host": [{"key": "Host", "value": S3_DOMAIN}], }, "querystring": "X-Amz-Algorithm=algo&X-Amz-Credential=cred&X-Amz-Date=date" "&X-Amz-Expires=3600&X-Amz-SignedHeaders=signed" diff --git a/lambdas/tests/unit/handlers/test_edge_presign_handler.py b/lambdas/tests/unit/handlers/test_edge_presign_handler.py index c6b638229..5a9aef89f 100644 --- a/lambdas/tests/unit/handlers/test_edge_presign_handler.py +++ b/lambdas/tests/unit/handlers/test_edge_presign_handler.py @@ -45,7 +45,7 @@ def mock_edge_presign_service(mocker): def test_lambda_handler_success(valid_event, mock_edge_presign_service): context = mock_context() - # Add required headers for the test + valid_event["Records"][0]["cf"]["request"]["headers"][ "cloudfront-viewer-country" ] = [{"key": "CloudFront-Viewer-Country", "value": "US"}] @@ -67,7 +67,7 @@ def test_lambda_handler_success(valid_event, mock_edge_presign_service): def test_lambda_handler_missing_query_params(valid_event, mock_edge_presign_service): context = mock_context() event = copy.deepcopy(valid_event) - event["Records"][0]["cf"]["request"]["querystring"] = "" # Missing all query params + event["Records"][0]["cf"]["request"]["querystring"] = "" response = lambda_handler(event, context) actual_status = response["status"] @@ -81,7 +81,7 @@ def test_lambda_handler_missing_query_params(valid_event, mock_edge_presign_serv def test_lambda_handler_missing_headers(valid_event, mock_edge_presign_service): context = mock_context() event = copy.deepcopy(valid_event) - event["Records"][0]["cf"]["request"]["headers"] = {} # Clear all headers + event["Records"][0]["cf"]["request"]["headers"] = {} event["Records"][0]["cf"]["request"]["querystring"] = ( "X-Amz-Algorithm=algo&X-Amz-Credential=cred&X-Amz-Date=date" "&X-Amz-Expires=3600&X-Amz-SignedHeaders=signed" @@ -100,7 +100,7 @@ def test_lambda_handler_missing_headers(valid_event, mock_edge_presign_service): def test_lambda_handler_missing_origin(valid_event, mock_edge_presign_service): context = mock_context() event = copy.deepcopy(valid_event) - event["Records"][0]["cf"]["request"]["origin"] = {} # Missing origin data + event["Records"][0]["cf"]["request"]["origin"] = {} event["Records"][0]["cf"]["request"]["querystring"] = ( "X-Amz-Algorithm=algo&X-Amz-Credential=cred&X-Amz-Date=date" "&X-Amz-Expires=3600&X-Amz-SignedHeaders=signed" @@ -119,9 +119,7 @@ def test_lambda_handler_missing_origin(valid_event, mock_edge_presign_service): def test_lambda_handler_generic_edge_malformed(valid_event, mock_edge_presign_service): context = mock_context() event = copy.deepcopy(valid_event) - event["Records"][0]["cf"]["request"].pop( - "uri", None - ) # Remove URI to simulate KeyError + event["Records"][0]["cf"]["request"].pop("uri", None) response = lambda_handler(event, context) actual_status = response["status"]