Skip to content

Commit abaf729

Browse files
committed
[feature/PI-536-create_product_without_fhir] create product without fhir
1 parent 81f0e0e commit abaf729

File tree

13 files changed

+89
-149
lines changed

13 files changed

+89
-149
lines changed

src/api/createCpmProduct/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from api_utils.api_step_chain import execute_step_chain_with_location
1+
from api_utils.api_step_chain import execute_step_chain
22
from event.aws.client import dynamodb_client
33
from event.environment import BaseEnvironment
44
from event.logging.logger import setup_logger
@@ -19,7 +19,7 @@ class Environment(BaseEnvironment):
1919

2020
def handler(event: dict, context=None):
2121
setup_logger(service_name=__file__)
22-
return execute_step_chain_with_location(
22+
return execute_step_chain(
2323
event=event,
2424
cache=cache,
2525
versioned_steps=versioned_steps,

src/api/createCpmProduct/tests/test_index.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from domain.core.root.v3 import Root
77
from domain.repository.product_team_repository.v2 import ProductTeamRepository
8-
from nhs_context_logging import app_logger
8+
from event.json import json_loads
99

1010
from test_helpers.dynamodb import mock_table
1111
from test_helpers.response_assertions import _response_assertions
@@ -57,31 +57,18 @@ def _mock_test(version, params):
5757
def test_index(version):
5858
result = _mock_test(version=version, params=json.dumps(product_payload))
5959

60+
product = json_loads(result["body"])
6061
expected_body = json.dumps(
6162
{
62-
"resourceType": "OperationOutcome",
63-
"id": app_logger.service_name,
64-
"meta": {
65-
"profile": [
66-
"https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome"
67-
]
68-
},
69-
"issue": [
70-
{
71-
"severity": "information",
72-
"code": "informational",
73-
"details": {
74-
"coding": [
75-
{
76-
"system": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome",
77-
"code": "RESOURCE_CREATED",
78-
"display": "Resource created",
79-
}
80-
]
81-
},
82-
"diagnostics": "Resource created",
83-
}
84-
],
63+
"id": product["id"],
64+
"product_team_id": product["product_team_id"],
65+
"name": "Foobar product",
66+
"ods_code": "F5H1R",
67+
"status": "active",
68+
"created_on": product["created_on"],
69+
"updated_on": None,
70+
"deleted_on": None,
71+
"keys": [],
8572
}
8673
)
8774
expected = {

src/api/createCpmProductForEpr/index.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from api_utils.api_step_chain import execute_step_chain_with_location
1+
from api_utils.api_step_chain import execute_step_chain
22
from event.aws.client import dynamodb_client
33
from event.environment import BaseEnvironment
44
from event.logging.logger import setup_logger
@@ -19,6 +19,4 @@ class Environment(BaseEnvironment):
1919

2020
def handler(event: dict, context=None):
2121
setup_logger(service_name=__file__)
22-
return execute_step_chain_with_location(
23-
event=event, cache=cache, versioned_steps=versioned_steps
24-
)
22+
return execute_step_chain(event=event, cache=cache, versioned_steps=versioned_steps)

src/api/createCpmProductForEpr/tests/test_index.py

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import os
33
from contextlib import contextmanager
4-
from datetime import datetime
54
from unittest import mock
65

76
import pytest
@@ -11,7 +10,6 @@
1110
from domain.repository.cpm_product_repository.v3 import CpmProductRepository
1211
from domain.repository.product_team_repository.v2 import ProductTeamRepository
1312
from event.json import json_loads
14-
from nhs_context_logging import app_logger
1513

1614
from test_helpers.dynamodb import mock_table
1715
from test_helpers.sample_data import CPM_PRODUCT_TEAM_NO_ID
@@ -23,30 +21,6 @@
2321
PRODUCT_NAME = "My Product"
2422
PRODUCT_TEAM_KEYS = CPM_PRODUCT_TEAM_NO_ID["keys"]
2523
VERSION = 1
26-
RESOURCE_CREATED = {
27-
"resourceType": "OperationOutcome",
28-
"meta": {
29-
"profile": [
30-
"https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome"
31-
]
32-
},
33-
"issue": [
34-
{
35-
"severity": "information",
36-
"code": "informational",
37-
"details": {
38-
"coding": [
39-
{
40-
"system": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome",
41-
"code": "RESOURCE_CREATED",
42-
"display": "Resource created",
43-
}
44-
]
45-
},
46-
"diagnostics": "Resource created",
47-
}
48-
],
49-
}
5024

5125

5226
@contextmanager
@@ -85,22 +59,23 @@ def test_index():
8559
)
8660
# Validate that the response indicates that a resource was created
8761
assert response["statusCode"] == 201
88-
assert json_loads(response["body"]) == {
89-
"id": app_logger.service_name,
90-
**RESOURCE_CREATED,
91-
}
62+
created_product = json_loads(response["body"])
9263

9364
# Retrieve the created resource
9465
repo = CpmProductRepository(
9566
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
9667
)
97-
created_product = repo.read(
98-
product_team_id=product_team.id, product_id=response["headers"]["Location"]
99-
).dict()
68+
read_product = repo.read(
69+
product_team_id=product_team.id, product_id=created_product["id"]
70+
).state()
71+
72+
assert created_product == read_product
73+
74+
# Don't check dates
75+
created_product.pop("created_on")
76+
created_product.pop("updated_on")
10077

10178
# Sense checks on the created resource
102-
assert isinstance(created_product.pop("created_on"), datetime)
103-
assert isinstance(created_product.pop("updated_on"), datetime)
10479
assert ProductId.validate_cpm_system_id(created_product.pop("id"))
10580
assert PartyKeyId.validate_cpm_system_id(
10681
created_product.pop("keys")[0]["key_value"]

src/api/tests/feature_tests/features/createCpmProduct.success.feature

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@ Feature: Create CPM Product - success scenarios
1919
| path | value |
2020
| product_name | My Great Product |
2121
Then I receive a status code "201" with body
22-
| path | value |
23-
| resourceType | OperationOutcome |
24-
| id | << ignore >> |
25-
| meta.profile.0 | https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome |
26-
| issue.0.severity | information |
27-
| issue.0.code | informational |
28-
| issue.0.details.coding.0.system | https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome |
29-
| issue.0.details.coding.0.code | RESOURCE_CREATED |
30-
| issue.0.details.coding.0.display | Resource created |
31-
| issue.0.diagnostics | Resource created |
22+
| path | value |
23+
| id | << ignore >> |
24+
| name | My Great Product |
25+
| product_team_id | ${ note(product_team_id) } |
26+
| ods_code | F5H1R |
27+
| status | active |
28+
| keys | [] |
29+
| created_on | << ignore >> |
30+
| updated_on | << ignore >> |
31+
| deleted_on | << ignore >> |
3232
And the response headers contain:
3333
| name | value |
3434
| Content-Type | application/json |
35-
| Content-Length | 460 |
36-
When I make a "GET" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/${ note(product_team_id) }/Product/<id>"
35+
| Content-Length | 255 |
36+
And I note the response field "$.id" as "product_id"
37+
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }"
3738
Then I receive a status code "200" with body
3839
| path | value |
39-
| id | << ignore >> |
40+
| id | ${ note(product_id) } |
4041
| name | My Great Product |
4142
| product_team_id | ${ note(product_team_id) } |
4243
| ods_code | F5H1R |

src/api/tests/feature_tests/features/createCpmProductForEpr.success.feature

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@ Feature: Create CPM Product for EPR - success scenarios
1919
| path | value |
2020
| product_name | My Great Product |
2121
Then I receive a status code "201" with body
22-
| path | value |
23-
| resourceType | OperationOutcome |
24-
| id | << ignore >> |
25-
| meta.profile.0 | https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome |
26-
| issue.0.severity | information |
27-
| issue.0.code | informational |
28-
| issue.0.details.coding.0.system | https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome |
29-
| issue.0.details.coding.0.code | RESOURCE_CREATED |
30-
| issue.0.details.coding.0.display | Resource created |
31-
| issue.0.diagnostics | Resource created |
22+
| path | value |
23+
| id | << ignore >> |
24+
| name | My Great Product |
25+
| product_team_id | ${ note(product_team_id) } |
26+
| ods_code | F5H1R |
27+
| status | active |
28+
| keys.0.key_value | F5H1R-850000 |
29+
| keys.0.key_type | party_key |
30+
| created_on | << ignore >> |
31+
| updated_on | << ignore >> |
32+
| deleted_on | << ignore >> |
3233
And the response headers contain:
3334
| name | value |
3435
| Content-Type | application/json |
35-
| Content-Length | 466 |
36-
When I make a "GET" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/${ note(product_team_id) }/Product/<id>"
36+
| Content-Length | 339 |
37+
And I note the response field "$.id" as "product_id"
38+
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }"
3739
Then I receive a status code "200" with body
3840
| path | value |
39-
| id | << ignore >> |
41+
| id | ${ note(product_id) } |
4042
| name | My Great Product |
4143
| product_team_id | ${ note(product_team_id) } |
4244
| ods_code | F5H1R |
@@ -62,28 +64,28 @@ Feature: Create CPM Product for EPR - success scenarios
6264
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
6365
| path | value |
6466
| product_name | My Great Product |
67+
And I note the response field "$.id" as "product_id_1"
6568
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
6669
| path | value |
6770
| product_name | My Other Great Product |
68-
Then I receive a status code "201" with body
69-
| path | value |
70-
| resourceType | OperationOutcome |
71-
| id | << ignore >> |
72-
| meta.profile.0 | https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome |
73-
| issue.0.severity | information |
74-
| issue.0.code | informational |
75-
| issue.0.details.coding.0.system | https://fhir.nhs.uk/StructureDefinition/NHSDigital-OperationOutcome |
76-
| issue.0.details.coding.0.code | RESOURCE_CREATED |
77-
| issue.0.details.coding.0.display | Resource created |
78-
| issue.0.diagnostics | Resource created |
79-
And the response headers contain:
80-
| name | value |
81-
| Content-Type | application/json |
82-
| Content-Length | 466 |
83-
When I make a "GET" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/${ note(product_team_id) }/Product/<id>"
71+
And I note the response field "$.id" as "product_id_2"
72+
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id_1) }"
8473
Then I receive a status code "200" with body
8574
| path | value |
86-
| id | << ignore >> |
75+
| id | ${ note(product_id_1) } |
76+
| name | My Great Product |
77+
| product_team_id | ${ note(product_team_id) } |
78+
| ods_code | F5H1R |
79+
| keys.0.key_value | F5H1R-850000 |
80+
| keys.0.key_type | party_key |
81+
| status | active |
82+
| created_on | << ignore >> |
83+
| updated_on | << ignore >> |
84+
| deleted_on | << ignore >> |
85+
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id_2) }"
86+
Then I receive a status code "200" with body
87+
| path | value |
88+
| id | ${ note(product_id_2) } |
8789
| name | My Other Great Product |
8890
| product_team_id | ${ note(product_team_id) } |
8991
| ods_code | F5H1R |
@@ -93,7 +95,3 @@ Feature: Create CPM Product for EPR - success scenarios
9395
| created_on | << ignore >> |
9496
| updated_on | << ignore >> |
9597
| deleted_on | << ignore >> |
96-
And the response headers contain:
97-
| name | value |
98-
| Content-Type | application/json |
99-
| Content-Length | 345 |

src/api/tests/feature_tests/features/createDeviceReferenceData.success.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Feature: Create Device Reference Data - success scenarios
1616
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product" with body:
1717
| path | value |
1818
| product_name | My Great Product |
19-
# ####### TODO: CAN REMOVE THE FOLLOWING LINE AFTER PI-536 completed
20-
When I make a "GET" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/${ note(product_team_id) }/Product/<id>"
2119
And I note the response field "$.id" as "product_id"
2220
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData" with body:
2321
| path | value |

src/api/tests/feature_tests/features/deleteCpmProduct.failure.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Feature: Delete CPM Product - failure scenarios
1818
Given I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product" with body:
1919
| path | value |
2020
| product_name | My Great CpmProduct |
21-
When I make a "DELETE" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/123/Product/<id>"
21+
And I note the response field "$.id" as "product_id"
22+
When I make a "DELETE" request with "default" headers to "ProductTeam/123/Product/${ note(product_id) }"
2223
Then I receive a status code "404" with body
2324
| path | value |
2425
| errors.0.code | RESOURCE_NOT_FOUND |

src/api/tests/feature_tests/features/deleteCpmProduct.success.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Feature: Delete CPM Product - success scenarios
1818
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product" with body:
1919
| path | value |
2020
| product_name | My Great Product |
21-
When I make a "DELETE" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/${ note(product_team_id) }/Product/<id>"
21+
And I note the response field "$.id" as "product_id"
22+
When I make a "DELETE" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }"
2223
Then I receive a status code "204"
2324
And the response headers contain:
2425
| name | value |

src/api/tests/feature_tests/features/readCpmProduct.failure.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Feature: Read CPM Product - failure scenarios
1818
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product" with body:
1919
| path | value |
2020
| product_name | My Great CpmProduct |
21-
When I make a "GET" request with "default" headers to the id in the location response header to the endpoint prefix "ProductTeam/123/Product/<id>"
21+
And I note the response field "$.id" as "product_id"
22+
When I make a "GET" request with "default" headers to "ProductTeam/123/Product/${ note(product_id) }"
2223
Then I receive a status code "404" with body
2324
| path | value |
2425
| errors.0.code | RESOURCE_NOT_FOUND |

0 commit comments

Comments
 (0)