Skip to content

Commit

Permalink
Update unit test formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RioKnightleyNHS committed Oct 23, 2024
1 parent 506e32b commit 62bda59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lambdas/tests/unit/enums/test_edge_presign_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 5 additions & 7 deletions lambdas/tests/unit/handlers/test_edge_presign_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
Expand All @@ -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"]
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"]
Expand Down

0 comments on commit 62bda59

Please sign in to comment.