Skip to content
Draft
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ lambdas/tests/unit/helpers/data/pdf/tmp

tests/bulk-upload/output/**
tests/bulk-upload/test_patients_data/**
tests/bulk-upload/scripts/scenario_report.txt
tests/bulk-upload/scripts/scenario_report.txt
1 change: 1 addition & 0 deletions lambdas/requirements/requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pytest==7.4.3
requests_mock==1.11.0
ruff==0.0.284
syrupy==4.9.1
locust==2.38.0
1 change: 1 addition & 0 deletions lambdas/services/mock_virus_scan_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"9730154341",
"9730154066",
"9730154708",
# Following used in e2e automation testing
"9730154260",
]

Expand Down
2 changes: 1 addition & 1 deletion lambdas/tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In addition the following AWS Environment Variables need to be set in order to u
| Environment Variable | Description |
| -------------------- | ------------------------------------------------------------- |
| `NDR_API_KEY` | The API key required to authenticate requests to the NDR API. |
| `NDR_API_ENDPOINT` | The URI string used to connect to the NDR API. |
| `NDR_API_ENDPOINT` | The URI string usedhto connect to the NDR API. |
| `NDR_S3_BUCKET` | The name of the Lloyd George Store. |
| `NDR_DYNAMO_STORE` | The name of the Lloyd George Reference Data Store. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
'creation': '2023-01-01',
'data': 'U2FtcGxlIFBERiBDb250ZW50',
'language': 'en-GB',
'size': 128670,
'size': 12345,
'title': '1of1_Lloyd_George_Record_[Holly Lorna MAGAN]_[9449305943]_[29-05-2006].pdf',
}),
}),
Expand Down
278 changes: 278 additions & 0 deletions lambdas/tests/e2e/api/__snapshots__/test_upload_document_api.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
# serializer version: 1
# name: test_create_document_base64
dict({
'author': list([
dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
]),
'content': list([
dict({
'attachment': dict({
'contentType': 'application/pdf',
'creation': '2023-01-01',
'language': 'en-GB',
'title': '1of1_Lloyd_George_Record_[Paula Esme VESEY]_[9730153973]_[22-01-1960].pdf',
}),
}),
]),
'custodian': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
'docStatus': 'preliminary',
'resourceType': 'DocumentReference',
'status': 'current',
'subject': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/nhs-number',
'value': '9449303304',
}),
}),
'type': dict({
'coding': list([
dict({
'code': '16521000000101',
'display': 'Lloyd George record folder',
'system': 'http://snomed.info/sct',
}),
]),
}),
})
# ---
# name: test_create_document_base64.1
dict({
'author': list([
dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
]),
'content': list([
dict({
'attachment': dict({
'contentType': 'application/pdf',
'creation': '2023-01-01',
'language': 'en-GB',
'size': 59315,
'title': '1of1_Lloyd_George_Record_[Paula Esme VESEY]_[9730153973]_[22-01-1960].pdf',
}),
}),
]),
'custodian': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
'docStatus': 'final',
'resourceType': 'DocumentReference',
'status': 'current',
'subject': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/nhs-number',
'value': '9449303304',
}),
}),
'type': dict({
'coding': list([
dict({
'code': '16521000000101',
'display': 'Lloyd George record folder',
'system': 'http://snomed.info/sct',
}),
]),
}),
})
# ---
# name: test_create_document_presign
dict({
'author': list([
dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
]),
'content': list([
dict({
'attachment': dict({
'contentType': 'application/pdf',
'creation': '2023-01-01',
'language': 'en-GB',
'title': '1of1_Lloyd_George_Record_[Paula Esme VESEY]_[9730153973]_[22-01-1960].pdf',
}),
}),
]),
'custodian': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
'docStatus': 'preliminary',
'resourceType': 'DocumentReference',
'status': 'current',
'subject': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/nhs-number',
'value': '9449303304',
}),
}),
'type': dict({
'coding': list([
dict({
'code': '16521000000101',
'display': 'Lloyd George record folder',
'system': 'http://snomed.info/sct',
}),
]),
}),
})
# ---
# name: test_create_document_presign.1
dict({
'author': list([
dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
]),
'content': list([
dict({
'attachment': dict({
'contentType': 'application/pdf',
'creation': '2023-01-01',
'language': 'en-GB',
'title': '1of1_Lloyd_George_Record_[Paula Esme VESEY]_[9730153973]_[22-01-1960].pdf',
}),
}),
]),
'custodian': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
'docStatus': 'final',
'resourceType': 'DocumentReference',
'status': 'current',
'subject': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/nhs-number',
'value': '9449303304',
}),
}),
'type': dict({
'coding': list([
dict({
'code': '16521000000101',
'display': 'Lloyd George record folder',
'system': 'http://snomed.info/sct',
}),
]),
}),
})
# ---
# name: test_create_document_virus
dict({
'author': list([
dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
]),
'content': list([
dict({
'attachment': dict({
'contentType': 'application/pdf',
'creation': '2023-01-01',
'language': 'en-GB',
'title': '1of1_Lloyd_George_Record_[Paula Esme VESEY]_[9730153973]_[22-01-1960].pdf',
}),
}),
]),
'custodian': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
'docStatus': 'preliminary',
'resourceType': 'DocumentReference',
'status': 'current',
'subject': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/nhs-number',
'value': '9730154260',
}),
}),
'type': dict({
'coding': list([
dict({
'code': '16521000000101',
'display': 'Lloyd George record folder',
'system': 'http://snomed.info/sct',
}),
]),
}),
})
# ---
# name: test_create_document_virus.1
dict({
'author': list([
dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
]),
'content': list([
dict({
'attachment': dict({
'contentType': 'application/pdf',
'creation': '2023-01-01',
'language': 'en-GB',
'title': '1of1_Lloyd_George_Record_[Paula Esme VESEY]_[9730153973]_[22-01-1960].pdf',
}),
}),
]),
'custodian': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/ods-organization-code',
'value': 'H81109',
}),
}),
'docStatus': 'cancelled',
'resourceType': 'DocumentReference',
'status': 'current',
'subject': dict({
'identifier': dict({
'system': 'https://fhir.nhs.uk/Id/nhs-number',
'value': '9730154260',
}),
}),
'type': dict({
'coding': list([
dict({
'code': '16521000000101',
'display': 'Lloyd George record folder',
'system': 'http://snomed.info/sct',
}),
]),
}),
})
# ---
Binary file added lambdas/tests/e2e/api/files/big-dummy.pdf
Binary file not shown.
Binary file added lambdas/tests/e2e/api/files/dummy.pdf
Binary file not shown.
31 changes: 15 additions & 16 deletions lambdas/tests/e2e/api/test_retrieve_document_api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import io
import os
import uuid

import requests
from tests.e2e.conftest import LLOYD_GEORGE_SNOMED
from tests.e2e.conftest import (
API_ENDPOINT,
API_KEY,
LLOYD_GEORGE_S3_BUCKET,
LLOYD_GEORGE_SNOMED,
)
from tests.e2e.helpers.lloyd_george_data_helper import LloydGeorgeDataHelper

data_helper = LloydGeorgeDataHelper()

api_endpoint = os.environ.get("NDR_API_ENDPOINT")
api_key = os.environ.get("NDR_API_KEY")


def test_small_file(test_data, snapshot):
lloyd_george_record = {}
Expand All @@ -23,8 +24,8 @@ def test_small_file(test_data, snapshot):
data_helper.create_metadata(lloyd_george_record)
data_helper.create_resource(lloyd_george_record)

url = f"https://{api_endpoint}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": api_key}
url = f"https://{API_ENDPOINT}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": API_KEY}
response = requests.request("GET", url, headers=headers)
json = response.json()

Expand All @@ -38,8 +39,6 @@ def test_large_file(test_data, snapshot):
lloyd_george_record = {}
test_data.append(lloyd_george_record)

s3_bucket_name = os.environ.get("NDR_S3_BUCKET") or ""

lloyd_george_record["id"] = str(uuid.uuid4())
lloyd_george_record["nhs_number"] = "9449305943"
lloyd_george_record["data"] = io.BytesIO(b"A" * (10 * 1024 * 1024))
Expand All @@ -48,12 +47,12 @@ def test_large_file(test_data, snapshot):
data_helper.create_metadata(lloyd_george_record)
data_helper.create_resource(lloyd_george_record)

url = f"https://{api_endpoint}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": api_key}
url = f"https://{API_ENDPOINT}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": API_KEY}
response = requests.request("GET", url, headers=headers)
json = response.json()

expected_presign_uri = f"https://{s3_bucket_name}.s3.eu-west-2.amazonaws.com/{lloyd_george_record['nhs_number']}/{lloyd_george_record['id']}"
expected_presign_uri = f"https://{LLOYD_GEORGE_S3_BUCKET}.s3.eu-west-2.amazonaws.com/{lloyd_george_record['nhs_number']}/{lloyd_george_record['id']}"
assert expected_presign_uri in json["content"][0]["attachment"]["url"]

del json["date"]
Expand All @@ -67,8 +66,8 @@ def test_no_file_found(snapshot):
lloyd_george_record = {}
lloyd_george_record["id"] = str(uuid.uuid4())

url = f"https://{api_endpoint}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": api_key}
url = f"https://{API_ENDPOINT}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": API_KEY}
response = requests.request("GET", url, headers=headers)
json = response.json()

Expand All @@ -87,8 +86,8 @@ def test_preliminary_file(test_data, snapshot):
data_helper.create_metadata(lloyd_george_record)
data_helper.create_resource(lloyd_george_record)

url = f"https://{api_endpoint}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": api_key}
url = f"https://{API_ENDPOINT}/FhirDocumentReference/{LLOYD_GEORGE_SNOMED}~{lloyd_george_record['id']}"
headers = {"Authorization": "Bearer 123", "X-Api-Key": API_KEY}
response = requests.request("GET", url, headers=headers)
json = response.json()

Expand Down
Loading