Skip to content

Commit

Permalink
EM-933. Merged in changes from other dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmarston-nhs committed Oct 1, 2024
2 parents 4f69672 + cad5a86 commit 0a8e7b5
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 246 deletions.
183 changes: 92 additions & 91 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
aws-lambda-powertools==2.43.1 ; python_version >= "3.11" and python_version < "4.0"
boto3-stubs[athena,dynamodb,events,firehose,kms,lambda,logs,s3,secretsmanager,ses,sns,sqs,ssm,stepfunctions]==1.35.19 ; python_version >= "3.11" and python_version < "4.0"
boto3==1.35.19 ; python_version >= "3.11" and python_version < "4.0"
botocore-stubs==1.35.19 ; python_version >= "3.11" and python_version < "4.0"
botocore==1.35.19 ; python_version >= "3.11" and python_version < "4.0"
boto3-stubs[athena,dynamodb,events,firehose,kms,lambda,logs,s3,secretsmanager,ses,sns,sqs,ssm,stepfunctions]==1.35.30 ; python_version >= "3.11" and python_version < "4.0"
boto3==1.35.30 ; python_version >= "3.11" and python_version < "4.0"
botocore-stubs==1.35.30 ; python_version >= "3.11" and python_version < "4.0"
botocore==1.35.30 ; python_version >= "3.11" and python_version < "4.0"
certifi==2024.8.30 ; python_version >= "3.11" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.11" and python_version < "4.0"
idna==3.10 ; python_version >= "3.11" and python_version < "4.0"
importlib-metadata==8.0.0 ; python_version >= "3.11" and python_version < "4.0"
jmespath==1.0.1 ; python_version >= "3.11" and python_version < "4.0"
mesh-client==3.2.3 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-athena==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-dynamodb==1.35.15 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-athena==1.35.25 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-dynamodb==1.35.24 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-events==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-firehose==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-kms==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-lambda==1.35.3 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-lambda==1.35.28 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-logs==1.35.12 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-s3==1.35.16 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-s3==1.35.22 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-secretsmanager==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-ses==1.35.3 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-sns==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-sqs==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-ssm==1.35.0 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-ssm==1.35.21 ; python_version >= "3.11" and python_version < "4.0"
mypy-boto3-stepfunctions==1.35.9 ; python_version >= "3.11" and python_version < "4.0"
nhs-aws-helpers==0.7.10 ; python_version >= "3.11" and python_version < "4.0"
nhs-aws-helpers==0.7.18 ; python_version >= "3.11" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.11" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.11" and python_version < "4.0"
s3transfer==0.10.2 ; python_version >= "3.11" and python_version < "4.0"
Expand Down
101 changes: 1 addition & 100 deletions tests/mocked/mesh_check_send_parameters_application_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from uuid import uuid4

Check failure on line 7 in tests/mocked/mesh_check_send_parameters_application_test.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

tests/mocked/mesh_check_send_parameters_application_test.py:7:18: F401 `uuid.uuid4` imported but unused

from nhs_aws_helpers import stepfunctions

Check failure on line 9 in tests/mocked/mesh_check_send_parameters_application_test.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

tests/mocked/mesh_check_send_parameters_application_test.py:9:29: F401 `nhs_aws_helpers.stepfunctions` imported but unused
import pytest

Check failure on line 10 in tests/mocked/mesh_check_send_parameters_application_test.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

tests/mocked/mesh_check_send_parameters_application_test.py:10:8: F401 `pytest` imported but unused

from .mesh_testing_common import CONTEXT, was_value_logged

Expand Down Expand Up @@ -163,106 +164,6 @@ def test_mesh_check_send_parameters_happy_path_unchunked(
assert was_value_logged(logs.out, "LAMBDA0003", "Log_Level", "INFO")


def test_running_as_singleton(
mesh_s3_bucket: str,
environment: str,
send_message_sfn_arn: str,
get_messages_sfn_arn: str,
capsys,
):
"""
Test that the singleton check works correctly
"""

print("------------------------- TEST 1 -------------------------------")

# 'start' fake state machine
sf_response = stepfunctions().start_execution(
stateMachineArn=send_message_sfn_arn,
input=json.dumps(sample_trigger_event(mesh_s3_bucket)),
)
step_func_exec_arn = sf_response.get("executionArn", None)
assert step_func_exec_arn is not None
# do running check - should pass (1 step function running, just mine)
from mesh_check_send_parameters_application import (
MeshCheckSendParametersApplication,
)

app = MeshCheckSendParametersApplication()

response = app.main(event=sample_trigger_event(mesh_s3_bucket), context=CONTEXT)
assert response is not None

logs = capsys.readouterr()

assert not was_value_logged(logs.out, "MESHSEND0003", "Log_Level", "ERROR")
assert was_value_logged(logs.out, "MESHSEND0004", "Log_Level", "INFO")
assert was_value_logged(logs.out, "MESHSEND0004a", "Log_Level", "INFO")

print("------------------------- TEST 2 -------------------------------")

# 'start' state machine 2 with my mailbox
sf_response = stepfunctions().start_execution(
stateMachineArn=get_messages_sfn_arn,
input=json.dumps(sample_trigger_event(mesh_s3_bucket)),
)
step_func_exec_arn = sf_response.get("executionArn", None)
assert step_func_exec_arn is not None

# do running check - should pass (1 step function of my name with my mailbox)
response = app.main(event=sample_trigger_event(mesh_s3_bucket), context=CONTEXT)
assert response is not None

logs = capsys.readouterr()
assert not was_value_logged(logs.out, "MESHSEND0003", "Log_Level", "ERROR")
assert was_value_logged(logs.out, "MESHSEND0004", "Log_Level", "INFO")
assert was_value_logged(logs.out, "MESHSEND0004a", "Log_Level", "INFO")

print("------------------------- TEST 3 -------------------------------")

# 'start' state machine with different mailbox
sf_response = stepfunctions().start_execution(
stateMachineArn=send_message_sfn_arn,
input=json.dumps(
sample_trigger_event(mesh_s3_bucket, f"X26ABC2/outbound/{uuid4().hex}.json")
),
)
step_func_exec_arn = sf_response.get("executionArn", None)
assert step_func_exec_arn is not None

# do running check - should pass (1 step function running with my mailbox)
response = app.main(event=sample_trigger_event(mesh_s3_bucket), context=CONTEXT)
assert response is not None

logs = capsys.readouterr()

assert not was_value_logged(logs.out, "MESHSEND0003", "Log_Level", "ERROR")
assert was_value_logged(logs.out, "MESHSEND0004", "Log_Level", "INFO")
assert was_value_logged(logs.out, "MESHSEND0004a", "Log_Level", "INFO")

print("------------------------- TEST 4 -------------------------------")

# 'start' another instance with same mailbox as mine
sf_response = stepfunctions().start_execution(
stateMachineArn=send_message_sfn_arn,
input=json.dumps(sample_trigger_event(mesh_s3_bucket)),
)
step_func_exec_arn = sf_response.get("executionArn", None)
assert step_func_exec_arn is not None
# do running check - should return 503 and log MESHSEND0003 error message
response = app.main(event=sample_trigger_event(mesh_s3_bucket), context=CONTEXT)
expected_return_code = {"statusCode": HTTPStatus.TOO_MANY_REQUESTS.value}
expected_header = {"Retry-After": 18000}
assert response == {**response, **expected_return_code}
assert response["headers"] == {**response["headers"], **expected_header}

logs = capsys.readouterr()

assert was_value_logged(logs.out, "MESHSEND0003", "Log_Level", "ERROR")
assert not was_value_logged(logs.out, "MESHSEND0004", "Log_Level", "INFO")
assert was_value_logged(logs.out, "MESHSEND0004a", "Log_Level", "INFO")


def sample_trigger_event(
bucket: str, key: str = "X26ABC2/outbound/testfile.json"
) -> dict:
Expand Down
45 changes: 0 additions & 45 deletions tests/mocked/mesh_send_message_chunk_application_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import json
import sys
from http import HTTPStatus

import pytest
from mesh_send_message_chunk_application import MaxByteExceededException
from nhs_aws_helpers import stepfunctions

from .mesh_check_send_parameters_application_test import sample_trigger_event
from .mesh_testing_common import (
CONTEXT,
FILE_CONTENT,
Expand Down Expand Up @@ -112,48 +109,6 @@ def test_mesh_send_file_chunk_app_too_many_chunks(
app.main(event=mock_input, context=CONTEXT)


def test_mesh_send_file_chunk_app_no_chunks_invoke_via_eventbridge(
environment: str,
mesh_s3_bucket: str,
send_message_sfn_arn: str,
capsys,
):
from mesh_send_message_chunk_application import MeshSendMessageChunkApplication

app = MeshSendMessageChunkApplication()

app.config.crumb_size = sys.maxsize
app.config.chunk_size = sys.maxsize
app.config.compress_threshold = 10

expected_lambda_response = _sample_output_invoked_via_event_bridge(mesh_s3_bucket)
expected_lambda_response["body"].update({"complete": True})
expected_lambda_response["body"].update(
{"current_byte_position": len(FILE_CONTENT)}
)

response = stepfunctions().start_execution(
stateMachineArn=send_message_sfn_arn,
input=json.dumps(sample_trigger_event(mesh_s3_bucket)),
)
step_func_exec_arn = response.get("executionArn", None)
assert step_func_exec_arn is not None

lambda_response = app.main(
event=sample_trigger_event(mesh_s3_bucket), context=CONTEXT
)

lambda_response["body"].pop("message_id")
lambda_response["body"].pop("internal_id")

assert lambda_response == expected_lambda_response
# Check completion
logs = capsys.readouterr()
assert was_value_logged(logs.out, "MESHSEND0002", "Log_Level", "INFO")
assert was_value_logged(logs.out, "MESHSEND0008", "Log_Level", "INFO")
assert was_value_logged(logs.out, "LAMBDA0003", "Log_Level", "INFO")


def _sample_single_chunk_input_event(bucket: str):
"""Return Example input event"""
return {
Expand Down

0 comments on commit 0a8e7b5

Please sign in to comment.