Skip to content

Commit 2562437

Browse files
committed
CCM-12616: Added py-mock-mesh module
1 parent 6703a70 commit 2562437

14 files changed

Lines changed: 1572 additions & 2 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ node_modules
2222
dist
2323
.DS_Store
2424
.reports
25+
26+
# Don't track ephemeral local build files
27+
.turbo
28+
target/
29+
30+
# Ignore coverage files
31+
.coverage

.gitleaksignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ cd9c0efec38c5d63053dd865e5d4e207c0760d91:docs/guides/Perform_static_analysis.md:
44
cd9c0efec38c5d63053dd865e5d4e207c0760d91:docs/guides/Perform_static_analysis.md:sonar-api-token:37
55
96096685ab3d6876671e2bc9a6ff4d48fc56e521:src/helloworld/helloworld.sln:ipv4:4
66
4f4e8c15629b2cb09356a7fed4d72953590227ce:docs/Gemfile.lock:ipv4:4
7+
52386bca9b88c0c8c7dee52ab0ec69d04fb72c46:src/TESTING_PLAN.md:ipv4:145

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ gitleaks 8.24.0
33
jq 1.6
44
nodejs 22.11.0
55
pre-commit 3.6.0
6+
python 3.13.2
67
terraform 1.10.1
78
terraform-docs 0.19.0
89
trivy 0.61.0
910
vale 3.6.0
10-
11-
11+
poetry 1.8.3
1212
# ==============================================================================
1313
# The section below is reserved for Docker image versions.
1414

docs/Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ GEM
2828
erb (4.0.4)
2929
cgi (>= 0.3.3)
3030
eventmachine (1.2.7)
31+
ffi (1.17.2-arm64-darwin)
3132
ffi (1.17.2-x86_64-linux-gnu)
3233
forwardable-extended (2.6.0)
3334
gemoji (4.1.0)
35+
google-protobuf (4.32.1-arm64-darwin)
36+
bigdecimal
37+
rake (>= 13)
3438
google-protobuf (4.32.1-x86_64-linux-gnu)
3539
bigdecimal
3640
rake (>= 13)
@@ -103,6 +107,8 @@ GEM
103107
mercenary (0.4.0)
104108
minitest (5.24.1)
105109
mutex_m (0.2.0)
110+
nokogiri (1.18.9-arm64-darwin)
111+
racc (~> 1.4)
106112
nokogiri (1.18.9-x86_64-linux-gnu)
107113
racc (~> 1.4)
108114
parallel (1.27.0)
@@ -138,6 +144,8 @@ GEM
138144
prism (~> 1.4)
139145
ruby-progressbar (1.13.0)
140146
safe_yaml (1.0.5)
147+
sass-embedded (1.78.0-arm64-darwin)
148+
google-protobuf (~> 4.27)
141149
sass-embedded (1.78.0-x86_64-linux-gnu)
142150
google-protobuf (~> 4.27)
143151
terminal-table (3.0.2)
@@ -148,6 +156,7 @@ GEM
148156
webrick (1.9.1)
149157

150158
PLATFORMS
159+
arm64-darwin-25
151160
x86_64-linux
152161

153162
DEPENDENCIES

infrastructure/terraform/components/dl/module_lambda_mesh_poll.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,18 @@ data "aws_iam_policy_document" "mesh_poll_lambda" {
5454
module.kms.key_arn,
5555
]
5656
}
57+
58+
statement {
59+
sid = "LettersBucketPermissions"
60+
effect = "Allow"
61+
62+
actions = [
63+
"s3:ListBucket",
64+
"s3:GetObject",
65+
]
66+
67+
resources = [
68+
"${module.s3bucket_letters.arn}/mock-mesh/*",
69+
]
70+
}
5771
}

utils/py-mock-mesh/Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PACKAGE=py_mock_mesh
2+
VERSION=1.0.0
3+
4+
audit:
5+
poetry run python -m jake.app ddt -t POETRY -f poetry.lock
6+
7+
install:
8+
poetry install
9+
10+
test:
11+
poetry run pytest || echo
12+
13+
test-coverage:
14+
poetry run pytest --cov --cov-report xml:target/coverage/@comms/py-mock-mesh/cobertura-coverage.xml || echo
15+
16+
lint:
17+
poetry run pylint py_mock_mesh
18+
19+
format:
20+
poetry run autopep8 -ri .
21+
22+
clean:
23+
rm -rf target
24+
25+
.PHONY: audit install test test-coverage lint format clean

utils/py-mock-mesh/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# py-mock-mesh
2+
3+
## Overview
4+
5+
The py-mock-mesh library provides a mock implementation of the NHS Notify MESH API using AWS S3, allowing developers to simulate interactions with the MESH service for testing and development purposes.
6+
7+
This library does the following:
8+
9+
- Simulates the sending and receiving of messages via the MESH API.
10+
- Stores messages in AWS S3 buckets for retrieval and processing.
11+
- Provides endpoints to interact with the mock MESH service.
12+
- Supports testing of MESH API integrations without needing access to the live service.
13+
- Facilitates development by mimicking the behaviour of the actual MESH service.
14+
- Ensures compatibility with existing MESH API clients.
15+
- Allows configuration of message delivery delays and errors for testing purposes.
16+
- Includes logging and monitoring features for debugging and analysis.
17+
18+
## Sending and Receiving Messages
19+
20+
1. Upload the to the S3 bucket by running this command: `aws s3 cp --metadata <field>=<value>,<field2>=<value2> <input_file> <target_path>`. Note: the target path should be the `nhs-<account>-<region>-<environment>-dl-letters` bucket for your environment. For example: the target path would be `s3://nhs-123456789012-eu-west-2-pr42-dl-letters/mock-mesh/<target-mailbox>/in/<key>`. The key is what the file will be saved as in the AWS S3 bucket, this is a string.
21+
2. The MESH poll lambda can be invoked early by pressing 'Test' in the AWS console. Alternatively, the lambda polls the mailbox every 30 minutes.
22+
3. To check for any errors and troubleshoot or that the message has been sent successfully, check the logs in the lambdas in the following order: MESH poller lambda, then the MESH retriever lambda.

utils/py-mock-mesh/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"description": "python library to simulate mesh with an s3 backend",
3+
"name": "@comms/py-mock-mesh",
4+
"private": true,
5+
"scripts": {
6+
"audit": "make audit",
7+
"lint": "make lint",
8+
"lint:fmt": "make format",
9+
"python-install": "make install",
10+
"test:unit": "make test",
11+
"test:unit:coverage": "make test-coverage",
12+
"typecheck": "echo this package contains no typescript"
13+
},
14+
"version": "1.0.0"
15+
}

0 commit comments

Comments
 (0)