Skip to content

Commit af8055c

Browse files
docker clean up
1 parent e7a15c5 commit af8055c

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

tests/integration/lambda/conftest.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ def lambda_runtime_url(request, lambda_zip): # noqa: ARG001
103103
check=lambda: is_responsive(base_url),
104104
)
105105

106-
return base_url
107-
106+
yield base_url
108107

109-
@pytest.fixture(scope="session")
110-
def lambda_client(boto3_session: Session, lambda_runtime_url: URL) -> BaseClient:
111-
"""Return a boto3 Lambda client pointing at the simulated lambda runtime."""
112-
return boto3_session.client("lambda", endpoint_url=str(lambda_runtime_url))
108+
subprocess.run( # noqa: S603
109+
[docker_path, "compose", "-f", str(compose_file), "rm", "-f", "-s", "lambda-api", "api-gateway-mock"],
110+
check=False,
111+
env=env,
112+
capture_output=True,
113+
text=True,
114+
)
113115

114116

115117
@pytest.fixture(scope="session")
@@ -134,6 +136,12 @@ def api_gateway_endpoint(request: pytest.FixtureRequest, lambda_runtime_url): #
134136
return base_url
135137

136138

139+
@pytest.fixture(scope="session")
140+
def lambda_client(boto3_session: Session, lambda_runtime_url: URL) -> BaseClient:
141+
"""Return a boto3 Lambda client pointing at the simulated lambda runtime."""
142+
return boto3_session.client("lambda", endpoint_url=str(lambda_runtime_url))
143+
144+
137145
@pytest.fixture
138146
def lambda_logs(docker_services) -> Callable[[], list[str]]:
139147
"""Return a callable that fetches the latest lambda-api logs."""
@@ -168,5 +176,4 @@ def get_lambda_logs(docker_services) -> list[str]: # noqa :ARG001
168176
text=True,
169177
check=False,
170178
)
171-
172-
return [line.partition("|")[-1].strip() for line in result.stdout.splitlines()]
179+
return [line.split("|", 1)[-1].strip() for line in result.stdout.splitlines()]

tests/integration/lambda/test_app_running_as_lambda.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
logger = logging.getLogger(__name__)
3131

3232

33-
def test_install_and_call_lambda_flask(
33+
def test_install_and_call_lambda_flask( # noqa: PLR0913
3434
lambda_client: BaseClient,
3535
persisted_person: NHSNumber,
3636
consumer_to_active_rsv_campaign_mapping: ConsumerMapping, # noqa: ARG001
3737
consumer_id: ConsumerId,
3838
secretsmanager_client: BaseClient, # noqa :ARG001
39+
lambda_logs: Callable[[], list[str]],
3940
):
4041
"""Given lambda installed into localstack, run it via boto3 lambda client"""
4142
# Given
42-
4343
# When
4444
request_payload = {
4545
"version": "2.0",
@@ -69,9 +69,7 @@ def test_install_and_call_lambda_flask(
6969
FunctionName="function",
7070
InvocationType="RequestResponse",
7171
Payload=json.dumps(request_payload),
72-
# LogType="Tail", #TODO
7372
)
74-
# log_output = base64.b64decode(response["LogResult"]).decode("utf-8")
7573

7674
# Then
7775
assert_that(response, has_entries(StatusCode=HTTPStatus.OK))
@@ -82,7 +80,8 @@ def test_install_and_call_lambda_flask(
8280
has_entries(statusCode=HTTPStatus.OK, body=is_json_that(has_key("processedSuggestions"))),
8381
)
8482

85-
# assert_that(log_output, contains_string("checking nhs_number"))
83+
messages = lambda_logs()
84+
assert_that(messages, has_item(contains_string("checking nhs_number")))
8685

8786

8887
def test_install_and_call_flask_lambda_over_http(

0 commit comments

Comments
 (0)