Skip to content

Commit a344cf3

Browse files
committed
NRL-476 add feature tests
1 parent 3fe0086 commit a344cf3

File tree

5 files changed

+144
-1
lines changed

5 files changed

+144
-1
lines changed

tests/features/producer/createDocumentReference-failure.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,45 @@ Feature: Producer - createDocumentReference - Failure Scenarios
219219
}
220220
"""
221221

222+
Scenario: Invalid status
223+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
224+
And the organisation 'X26' is authorised to access pointer types:
225+
| system | value |
226+
| http://snomed.info/sct | 1363501000000100 |
227+
| http://snomed.info/sct | 736253002 |
228+
When producer 'X26' creates a DocumentReference with values:
229+
| property | value |
230+
| subject | 9999999999 |
231+
| status | current |
232+
| type | 736253002 |
233+
| category | 734163000 |
234+
| custodian | X26 |
235+
| author | HAR1 |
236+
| url | https://example.org/my-doc.pdf |
237+
| status | invalid |
238+
Then the response status code is 400
239+
And the response is an OperationOutcome with 1 issue
240+
And the OperationOutcome contains the issue:
241+
"""
242+
{
243+
"severity": "error",
244+
"code": "invalid",
245+
"details": {
246+
"coding": [
247+
{
248+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
249+
"code": "MESSAGE_NOT_WELL_FORMED",
250+
"display": "Message not well formed"
251+
}
252+
]
253+
},
254+
"diagnostics": "Request body could not be parsed (status: String should match pattern '^current$')",
255+
"expression": [
256+
"status"
257+
]
258+
}
259+
"""
260+
222261
# Credentials - missing pointer type for create
223262
Scenario: Producer lacks the permission for the pointer type requested
224263
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API

tests/features/producer/updateDocumentReference-failure.feature

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,47 @@
44
# Invalid document reference - changing immutable fields
55
# Provider ID mismatch
66
# No existing document reference
7+
Feature: Producer - updateDocumentReference - Failure Scenarios
8+
9+
Scenario: Invalid status
10+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
11+
And the organisation 'X26' is authorised to access pointer types:
12+
| system | value |
13+
| http://snomed.info/sct | 1363501000000100 |
14+
| http://snomed.info/sct | 736253002 |
15+
And a DocumentReference resource exists with values:
16+
| property | value |
17+
| id | X26-1114567890-updateDocTest |
18+
| subject | 9999999999 |
19+
| status | current |
20+
| type | 736253002 |
21+
| category | 734163000 |
22+
| contentType | application/pdf |
23+
| url | https://example.org/my-doc.pdf |
24+
| custodian | X26 |
25+
| author | X26 |
26+
When producer 'X26' updates a DocumentReference 'X26-1114567890-updateDocTest' with values:
27+
| property | value |
28+
| status | invalid |
29+
Then the response status code is 400
30+
And the response is an OperationOutcome with 1 issue
31+
And the OperationOutcome contains the issue:
32+
"""
33+
{
34+
"severity": "error",
35+
"code": "invalid",
36+
"details": {
37+
"coding": [
38+
{
39+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
40+
"code": "MESSAGE_NOT_WELL_FORMED",
41+
"display": "Message not well formed"
42+
}
43+
]
44+
},
45+
"diagnostics": "Request body could not be parsed (status: String should match pattern '^current$')",
46+
"expression": [
47+
"status"
48+
]
49+
}
50+
"""

tests/features/producer/upsertDocumentReference-failure.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,42 @@ Feature: Producer - upsertDocumentReference - Failure Scenarios
3838
]
3939
}
4040
"""
41+
42+
Scenario: Invalid status
43+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
44+
And the organisation 'X26' is authorised to access pointer types:
45+
| system | value |
46+
| http://snomed.info/sct | 1363501000000100 |
47+
| http://snomed.info/sct | 736253002 |
48+
When producer 'X26' upserts a DocumentReference with values:
49+
| property | value |
50+
| subject | 9999999999 |
51+
| status | current |
52+
| type | 736253002 |
53+
| category | 734163000 |
54+
| custodian | X26 |
55+
| author | HAR1 |
56+
| url | https://example.org/my-doc.pdf |
57+
| status | invalid |
58+
Then the response status code is 400
59+
And the response is an OperationOutcome with 1 issue
60+
And the OperationOutcome contains the issue:
61+
"""
62+
{
63+
"severity": "error",
64+
"code": "invalid",
65+
"details": {
66+
"coding": [
67+
{
68+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
69+
"code": "MESSAGE_NOT_WELL_FORMED",
70+
"display": "Message not well formed"
71+
}
72+
]
73+
},
74+
"diagnostics": "Request body could not be parsed (status: String should match pattern '^current$')",
75+
"expression": [
76+
"status"
77+
]
78+
}
79+
"""

tests/features/steps/2_request.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ def create_put_document_reference_step(context: Context, ods_code: str):
131131
context.add_cleanup(lambda: context.repository.delete_by_id(doc_ref_id))
132132

133133

134+
@when("producer '{ods_code}' updates a DocumentReference '{doc_ref_id}' with values")
135+
def update_put_document_reference_step(
136+
context: Context, ods_code: str, doc_ref_id: str
137+
):
138+
client = producer_client_from_context(context, ods_code)
139+
140+
if not context.table:
141+
raise ValueError("No document reference data table provided")
142+
143+
items = {row["property"]: row["value"] for row in context.table}
144+
145+
doc_ref = client.read(doc_ref_id).json()
146+
for key, value in items.items():
147+
doc_ref.update({key: value})
148+
149+
context.response = client.update(doc_ref, doc_ref_id)
150+
151+
if context.response.status_code == 201:
152+
context.add_cleanup(lambda: context.repository.delete_by_id(doc_ref_id))
153+
154+
134155
@when(
135156
"producer '{ods_code}' requests to delete DocumentReference with id '{doc_ref_id}'"
136157
)

tests/features/utils/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def create_test_document_reference(items: dict) -> DocumentReference:
27-
base_doc_ref = DocumentReference(
27+
base_doc_ref = DocumentReference.model_construct(
2828
resourceType="DocumentReference",
2929
status=items.get("status", "current"),
3030
content=[

0 commit comments

Comments
 (0)