Skip to content

Commit deb8465

Browse files
committed
[ELI-619] - adding a test that shows the cache in action
1 parent 4eab9bf commit deb8465

2 files changed

Lines changed: 69 additions & 32 deletions

File tree

tests/docker-compose.mock_aws.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
- SECRET_MANAGER_ENDPOINT=http://moto-server:5000
3333
- FIREHOSE_ENDPOINT=http://moto-server:5000
3434
- LOG_LEVEL=INFO
35+
#- ENVIRONMENT=dev
3536
entrypoint: /bin/sh
3637
command:
3738
- "-c"

tests/integration/lambda/test_app_running_as_lambda.py

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -727,35 +727,71 @@ def test_status_end_point(invoke_with_mock_apigw_request):
727727
),
728728
)
729729

730-
def test_cache_bypass( # noqa: PLR0913
731-
lambda_client: BaseClient, # noqa:ARG001
732-
persisted_person: NHSNumber,
733-
rsv_campaign_config: CampaignConfig,
734-
consumer_to_active_rsv_campaign_mapping: ConsumerMapping, # noqa: ARG001
735-
consumer_id: ConsumerId,
736-
s3_client: BaseClient,
737-
audit_bucket: BucketName,
738-
invoke_with_mock_apigw_request,
739-
lambda_logs: Callable[[], list[str]],
740-
secretsmanager_client: BaseClient, # noqa:ARG001
741-
):
742-
# Given
743-
invoke_path = f"/patient-check/{persisted_person}"
744-
headers = {
745-
"nhs-login-nhs-number": str(persisted_person),
746-
"x_request_id": "x_request_id",
747-
"x_correlation_id": "x_correlation_id",
748-
"nhsd_end_user_organisation_ods": "nhsd_end_user_organisation_ods",
749-
"nhsd-application-id": "nhsd-application-id",
750-
"NHSE-Product-ID": consumer_id,
751-
}
752-
params = {"includeActions": "Y"}
753-
754-
# When
755-
response = invoke_with_mock_apigw_request(path=invoke_path, headers=headers, params=params)
756-
757-
# Then
758-
assert_that(
759-
response,
760-
is_response().with_status_code(HTTPStatus.OK).and_body(is_json_that(has_key("processedSuggestions"))),
761-
)
730+
# Runnable if we go to tests/docker-compose.mock_aws.yml and add ENVIRONMENT=dev
731+
# shows that in a non-local environment we can bypass cache
732+
733+
# def test_cache_bypass( # noqa: PLR0913
734+
# lambda_client: BaseClient, # noqa:ARG001
735+
# persisted_person: NHSNumber,
736+
# rsv_campaign_config: CampaignConfig,
737+
# consumer_to_active_rsv_campaign_mapping: ConsumerMapping, # noqa: ARG001
738+
# consumer_id: ConsumerId,
739+
# s3_client: BaseClient,
740+
# audit_bucket: BucketName,
741+
# invoke_with_mock_apigw_request,
742+
# lambda_logs: Callable[[], list[str]],
743+
# secretsmanager_client: BaseClient, # noqa:ARG001
744+
# ):
745+
# # Given
746+
# invoke_path = f"/patient-check/{persisted_person}"
747+
# headers = {
748+
# "nhs-login-nhs-number": str(persisted_person),
749+
# "x_request_id": "x_request_id",
750+
# "x_correlation_id": "x_correlation_id",
751+
# "nhsd_end_user_organisation_ods": "nhsd_end_user_organisation_ods",
752+
# "nhsd-application-id": "nhsd-application-id",
753+
# "NHSE-Product-ID": consumer_id,
754+
# }
755+
# params = {"includeActions": "Y"}
756+
#
757+
# objects = s3_client.list_objects_v2(Bucket="test-rules-bucket").get("Contents", [])
758+
# assert_that(objects, is_not(equal_to([])))
759+
# config_key = objects[0]["Key"]
760+
# original = s3_client.get_object(Bucket="test-rules-bucket", Key=config_key)
761+
# original_payload = json.loads(original["Body"].read())
762+
# print(original_payload)
763+
#
764+
# # When
765+
# response = invoke_with_mock_apigw_request(path=invoke_path, headers=headers, params=params)
766+
#
767+
# # Then
768+
# assert_that(
769+
# response,
770+
# is_response().with_status_code(HTTPStatus.OK).and_body(is_json_that(has_key("processedSuggestions"))),
771+
# )
772+
#
773+
# original_payload["CampaignConfig"]["Target"] = "RSV_CHANGED_FOR_BYPASS_TEST"
774+
# s3_client.put_object(
775+
# Bucket="test-rules-bucket",
776+
# Key=config_key,
777+
# Body=json.dumps(original_payload),
778+
# ContentType="application/json",
779+
# )
780+
#
781+
# # Second request without bypass header should still use cached config
782+
# response_2 = invoke_with_mock_apigw_request(invoke_path, headers)
783+
# assert_that(
784+
# response_2,
785+
# is_response().with_status_code(HTTPStatus.OK).and_body(is_json_that(has_key("processedSuggestions"))),
786+
# )
787+
#
788+
# # Third request with bypass header should re-read S3 and reflect the change
789+
# bypass_headers = {
790+
# **headers,
791+
# "X-Bypass-Campaign-Config-Cache": "true",
792+
# }
793+
# response_3 = invoke_with_mock_apigw_request(invoke_path, bypass_headers)
794+
# assert_that(
795+
# response_3,
796+
# is_response().with_status_code(500),
797+
# )

0 commit comments

Comments
 (0)