Skip to content

Commit 186b2ec

Browse files
add end to end testing and environment setup
1 parent cf8eec1 commit 186b2ec

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed

.github/workflows/stage-2-test.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,51 @@ jobs:
143143
DATABASE_USER: postgres
144144
DATABASE_HOST: localhost
145145

146+
notifications-end-to-end-test:
147+
needs: test
148+
if: needs.test.outputs.notifications-changed == 'true'
149+
name: 'Notifications End to End Tests'
150+
runs-on: ubuntu-latest
151+
timeout-minutes: 5
152+
153+
services:
154+
postgres:
155+
image: postgres:17.4-alpine3.21
156+
ports:
157+
- 5432:5432
158+
env:
159+
POSTGRES_PASSWORD: postgres
160+
options: >-
161+
--health-cmd pg_isready
162+
--health-interval 10s
163+
--health-timeout 5s
164+
--health-retries 5
165+
166+
steps:
167+
- name: 'Checkout code'
168+
uses: actions/checkout@v5
169+
170+
- name: Install poetry
171+
run: pipx install poetry
172+
173+
- name: Set up Python
174+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
175+
with:
176+
python-version: '${{inputs.python_version}}'
177+
cache: poetry
178+
cache-dependency-path: ./poetry.lock
179+
180+
- name: Install dependencies
181+
run: make dependencies
182+
183+
- name: 'Run notifications end to end test suite'
184+
run: make test-end-to-end
185+
env:
186+
DATABASE_NAME: postgres
187+
DATABASE_PASSWORD: postgres
188+
DATABASE_USER: postgres
189+
DATABASE_HOST: localhost
190+
146191
frontend-integration-test:
147192
needs: test
148193
if: needs.test.outputs.frontend-changed == 'true'

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ help: # Print help @Others
4444
test: test-unit test-ui test-lint # Run all tests @Testing
4545

4646
test-unit: # Run unit tests @Testing
47-
poetry run pytest -m 'not system' --ignore manage_breast_screening/notifications/tests/dependencies --ignore manage_breast_screening/notifications/tests/integration --cov --cov-report term-missing:skip-covered
47+
poetry run pytest -m 'not system' --ignore manage_breast_screening/notifications/tests/dependencies --ignore manage_breast_screening/notifications/tests/integration --ignore manage_breast_screening/notifications/tests/end_to_end --cov --cov-report term-missing:skip-covered
4848
npm test -- --coverage
4949

5050
test-lint: # Lint files @Testing
@@ -63,6 +63,9 @@ test-ui: # Run UI tests @Testing
6363
test-integration:
6464
cd manage_breast_screening/notifications && ./tests/integration/run.sh
6565

66+
test-end-to-end:
67+
cd manage_breast_screening/notifications && ./tests/end_to_end/run.sh
68+
6669
run: manage_breast_screening/config/.env # Start the development server @Development
6770
poetry run ./manage.py runserver
6871

manage_breast_screening/notifications/compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
profiles:
1313
- development
1414
- integration
15+
- end_to_end
1516

1617
mesh-sandbox:
1718
build:
@@ -34,6 +35,7 @@ services:
3435
profiles:
3536
- development
3637
- integration
38+
- end_to_end
3739
volumes:
3840
- ./store/mailboxes.jsonl:/app/mesh_sandbox/store/data/mailboxes.jsonl:ro
3941
- ./store/workflows.jsonl:/app/mesh_sandbox/store/data/workflows.jsonl:ro
@@ -46,6 +48,8 @@ services:
4648
profiles:
4749
- development
4850
- integration
51+
- end_to_end
52+
4953
ports:
5054
- '8888:8888'
5155
healthcheck:
@@ -64,3 +68,4 @@ services:
6468
condition: service_healthy
6569
profiles:
6670
- integration
71+
- end_to_end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docker compose --profile end-to-end run test-dependencies sleep 0.1
2+
poetry run pytest $(dirname "$(realpath $0)")
3+
test_exit_code=$?
4+
docker compose --profile end-to-end down --volumes --remove-orphans
5+
exit $test_exit_code
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import uuid
2+
from datetime import datetime
3+
from unittest.mock import patch
4+
5+
import pytest
6+
7+
from manage_breast_screening.notifications.management.commands.create_appointments import (
8+
Command as CreateAppointmentsCommand,
9+
)
10+
from manage_breast_screening.notifications.management.commands.send_message_batch import (
11+
Command as SendMessageBatchCommand,
12+
)
13+
from manage_breast_screening.notifications.management.commands.store_mesh_messages import (
14+
Command as StoreMeshMessagesCommand,
15+
)
16+
from manage_breast_screening.notifications.tests.integration.helpers import Helpers
17+
18+
19+
@patch("manage_breast_screening.notifications.services.api_client.jwt.encode")
20+
class TestEndToEnd:
21+
@pytest.fixture(autouse=True)
22+
def setup(self, monkeypatch):
23+
monkeypatch.setenv("MESH_BASE_URL", "http://localhost:8700")
24+
monkeypatch.setenv("MESH_CLIENT_PASSWORD", "password")
25+
monkeypatch.setenv("MESH_CLIENT_SHARED_KEY", "TestKey")
26+
monkeypatch.setenv("MESH_INBOX_NAME", "X26ABC1")
27+
28+
monkeypatch.setenv(
29+
"BLOB_STORAGE_CONNECTION_STRING", Helpers().azurite_connection_string()
30+
)
31+
monkeypatch.setenv("BLOB_CONTAINER_NAME", "nbss-appoinments-data")
32+
33+
monkeypatch.setenv(
34+
"NHS_NOTIFY_API_MESSAGE_BATCH_URL", "http://localhost:8888/message/batch"
35+
)
36+
monkeypatch.setenv("API_OAUTH_TOKEN_URL", "http://localhost:8888/token")
37+
monkeypatch.setenv("API_OAUTH_API_KEY", "a1b2c3d4")
38+
monkeypatch.setenv("API_OAUTH_API_KID", "test-1")
39+
40+
monkeypatch.setenv("PRIVATE_KEY", "test-key")
41+
42+
@pytest.mark.django_db
43+
def test_get_from_mesh_and_send_message_batch(self, mock_jwt_encode):
44+
helpers = Helpers()
45+
test_file_1 = helpers.get_test_file_path("ABC_20241202091221_APPT_106.dat")
46+
test_file_2 = helpers.get_test_file_path("ABC_20241202091321_APPT_107.dat")
47+
helpers.add_file_to_mesh_mailbox(test_file_1)
48+
helpers.add_file_to_mesh_mailbox(test_file_2)
49+
50+
store_mesh_messages = StoreMeshMessagesCommand()
51+
store_mesh_messages.handle()
52+
53+
today_dirname = datetime.today().strftime("%Y-%m-%d")
54+
CreateAppointmentsCommand().handle(**{"date_str": today_dirname})
55+
56+
routing_plan = str(uuid.uuid4())
57+
send_message_batch = SendMessageBatchCommand()
58+
send_message_batch.handle(**{"routing_plan_id": routing_plan})
59+
60+
# do we want to perform the failed message batch command here? or save that for another test?

0 commit comments

Comments
 (0)