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: 0 additions & 2 deletions .github/workflows/base-e2e-backendtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ jobs:
- name: Get E2e Test Variables
run: |
AWS_WORKSPACE="${SANDBOX}"
API_URL="api-${SANDBOX}.access-request-fulfilment.patient-deductions.nhs.uk"
echo "NDR_API_ENDPOINT=$API_URL" >> $GITHUB_ENV
echo "AWS_WORKSPACE=$AWS_WORKSPACE" >> $GITHUB_ENV
env:
SANDBOX: ${{ inputs.sandbox }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/full-deploy-to-pre-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,15 @@ jobs:
sandbox: pre-prod
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

run_backend_e2e_tests:
name: Run E2E Tests
needs: ["deploy_all_lambdas"]
uses: ./.github/workflows/ndr-e2e-test-sandbox.yml
with:
build_branch: ${{ needs.tag_and_release.outputs.version }}
environment: pre-prod
sandbox: pre-prod
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

12 changes: 12 additions & 0 deletions .github/workflows/lambdas-deploy-to-pre-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ jobs:
environment: pre-prod
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

run_backend_e2e_tests:
name: Run E2E Tests
needs: ["deploy_all"]
uses: ./.github/workflows/ndr-e2e-test-sandbox.yml
with:
build_branch: ${{ needs.tag_and_release.outputs.version }}
environment: pre-prod
sandbox: pre-prod
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

15 changes: 15 additions & 0 deletions .github/workflows/ndr-e2e-test-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ on:
type: string
default: development

workflow_call:
inputs:
build_branch:
required: true
type: string
sandbox:
required: true
type: string
environment:
required: true
type: string
secrets:
AWS_ASSUME_ROLE:
required: true

permissions:
pull-requests: write
id-token: write
Expand Down
4 changes: 2 additions & 2 deletions lambdas/tests/e2e/api/fhir/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

pdm_data_helper = PdmDataHelper()

PDM_SNOMED = 717391000000106
PDM_SNOMED = pdm_data_helper.snomed_code
PDM_METADATA_TABLE = pdm_data_helper.dynamo_table
PDM_S3_BUCKET = pdm_data_helper.s3_bucket
MTLS_ENDPOINT = os.environ.get("MTLS_ENDPOINT")
MTLS_ENDPOINT = pdm_data_helper.mtls_endpoint
CLIENT_CERT_PATH = os.environ.get("CLIENT_CERT_PATH")
CLIENT_KEY_PATH = os.environ.get("CLIENT_KEY_PATH")

Expand Down
5 changes: 3 additions & 2 deletions lambdas/tests/e2e/api/fhir/test_search_patient_fhir_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from lambdas.tests.e2e.api.fhir.conftest import (
MTLS_ENDPOINT,
PDM_SNOMED,
create_and_store_pdm_record,
create_mtls_session,
)
from lambdas.tests.e2e.conftest import APIM_ENDPOINT, PDM_SNOMED
from lambdas.tests.e2e.conftest import APIM_ENDPOINT
from lambdas.tests.e2e.helpers.data_helper import PdmDataHelper

pdm_data_helper = PdmDataHelper()
Expand All @@ -31,7 +32,7 @@ def search_document_reference(nhs_number, client_cert_path=None, client_key_path


def test_search_nonexistent_document_references_for_patient_details():
response = search_document_reference("9912003071")
response = search_document_reference("9449305943")
assert response.status_code == 200

bundle = response.json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from lambdas.tests.e2e.api.fhir.conftest import (
MTLS_ENDPOINT,
PDM_SNOMED,
create_mtls_session,
fetch_with_retry_mtls,
)
from lambdas.tests.e2e.conftest import APIM_ENDPOINT, PDM_SNOMED
from lambdas.tests.e2e.conftest import APIM_ENDPOINT
from lambdas.tests.e2e.helpers.data_helper import PdmDataHelper

pdm_data_helper = PdmDataHelper()
Expand Down
6 changes: 6 additions & 0 deletions lambdas/tests/e2e/api/test_login_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import pytest
from tests.e2e.helpers.data_helper import LloydGeorgeDataHelper
from tests.e2e.helpers.lloyd_george_mockcis2_helper import LloydGeorgeMockcis2Helper

# Note this is testing a mock, but this test is valuable to ensure the login code is working for other tests

data_helper = LloydGeorgeDataHelper()


@pytest.mark.skipif(
data_helper.workspace == "pre-prod", reason="CIS2 login is not mocked in pre-prod"
)
@pytest.mark.parametrize(
"ods_code, role_to_assume, expected_granted_role",
[
Expand Down
12 changes: 8 additions & 4 deletions lambdas/tests/e2e/api/test_upload_document_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def test_create_document_virus(test_data, snapshot_json):
lloyd_george_record["nhs_number"] = "9730154260"

# Attach EICAR data
eicar_string = r"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"
eicar_string = (
r"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"
)
lloyd_george_record["data"] = base64.b64encode(eicar_string.encode()).decode()

payload = create_upload_payload(lloyd_george_record)
Expand All @@ -185,14 +187,16 @@ def test_create_document_virus(test_data, snapshot_json):
def condition(response_json):
logging.info(response_json)
return response_json.get("docStatus") in (
"cancelled",
"final",
"cancelled",
"final",
)

raw_retrieve_response = fetch_with_retry(retrieve_url, condition)
retrieve_response = raw_retrieve_response.json()

assert upload_response == snapshot_json(exclude=paths("id", "date", "content.0.attachment.url"))
assert upload_response == snapshot_json(
exclude=paths("id", "date", "content.0.attachment.url")
)
assert retrieve_response == snapshot_json(exclude=paths("id", "date"))


Expand Down
8 changes: 2 additions & 6 deletions lambdas/tests/e2e/apim/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import os

import pytest

from lambdas.tests.e2e.helpers.data_helper import PdmDataHelper

pdm_data_helper = PdmDataHelper()

PDM_METADATA_TABLE = (
os.environ.get("PDM_METADATA_TABLE") or "ndr-dev_COREDocumentMetadata"
)
PDM_S3_BUCKET = os.environ.get("PDM_S3_BUCKET") or "ndr-dev-pdm-document-store"
PDM_METADATA_TABLE = pdm_data_helper.dynamo_table
PDM_S3_BUCKET = pdm_data_helper.s3_bucket


@pytest.fixture
Expand Down
3 changes: 1 addition & 2 deletions lambdas/tests/e2e/apim/test_apim_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import requests
from tests.e2e.helpers.data_helper import PdmDataHelper

from lambdas.tests.e2e.conftest import PDM_SNOMED

pdm_data_helper = PdmDataHelper()
PDM_SNOMED = pdm_data_helper.snomed_code


def test_ping(nhsd_apim_proxy_url):
Expand Down
8 changes: 2 additions & 6 deletions lambdas/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

data_helper = LloydGeorgeDataHelper()

LLOYD_GEORGE_SNOMED = 16521000000101
API_ENDPOINT = os.environ.get("NDR_API_ENDPOINT")
LLOYD_GEORGE_SNOMED = data_helper.snomed_code
API_ENDPOINT = data_helper.api_endpoint
API_KEY = os.environ.get("NDR_API_KEY")
LG_METADATA_TABLE = data_helper.dynamo_table
LG_UNSTITCHED_TABLE = os.environ.get("LG_UNSTITCHED_TABLE")
BULK_REPORT_TABLE = os.environ.get("BULK_REPORT_TABLE")
LLOYD_GEORGE_S3_BUCKET = data_helper.s3_bucket
APIM_ENDPOINT = data_helper.apim_url
PDM_SNOMED = 717391000000106
MTLS_ENDPOINT = os.environ.get("MTLS_ENDPOINT")
CLIENT_CERT_PATH = os.environ.get("CLIENT_CERT_PATH")
CLIENT_KEY_PATH = os.environ.get("CLIENT_KEY_PATH")


@pytest.fixture
Expand Down
23 changes: 20 additions & 3 deletions lambdas/tests/e2e/helpers/data_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(
self.dynamo_service = DynamoDBService()
self.s3_service = S3Service()
self.apim_url = None
self.api_endpoint = None
self.mtls_endpoint = None

self.build_env(table_name, bucket_name)

Expand All @@ -37,10 +39,25 @@ def build_env(self, table_name, bucket_name):
apim_map = {
"pre-prod": "int.api.service.nhs.uk",
"ndr-test": "internal-qa.api.service.nhs.uk",
"ndr-dev": "internal-dev.api.service.nhs.uk",
}
self.apim_url = apim_map.get(str(self.workspace), "internal-dev.api.service.nhs.uk")
"ndr-dev": "internal-dev.api.service.nhs.uk",
}
self.apim_url = apim_map.get(
str(self.workspace), "internal-dev.api.service.nhs.uk"
)

domain = (
"national-document-repository.nhs.uk"
if self.workspace == "pre-prod"
else "access-request-fulfilment.patient-deductions.nhs.uk"
)

self.api_endpoint = (
f"api.{self.workspace}.{domain}"
if self.workspace in {"pre-prod", "ndr-test"}
else f"api-{self.workspace}.{domain}"
)

self.mtls_endpoint = f"mtls.{self.workspace}.{domain}"

def build_record(
self, nhs_number="9912003071", data=None, doc_status=None, size=None
Expand Down
6 changes: 4 additions & 2 deletions lambdas/tests/e2e/helpers/lloyd_george_mockcis2_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
from urllib.parse import parse_qs, quote, urlparse

import requests
from tests.e2e.helpers.data_helper import LloydGeorgeDataHelper

data_helper = LloydGeorgeDataHelper()


class LloydGeorgeMockcis2Helper:
def __init__(self, ods, repository_role):
self.mock_key = os.environ.get("MOCK_CIS2_KEY") or ""
self.api_endpoint = os.environ.get("NDR_API_ENDPOINT")
self.api_endpoint = data_helper.api_endpoint
self.ods = ods
self.repository_role = repository_role

pass

def generate_mockcis2_token(self):
Expand Down
1 change: 0 additions & 1 deletion scripts/test/run-e2e-fhir-api-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fi
source ./scripts/test/set-e2e-env-vars.sh $WORKSPACE

echo "Running FHIR api E2E tests on workspace $AWS_WORKSPACE with:"
echo "MTLS_ENDPOINT=$MTLS_ENDPOINT"
echo "CLIENT_CERT_PATH=$CLIENT_CERT_PATH"
echo "CLIENT_KEY_PATH=$CLIENT_KEY_PATH"
echo "UNAUTHORISED_CLIENT_CERT_PATH=$UNAUTHORISED_CLIENT_CERT_PATH"
Expand Down
10 changes: 0 additions & 10 deletions scripts/test/set-e2e-env-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ if [[ "$#" -ne 1 ]]; then
fi

WORKSPACE="$1"

# Set domain
if [[ "$WORKSPACE" = "ndr-test" || "$WORKSPACE" = "pre-prod" ]]; then
DOMAIN="national-document-repository.nhs.uk"
else
DOMAIN="access-request-fulfilment.patient-deductions.nhs.uk"
fi

# Set environment variables
export AWS_WORKSPACE="${WORKSPACE}"
export MTLS_ENDPOINT="mtls.${WORKSPACE}.${DOMAIN}"

# Ensure Client certificates in place
if ! make download-api-certs WORKSPACE="${WORKSPACE}"; then
Expand Down
Loading