Skip to content

Commit

Permalink
Merge branch 'aea-4506-migrate-qc' of github.com:NHSDigital/electroni…
Browse files Browse the repository at this point in the history
…c-prescription-service-api-regression-tests into aea-4506-migrate-qc
  • Loading branch information
wildjames committed Nov 6, 2024
2 parents f56125a + 9048f6e commit c754f30
Show file tree
Hide file tree
Showing 27 changed files with 460 additions and 41 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ ENV PATH="$PATH:/home/vscode/.asdf/bin/"
RUN asdf plugin add python; \
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git; \
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git; \
asdf plugin add nodejs;\
asdf plugin add actionlint;
asdf plugin add nodejs; \
asdf plugin add actionlint; \
asdf plugin add allure

WORKDIR /workspaces/electronic-prescription-service-api-regression-tests
ADD .tool-versions /workspaces/electronic-prescription-service-api-regression-tests/.tool-versions
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"version": "latest",
"moby": "true",
"installDockerBuildx": "true"
}
},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"vscode": {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
- name: Comment on PR with link to JIRA ticket
if: contains(github.event.pull_request.head.ref, 'aea-') || contains(github.event.pull_request.head.ref, 'AEA-') || contains(github.event.pull_request.head.ref, 'apm-') || contains(github.event.pull_request.head.ref, 'APM-') || contains(github.event.pull_request.head.ref, 'apmspii-') || contains(github.event.pull_request.head.ref, 'APMSPII-') || contains(github.event.pull_request.head.ref, 'adz-') || contains(github.event.pull_request.head.ref, 'ADZ-') || contains(github.event.pull_request.head.ref, 'amb-') || contains(github.event.pull_request.head.ref, 'AMB-')
continue-on-error: true
uses: unsplash/comment-on-pr@master
uses: unsplash/comment-on-pr@b5610c6125a7197eaec80072ea35ef53e1fc6035
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: |
This branch is work on a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket:
This branch is work on a ticket in an NHS England JIRA Project. Here's a handy link to the ticket:
# [${{ env.TICKET_NAME }}](https://nhsd-jira.digital.nhs.uk/browse/${{ env.TICKET_NAME }})
9 changes: 4 additions & 5 deletions .github/workflows/regression_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on:
type: choice
options:
- EPS-FHIR
- EPS-FHIR-PRESCRIBING
- EPS-FHIR-DISPENSING
- PFP-APIGEE
- PFP-AWS
- PSU
Expand Down Expand Up @@ -128,13 +130,10 @@ jobs:
owner: "NHSDigital"
repositories: "electronic-prescription-service-api-regression-tests,eps-test-reports"

- name: Send Results
run: |
poetry run python scripts/send_test_results.py --token=${{ steps.generate-token.outputs.token }} --run_id ${{GITHUB.RUN_ID}}
- name: Report failure on test failure
if: steps.tests.outcome != 'success'
run: |
poetry run python scripts/send_test_results.py --token=${{ steps.generate-token.outputs.token }} --run_id ${{GITHUB.RUN_ID}}
echo The regression tests step failed, this likely means there are test failures.
echo The report will be generated shortly
echo A test report will be generated shortly and can be viewed at: https://nhsdigital.github.io/eps-test-reports
exit 1
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ poetry 1.8.3
shellcheck 0.10.0
nodejs 22.9.0
actionlint 1.7.1
allure 2.31.0
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ deep-clean-install:

pre-commit:
poetry run pre-commit run --all-files

download-allure-report: guard-GITHUB_RUN_ID
rm -rf allure-report
rm -rf allure-results
gh run download ${GITHUB_RUN_ID}
allure generate
allure open
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ allure_behave.formatter:AllureFormatter -o allure-results -f pretty features --n
Change the `env` variable accordingly to either `INT` or `INTERNAL-DEV`.
If you wish to test a different product i.e. `PFP-APIGEE` then you must change `product=` and `--tags` respectively.

### Method 5:
Run the tests by pushing changes to github in a pull request and running the regression tests job.
You can do this by the browser or by running this
```
BRANCH=fix_tests_take_2
gh workflow run regression_tests.yml \
--ref ${BRANCH} \
-f tags=@regression \
-f environment=INTERNAL-DEV \
-f pull_request_id=pr-2877 \
-f github_tag=${BRANCH}
```

### Getting the token to check the endpoint calls on Postman
On the root of the project is a file `get_token.py` <br>
This interactive Python script will assist you in generating a CIS2 authentication token that you can use elsewhere to make API calls (e.g. in Postman)
Expand All @@ -99,3 +112,14 @@ Pre commit hooks run checks on your code to ensure quality before being allowed

This process will stop after the first program detects an error or if Black modified any files.
You may need to run this multiple times to ensure everything is ok before committing.


### Generating the allure report from a github test run
To generate and view the results of a github test run, first authenticate to github by running this and following instructions
```
gh auth login
```
Then download the alluere results by noting the github run id in a browser and running this
```
GITHUB_RUN_ID=11523235428 make download-allure-report
```
32 changes: 28 additions & 4 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
from behave.model import Scenario
from dotenv import load_dotenv

from methods.api import eps_api_methods

load_dotenv(override=True)

INTERNAL_QA_BASE_URL = "https://internal-qa.api.service.nhs.uk/"
INTERNAL_DEV_BASE_URL = "https://internal-dev.api.service.nhs.uk/"
PFP_AWS_PR_URL = "https://pfp-{{aws_pull_request_id}}.dev.eps.national.nhs.uk/"
PFP_AWS_SANDBOX_PR_URL = (
"https://pfp-{{aws_pull_request_id}}-sandbox.dev.eps.national.nhs.uk/"
)
INT_BASE_URL = "https://int.api.service.nhs.uk/"
SANDBOX_DEV_BASE_URL = "https://internal-dev-sandbox.api.service.nhs.uk/"
SANDBOX_INT_BASE_URL = "https://sandbox.api.service.nhs.uk/"
REF_BASE_URL = "https://ref.api.service.nhs.uk/"

PFP_AWS_PR_URL = "https://pfp-{{aws_pull_request_id}}.dev.eps.national.nhs.uk/"
PFP_AWS_SANDBOX_PR_URL = (
"https://pfp-{{aws_pull_request_id}}-sandbox.dev.eps.national.nhs.uk/"
)


ENVS = {
"INTERNAL-DEV": INTERNAL_DEV_BASE_URL,
"INTERNAL-QA": INTERNAL_QA_BASE_URL,
Expand All @@ -36,6 +40,7 @@

REPOS = {
"EPS-FHIR": "https://github.com/NHSDigital/electronic-prescription-service-api",
# TODO Add EPS Dispensing and Prescribing repo URLs
"PFP-APIGEE": "https://github.com/NHSDigital/prescriptions-for-patients",
"PFP-AWS": "https://github.com/NHSDigital/prescriptionsforpatients",
"PSU": "https://github.com/NHSDigital/eps-prescription-status-update-api",
Expand All @@ -50,6 +55,8 @@
JWT_KID = os.getenv("JWT_KID")

EPS_FHIR_SUFFIX = "electronic-prescriptions"
EPS_FHIR_PRESCRIBING_SUFFIX = "fhir-prescribing"
EPS_FHIR_DISPENSING_SUFFIX = "fhir-dispensing"
PFP_SUFFIX = "prescriptions-for-patients"
PSU_SUFFIX = "prescription-status-update"

Expand All @@ -73,6 +80,12 @@ def before_all(context):
env = context.config.userdata["env"].upper()
product = context.config.userdata["product"].upper()
context.eps_fhir_base_url = os.path.join(select_base_url(env), EPS_FHIR_SUFFIX)
context.eps_fhir_prescribing_base_url = os.path.join(
select_base_url(env), EPS_FHIR_PRESCRIBING_SUFFIX
)
context.eps_fhir_dispensing_base_url = os.path.join(
select_base_url(env), EPS_FHIR_DISPENSING_SUFFIX
)
context.pfp_base_url = os.path.join(select_base_url(env), PFP_SUFFIX)
context.psu_base_url = os.path.join(select_base_url(env), PSU_SUFFIX)
if PULL_REQUEST_ID:
Expand All @@ -81,7 +94,10 @@ def before_all(context):
get_url_with_pr(context, env, product)
else:
raise RuntimeError("no tests to run. Check your tags and try again")
eps_api_methods.calculate_eps_fhir_base_url(context)
print("EPS: ", context.eps_fhir_base_url)
print("EPS-PRESCRIBING: ", context.eps_fhir_prescribing_base_url)
print("EPS-DISPENSING: ", context.eps_fhir_dispensing_base_url)
print("PFP: ", context.pfp_base_url)
print("PSU: ", context.psu_base_url)

Expand All @@ -92,6 +108,14 @@ def get_url_with_pr(context, env, product):
context.eps_fhir_base_url = os.path.join(
INTERNAL_DEV_BASE_URL, f"{EPS_FHIR_SUFFIX}-{PULL_REQUEST_ID}"
)
if product == "EPS-FHIR-PRESCRIBING":
context.eps_fhir_prescribing_base_url = os.path.join(
INTERNAL_DEV_BASE_URL, f"{EPS_FHIR_PRESCRIBING_SUFFIX}-{PULL_REQUEST_ID}"
)
if product == "EPS-FHIR-DISPENSING":
context.eps_fhir_dispensing_base_url = os.path.join(
INTERNAL_DEV_BASE_URL, f"{EPS_FHIR_DISPENSING_SUFFIX}-{PULL_REQUEST_ID}"
)
if product == "PFP-APIGEE":
context.pfp_base_url = os.path.join(
INTERNAL_DEV_BASE_URL, f"{PFP_SUFFIX}-{PULL_REQUEST_ID}"
Expand Down
24 changes: 24 additions & 0 deletions features/eps_fhir_dispensing/dispense_prescriptions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@eps_fhir_dispensing @regression @blocker @smoke
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4432
Feature: I can dispense prescriptions

@dispense
Scenario: I can dispense a prescription
Given a prescription has been created and released
When I dispense the prescription
Then the response indicates a success
And the response body indicates a successful dispense action

@amend
Scenario: I can amend a single dispense notification
Given a new prescription has been dispensed
When I amend the dispense notification
Then the response indicates a success
And the response body indicates a successful amend dispense action

@withdraw
Scenario: I can withdraw a dispense notification
Given a new prescription has been dispensed
When I withdraw the dispense notification
Then the response indicates a success
And the response body indicates a successful dispense withdrawal action
8 changes: 8 additions & 0 deletions features/eps_fhir_dispensing/ping.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@eps_fhir_dispensing @smoke @regression @ping @blocker
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4432
Feature: I can ping the API

Scenario: I can ping the API
When I make a request to the "eps_fhir_dispensing" ping endpoint
Then the response indicates a success
And I can see the ping information in the response
9 changes: 9 additions & 0 deletions features/eps_fhir_dispensing/return_prescriptions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@eps_fhir_dispensing @smoke @regression @blocker @return
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4432
Feature: I can return prescriptions

Scenario: I can return a prescription
Given a prescription has been created and released
When I return the prescription
Then the response indicates a success
And the response body indicates a successful return action
10 changes: 10 additions & 0 deletions features/eps_fhir_prescribing/cancel_prescriptions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@eps_fhir_prescribing @cancel @regression @blocker @smoke
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4432
Feature: I can cancel prescriptions

Scenario: I can cancel a prescription
Given I am an authorised prescriber
And I successfully prepare and sign a non-nominated prescription
When I cancel all line items on the prescription
Then the response indicates a success
And the response body indicates a successful cancel action
15 changes: 15 additions & 0 deletions features/eps_fhir_prescribing/create_prescriptions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@eps_fhir_prescribing @smoke @regression @blocker @create
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4432
Feature: I can create prescriptions

Scenario Outline: I can create, sign and release a prescription
Given I am an authorised prescriber
And I successfully prepare and sign a <Type> prescription
When I am an authorised dispenser
And I release the prescription
Then the response indicates a success
And the response body indicates a successful release action
Examples:
| Type |
| nominated |
| non-nominated |
8 changes: 8 additions & 0 deletions features/eps_fhir_prescribing/ping.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@eps_fhir_prescribing @smoke @regression @ping @blocker
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4432
Feature: I can ping the API

Scenario: I can ping the API
When I make a request to the "eps_fhir_prescribing" ping endpoint
Then the response indicates a success
And I can see the ping information in the response
4 changes: 4 additions & 0 deletions features/steps/common_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def i_make_a_request_to_the_ping_endpoint(context, product):
base_url = context.pfp_base_url
if product == "eps_fhir":
base_url = context.eps_fhir_base_url
if product == "eps_fhir_prescribing":
base_url = context.eps_fhir_prescribing_base_url
if product == "eps_fhir_dispensing":
base_url = context.eps_fhir_dispensing_base_url
if base_url is not None:
request_ping(context, base_url)
else:
Expand Down
6 changes: 5 additions & 1 deletion features/steps/eps_api_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

@given("I successfully prepare and sign a prescription")
def i_prepare_and_sign_a_prescription(context):
if "sandbox" in context.config.userdata["env"].lower() and context.config.userdata["product"].upper() != "EPS-FHIR":
if (
"sandbox" in context.config.userdata["env"].lower()
and context.config.userdata["product"].upper() != "EPS-FHIR"
):
return
i_prepare_a_new_prescription(context, "nominated")
i_sign_a_new_prescription(context=context)
Expand Down Expand Up @@ -116,6 +119,7 @@ def i_withdraw_the_dispense_notification(context):
def body_indicates_successful_action(context, action_type):
if "sandbox" in context.config.userdata["env"].lower():
return

def _withdraw_dispense_notification_assertion():
i_can_see_an_informational_operation_outcome_in_the_response(context)

Expand Down
Loading

0 comments on commit c754f30

Please sign in to comment.