Skip to content

Commit d01e097

Browse files
authored
Merge branch 'develop' into feature/eema1-NRL-936-custodianTypeMatchIntegrationTests
2 parents 964ec3a + 1eda970 commit d01e097

File tree

58 files changed

+2013
-649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2013
-649
lines changed

.github/workflows/persistent-environment.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ jobs:
233233
run: terraform -chdir=terraform/infrastructure apply tfplan
234234

235235
- name: Smoke Test
236-
run: make ENV=${{ inputs.environment }} test-smoke-internal
236+
run: |
237+
account=$(echo '${{ inputs.environment }}' | cut -d '-' -f1)
238+
make ENV=${account} truststore-pull-client
239+
make ENV=${{ inputs.environment }} test-smoke-internal
237240
238241
activate-stack:
239242
name: Activate - ${{ inputs.environment }}
@@ -318,12 +321,12 @@ jobs:
318321
319322
- name: "Smoke Test"
320323
run: |
321-
make ENV=${{ inputs.environment }} test-smoke-external
324+
make ENV=${{ inputs.environment }} test-smoke-public
322325
323326
rollback-stack:
324327
name: Rollback - ${{ inputs.environment }}
325328
needs: [post-release-verify]
326-
if: ${{ needs.post-release-verify.result == 'failure' }}
329+
if: always() && ( needs.post-release-verify.result == 'failure' )
327330
runs-on: [self-hosted, ci]
328331
environment: ${{ inputs.environment }}
329332

.github/workflows/rollback-stack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
6565
- name: "Smoke Test"
6666
run: |
67-
make ENV=${{ inputs.environment }} test-smoke-external
67+
make ENV=${{ inputs.environment }} test-smoke-public

Makefile

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
.EXPORT_ALL_VARIABLES:
33
.NOTPARALLEL:
4-
.ONESHELL:
54
.PHONY: *
65

76
MAKEFLAGS := --no-print-directory
87
SHELL := /bin/bash
98

109
DIST_PATH ?= ./dist
1110
TEST_ARGS ?= --cov --cov-report=term-missing
11+
SMOKE_TEST_ARGS ?=
1212
FEATURE_TEST_ARGS ?= ./tests/features --format progress2
1313
TF_WORKSPACE_NAME ?= $(shell terraform -chdir=terraform/infrastructure workspace show)
1414
ENV ?= dev
@@ -76,25 +76,45 @@ build-api-packages: ./api/consumer/* ./api/producer/*
7676

7777
test: check-warn ## Run the unit tests
7878
@echo "Running unit tests"
79-
pytest -m "not integration and not legacy and not smoke" --ignore=mi $(TEST_ARGS)
79+
pytest --ignore=tests/smoke $(TEST_ARGS)
8080

8181
test-features-integration: check-warn ## Run the BDD feature tests in the integration environment
82+
@echo "Running feature tests in the integration environment ${TF_WORKSPACE_NAME}"
83+
behave --define="integration_test=true" \
84+
--define="env=$(TF_WORKSPACE_NAME)" \
85+
--define="account_name=$(ENV)" \
86+
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
87+
$(FEATURE_TEST_ARGS)
88+
89+
test-features-integration-report: check-warn ## Run the BDD feature tests in the integration environment and generate allure report therafter
90+
@echo "Cleaning previous Allure results and reports"
91+
rm -rf ./allure-results
92+
rm -rf ./allure-report
8293
@echo "Running feature tests in the integration environment"
8394
behave --define="integration_test=true" \
8495
--define="env=$(TF_WORKSPACE_NAME)" \
8596
--define="account_name=$(ENV)" \
8697
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
8798
$(FEATURE_TEST_ARGS)
99+
@echo "Generating Allure report"
100+
allure generate ./allure-results -o ./allure-report --clean
101+
@echo "Opening Allure report"
102+
allure open ./allure-report
88103

89104
test-smoke-internal: check-warn ## Run the smoke tests against the internal environment
90-
@echo "Running smoke tests against the internal environment"
91-
#ENV=$(TF_WORKSPACE_NAME) SMOKE_TEST_MODE=mtls pytest ./tests/smoke $(SMOKE_TEST_ARGS)
92-
@echo "Skipping internal smoke tests (not yet implemented)"
93-
94-
test-smoke-external: check-warn ## Run the smoke tests for the external access points
95-
@echo "Running smoke tests for the external access points"
96-
#ENV=$(ENV) SMOKE_TEST_MODE=apigee pytest ./tests/smoke $(SMOKE_TEST_ARGS)
97-
@echo "Skipping external smoke tests (not yet implemented)"
105+
@echo "Running smoke tests against the internal environment ${TF_WORKSPACE_NAME}"
106+
TEST_ENVIRONMENT_NAME=$(ENV) \
107+
TEST_STACK_NAME=$(TF_WORKSPACE_NAME) \
108+
TEST_STACK_DOMAIN=$(shell terraform -chdir=terraform/infrastructure output -raw domain 2>/dev/null) \
109+
TEST_CONNECT_MODE="internal" \
110+
pytest ./tests/smoke/scenarios/* $(SMOKE_TEST_ARGS)
111+
112+
test-smoke-public: check-warn ## Run the smoke tests for the external access points
113+
@echo "Running smoke tests for the public endpoints ${ENV}"
114+
TEST_ENVIRONMENT_NAME=$(ENV) \
115+
TEST_STACK_NAME=$(TF_WORKSPACE_NAME) \
116+
TEST_CONNECT_MODE="public" \
117+
pytest ./tests/smoke/scenarios/* $(SMOKE_TEST_ARGS)
98118

99119
test-performance-prepare:
100120
mkdir -p $(DIST_PATH)
@@ -138,6 +158,10 @@ get-s3-perms: check-warn ## Get s3 permissions for an environment
138158
@echo "Creating new Lambda NRLF permissions layer zip"
139159
./scripts/add-perms-to-lambda.sh $(DIST_PATH)
140160

161+
set-smoketest-perms: check-warn ## Set the permissions for the smoke tests
162+
@echo "Setting permissions for smoke tests of env=$(ENV) stack=$(TF_WORKSPACE_NAME)...."
163+
poetry run python scripts/set_smoketest_permissions.py $(ENV) $(TF_WORKSPACE_NAME) $(ENV)
164+
141165
truststore-build-all: check-warn ## Build all truststore resources
142166
@./scripts/truststore.sh build-all
143167

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,28 @@ To run the feature integration tests:
283283
$ make test-features-integration
284284
```
285285

286+
### Smoke testing
287+
288+
For smoke tests, you need to have deployed your infrastructure (using Terraform).
289+
290+
Before the first run of the smoke tests, you need to set the required permissions in your deployment. You can do this by running:
291+
292+
```
293+
$ make set-smoketest-perms
294+
```
295+
296+
To run the internal smoke tests against your stack, do this:
297+
298+
```
299+
$ make test-smoke-internal
300+
```
301+
302+
To run the smoke tests against the public access endpoints (via APIGEE proxies), do this:
303+
304+
```
305+
$ make test-smoke-public
306+
```
307+
286308
## API Documentation
287309

288310
If the API changes, the API documentation needs to be updated in the appropriate API repo. This is done by making changes to the API specification `.yaml` files in each repo.

api/consumer/countDocumentReference/tests/test_count_document_reference.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
create_headers,
1111
create_mock_context,
1212
create_test_api_gateway_event,
13+
default_response_headers,
1314
)
1415

1516

@@ -26,7 +27,11 @@ def test_count_document_reference_happy_path(repository: DocumentPointerReposito
2627
result = handler(event, create_mock_context()) # type: ignore
2728
body = result.pop("body")
2829

29-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
30+
assert result == {
31+
"statusCode": "200",
32+
"headers": default_response_headers(),
33+
"isBase64Encoded": False,
34+
}
3035

3136
parsed_body = json.loads(body)
3237
assert parsed_body == {"resourceType": "Bundle", "type": "searchset", "total": 0}
@@ -38,7 +43,11 @@ def test_count_document_reference_happy_path(repository: DocumentPointerReposito
3843
result = handler(event, create_mock_context()) # type: ignore
3944
body = result.pop("body")
4045

41-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
46+
assert result == {
47+
"statusCode": "200",
48+
"headers": default_response_headers(),
49+
"isBase64Encoded": False,
50+
}
4251

4352
parsed_body = json.loads(body)
4453
assert parsed_body == {"resourceType": "Bundle", "type": "searchset", "total": 1}
@@ -50,7 +59,11 @@ def test_count_document_reference_missing_nhs_number():
5059
result = handler(event, create_mock_context()) # type: ignore
5160
body = result.pop("body")
5261

53-
assert result == {"statusCode": "400", "headers": {}, "isBase64Encoded": False}
62+
assert result == {
63+
"statusCode": "400",
64+
"headers": default_response_headers(),
65+
"isBase64Encoded": False,
66+
}
5467

5568
parsed_body = json.loads(body)
5669
assert parsed_body == {
@@ -86,7 +99,11 @@ def test_count_document_reference_invalid_nhs_number():
8699
result = handler(event, create_mock_context()) # type: ignore
87100
body = result.pop("body")
88101

89-
assert result == {"statusCode": "400", "headers": {}, "isBase64Encoded": False}
102+
assert result == {
103+
"statusCode": "400",
104+
"headers": default_response_headers(),
105+
"isBase64Encoded": False,
106+
}
90107

91108
parsed_body = json.loads(body)
92109
assert parsed_body == {

api/consumer/readDocumentReference/tests/test_read_document_reference_consumer.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
create_headers,
1111
create_mock_context,
1212
create_test_api_gateway_event,
13+
default_response_headers,
1314
)
1415

1516

@@ -28,7 +29,11 @@ def test_read_document_reference_happy_path(repository: DocumentPointerRepositor
2829
result = handler(event, create_mock_context())
2930
body = result.pop("body")
3031

31-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
32+
assert result == {
33+
"statusCode": "200",
34+
"headers": default_response_headers(),
35+
"isBase64Encoded": False,
36+
}
3237

3338
parsed_body = json.loads(body)
3439
assert parsed_body == doc_ref.dict(exclude_none=True)
@@ -44,7 +49,11 @@ def test_read_document_reference_not_found(repository: DocumentPointerRepository
4449
result = handler(event, create_mock_context())
4550
body = result.pop("body")
4651

47-
assert result == {"statusCode": "404", "headers": {}, "isBase64Encoded": False}
52+
assert result == {
53+
"statusCode": "404",
54+
"headers": default_response_headers(),
55+
"isBase64Encoded": False,
56+
}
4857

4958
parsed_body = json.loads(body)
5059
assert parsed_body == {
@@ -74,7 +83,11 @@ def test_read_document_reference_missing_id():
7483
result = handler(event, create_mock_context())
7584
body = result.pop("body")
7685

77-
assert result == {"statusCode": "400", "headers": {}, "isBase64Encoded": False}
86+
assert result == {
87+
"statusCode": "400",
88+
"headers": default_response_headers(),
89+
"isBase64Encoded": False,
90+
}
7891

7992
parsed_body = json.loads(body)
8093
assert parsed_body == {
@@ -118,7 +131,7 @@ def test_read_document_reference_unauthorised_for_type(
118131

119132
assert result == {
120133
"statusCode": "403",
121-
"headers": {},
134+
"headers": default_response_headers(),
122135
"isBase64Encoded": False,
123136
}
124137

@@ -163,7 +176,7 @@ def test_document_reference_invalid_json(repository: DocumentPointerRepository):
163176

164177
assert result == {
165178
"statusCode": "500",
166-
"headers": {},
179+
"headers": default_response_headers(),
167180
"isBase64Encoded": False,
168181
}
169182

api/consumer/searchDocumentReference/tests/test_search_document_reference_consumer.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
create_headers,
1111
create_mock_context,
1212
create_test_api_gateway_event,
13+
default_response_headers,
1314
)
1415

1516

@@ -30,7 +31,11 @@ def test_search_document_reference_happy_path(repository: DocumentPointerReposit
3031
result = handler(event, create_mock_context())
3132
body = result.pop("body")
3233

33-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
34+
assert result == {
35+
"statusCode": "200",
36+
"headers": default_response_headers(),
37+
"isBase64Encoded": False,
38+
}
3439

3540
parsed_body = json.loads(body)
3641

@@ -68,7 +73,11 @@ def test_search_document_reference_happy_path_with_custodian(
6873
result = handler(event, create_mock_context())
6974
body = result.pop("body")
7075

71-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
76+
assert result == {
77+
"statusCode": "200",
78+
"headers": default_response_headers(),
79+
"isBase64Encoded": False,
80+
}
7281

7382
parsed_body = json.loads(body)
7483
assert parsed_body == {
@@ -105,7 +114,11 @@ def test_search_document_reference_happy_path_with_type(
105114
result = handler(event, create_mock_context())
106115
body = result.pop("body")
107116

108-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
117+
assert result == {
118+
"statusCode": "200",
119+
"headers": default_response_headers(),
120+
"isBase64Encoded": False,
121+
}
109122

110123
parsed_body = json.loads(body)
111124
assert parsed_body == {
@@ -135,7 +148,11 @@ def test_search_document_reference_no_results(repository: DocumentPointerReposit
135148
result = handler(event, create_mock_context())
136149
body = result.pop("body")
137150

138-
assert result == {"statusCode": "200", "headers": {}, "isBase64Encoded": False}
151+
assert result == {
152+
"statusCode": "200",
153+
"headers": default_response_headers(),
154+
"isBase64Encoded": False,
155+
}
139156

140157
parsed_body = json.loads(body)
141158
assert parsed_body == {
@@ -162,7 +179,11 @@ def test_search_document_reference_missing_nhs_number(
162179
result = handler(event, create_mock_context())
163180
body = result.pop("body")
164181

165-
assert result == {"statusCode": "400", "headers": {}, "isBase64Encoded": False}
182+
assert result == {
183+
"statusCode": "400",
184+
"headers": default_response_headers(),
185+
"isBase64Encoded": False,
186+
}
166187

167188
parsed_body = json.loads(body)
168189
assert parsed_body == {
@@ -202,7 +223,11 @@ def test_search_document_reference_invalid_nhs_number(
202223
result = handler(event, create_mock_context())
203224
body = result.pop("body")
204225

205-
assert result == {"statusCode": "400", "headers": {}, "isBase64Encoded": False}
226+
assert result == {
227+
"statusCode": "400",
228+
"headers": default_response_headers(),
229+
"isBase64Encoded": False,
230+
}
206231

207232
parsed_body = json.loads(body)
208233
assert parsed_body == {
@@ -241,7 +266,11 @@ def test_search_document_reference_invalid_type(repository: DocumentPointerRepos
241266
result = handler(event, create_mock_context())
242267
body = result.pop("body")
243268

244-
assert result == {"statusCode": "400", "headers": {}, "isBase64Encoded": False}
269+
assert result == {
270+
"statusCode": "400",
271+
"headers": default_response_headers(),
272+
"isBase64Encoded": False,
273+
}
245274

246275
parsed_body = json.loads(body)
247276
assert parsed_body == {
@@ -285,7 +314,11 @@ def test_search_document_reference_invalid_json(repository: DocumentPointerRepos
285314
result = handler(event, create_mock_context())
286315
body = result.pop("body")
287316

288-
assert result == {"statusCode": "500", "headers": {}, "isBase64Encoded": False}
317+
assert result == {
318+
"statusCode": "500",
319+
"headers": default_response_headers(),
320+
"isBase64Encoded": False,
321+
}
289322

290323
parsed_body = json.loads(body)
291324
assert parsed_body == {

0 commit comments

Comments
 (0)