Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
API_KEY=api-key
APPLICATION_ID=application-id
COMMGT_BASE_URL=http://localhost:7071
DATABASE_USER=mpi_notify_user
DATABASE_PASSWORD=test
DATABASE_SID=FREEPDB1
DATABASE_HOST=localhost
DATABASE_PORT=1521
NOTIFY_API_BASE_URL=http://localhost:7071
OAUTH_API_KID=""
OAUTH_API_KEY=""
OAUTH_TOKEN_URL=""
Expand Down
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
API_KEY=api-key
APPLICATION_ID=application-id
COMMGT_BASE_URL=http://localhost:7071
DATABASE_USER=mpi_notify_user
DATABASE_PASSWORD=test
DATABASE_SID=FREEPDB1
DATABASE_HOST=localhost
DATABASE_PORT=1521
NOTIFY_API_BASE_URL=http://localhost:7071
OAUTH_API_KID=""
OAUTH_API_KEY=""
OAUTH_TOKEN_URL=""
Expand Down
42 changes: 21 additions & 21 deletions .github/workflows/test-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ jobs:
- name: "run unit testing:"
run: |
./test-unit.sh
contract-tests:
name: "Contract tests"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Install Python"
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: "Checkout code"
uses: actions/checkout@v4

- name: "Install dependencies"
run: |
pip install poetry
poetry install --no-root

- name: "Run contract tests"
run: |
./test-contract.sh
# contract-tests:
# name: "Contract tests"
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - name: "Install Python"
# uses: actions/setup-python@v5
# with:
# python-version: "3.13"
#
# - name: "Checkout code"
# uses: actions/checkout@v4
#
# - name: "Install dependencies"
# run: |
# pip install poetry
# poetry install --no-root
#
# - name: "Run contract tests"
# run: |
# ./test-contract.sh
integration-tests:
name: "Integration tests"
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions batch_notification_processor/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import batch_processor
import environment
import logging
import communication_management
import notify_api

def lambda_handler(_event: dict, _context: object) -> dict:
"""
Expand All @@ -19,7 +19,7 @@ def lambda_handler(_event: dict, _context: object) -> dict:
logging.info("Processing next batch. (batch_id: %s, routing_plan_id: %s, recipients: %s)", batch_id, routing_plan_id, recipients)

while routing_plan_id and recipients:
response = communication_management.send_batch_message(
response = notify_api.send_batch_message(
batch_id, routing_plan_id, recipients
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import access_token
import hashlib
import hmac
import json
import logging
import os
import uuid
from recipient import Recipient
Expand All @@ -18,17 +14,14 @@ def send_batch_message(
routing_config_id, batch_id, recipients
)

hmac_signature = generate_hmac_signature(request_body)
headers = {
"content-type": "application/vnd.api+json",
"accept": "application/vnd.api+json",
"x-correlation-id": str(uuid.uuid4()),
"x-api-key": os.getenv("API_KEY"),
"x-hmac-sha256-signature": hmac_signature,
"authorization": f"Bearer {access_token.get_token()}"
}

url = f"{os.getenv('COMMGT_BASE_URL')}/message/batch"
url = f"{os.getenv('NOTIFY_API_BASE_URL')}/comms/v1/message-batches"

response = requests.post(
url,
Expand All @@ -39,31 +32,6 @@ def send_batch_message(

return response


def get_read_messages(batch_reference: str) -> dict:
response = get_statuses(batch_reference)

if response.status_code == 201:
return response.json()

logging.error("Failed to fetch messages that have been read: %s ", response.text)
return {
"status": "error",
"message": f"Failed to fetch messages that have been read: {response.text}",
"data": [],
}


def get_statuses(batch_reference):
response = requests.get(
f"{os.getenv('COMMGT_BASE_URL')}/statuses",
headers={"x-api-key": os.getenv("API_KEY")},
params={"batchReference": batch_reference, "channel": "nhsapp", "supplierStatus": "read"},
timeout=10
)
return response


def generate_batch_message_request_body(
routing_config_id: str, message_batch_reference: str, recipients: list[Recipient]
) -> dict:
Expand Down Expand Up @@ -94,15 +62,3 @@ def generate_message(recipient) -> dict:
},
}
# pylint: enable=no-member


def generate_hmac_signature(request_body: dict) -> str:
return hmac.new(
bytes(secret(), 'ASCII'),
msg=bytes(json.dumps(request_body), 'ASCII'),
digestmod=hashlib.sha256
).hexdigest()


def secret() -> str:
return f"{os.getenv('APPLICATION_ID')}.{os.getenv('API_KEY')}"
4 changes: 2 additions & 2 deletions healthcheck/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def lambda_handler(_event, _context):
token = access_token.get_token()
logging.info("Access token: %s", token)

logging.info("Healthcheck lambda check #4: Make request to Communication Management API (CMAPI)")
response = requests.get(f"{os.getenv('COMMGT_BASE_URL')}/healthcheck", timeout=30)
logging.info("Healthcheck lambda check #4: Make request to NHS Notify API")
response = requests.get(f"{os.getenv('NOTIFY_API_BASE_URL')}/healthcheck", timeout=30)
logging.info("Response from CMAPI healthcheck: %s", response.status_code)
logging.info(response.text)
logging.info("CMAPI check complete")
Expand Down
2 changes: 1 addition & 1 deletion shared/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
KEYS = [
"API_KEY",
"APPLICATION_ID",
"COMMGT_BASE_URL",
"DATABASE_HOST",
"DATABASE_PASSWORD",
"DATABASE_PORT",
"DATABASE_SID",
"DATABASE_USER",
"NOTIFY_API_BASE_URL",
"OAUTH_API_KEY",
"OAUTH_API_KID",
"OAUTH_TOKEN_URL",
Expand Down
2 changes: 1 addition & 1 deletion tests/end_to_end/runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ FROM --platform=$BUILDPLATFORM python:3.13-bullseye AS builder

ENV API_KEY=${API_KEY} \
APPLICATION_ID=${APPLICATION_ID} \
COMMGT_BASE_URL=${COMMGT_BASE_URL} \
DATABASE_USER=${DATABASE_USER} \
DATABASE_PASSWORD=${DATABASE_PASSWORD} \
DATABASE_SID=${DATABASE_SID} \
DATABASE_HOST=${DATABASE_HOST} \
DATABASE_PORT=${DATABASE_PORT} \
NOTIFY_API_BASE_URL=${NOTIFY_API_BASE_URL} \
OAUTH_API_KID=${OAUTH_API_KID} \
OAUTH_API_KEY=${OAUTH_API_KEY} \
OAUTH_TOKEN_URL=${OAUTH_TOKEN_URL} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_batch_notification_processor_updates_message_queue(recipient_data, help

with requests_mock.Mocker() as rm:
rm.post(
f"{os.getenv('COMMGT_BASE_URL')}/message/batch",
f"{os.getenv('NOTIFY_API_BASE_URL')}/comms/v1/message-batches",
status_code=201,
json={"data": {"id": "batch_id"}},
)
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_batch_notification_processor_payload(recipient_data, nhs_notify_message

with requests_mock.Mocker() as rm:
adapter = rm.post(
f"{os.getenv('COMMGT_BASE_URL')}/message/batch",
f"{os.getenv('NOTIFY_API_BASE_URL')}/comms/v1/message-batches",
status_code=201,
json={"data": {"id": "batch_id"}},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from recipient import Recipient


@patch("lambda_function.communication_management")
@patch("lambda_function.notify_api")
@patch("lambda_function.batch_processor")
def test_lambda_handler(mock_batch_processor, mock_communication_management):
def test_lambda_handler(mock_batch_processor, mock_notify_api):
recipients = [
Recipient(("1234567890", "message_reference_0", "new")),
Recipient(("0987654321", "message_reference_1", "new")),
Expand All @@ -22,13 +22,13 @@ def test_lambda_handler(mock_batch_processor, mock_communication_management):

mock_response = Mock()
mock_response.status_code = 201
mock_communication_management.send_batch_message = Mock(return_value=mock_response)
mock_notify_api.send_batch_message = Mock(return_value=mock_response)

lambda_function.lambda_handler({}, {})

assert mock_batch_processor.next_batch.call_count == 2

mock_communication_management.send_batch_message.assert_called_once_with(
mock_notify_api.send_batch_message.assert_called_once_with(
batch_id_1,
routing_plan_id_1,
recipients
Expand Down
Loading