Skip to content

Commit bda5169

Browse files
committed
[feature/PI-590-path_alias] fix-forward: resolve merge conflict
1 parent 63c9663 commit bda5169

File tree

8 files changed

+61
-110
lines changed

8 files changed

+61
-110
lines changed

src/api/createDeviceMessageHandlingSystem/tests/test_index.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_index() -> None:
136136
assert device.ods_code == ODS_CODE
137137
assert device.created_on.date() == datetime.today().date()
138138
assert device.updated_on.date() == datetime.today().date()
139-
assert device.deleted_on is None
139+
assert not device.deleted_on
140140

141141
questionnaire_responses = device.questionnaire_responses["spine_mhs/1"]
142142
assert len(questionnaire_responses) == 1
@@ -147,7 +147,11 @@ def test_index() -> None:
147147
repo = DeviceRepository(
148148
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
149149
)
150-
created_device = repo.read(device.id)
150+
created_device = repo.read(
151+
product_team_id=device.product_team_id,
152+
product_id=device.product_id,
153+
id=device.id,
154+
)
151155

152156
# Check party_key is added to tags in the created device
153157
expected_party_key = (str(ProductKeyType.PARTY_KEY), "abc1234-987654")

src/api/createDeviceReferenceDataASActions/tests/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_index_without_questionnaire() -> None:
9898
created_device_reference_data = repo.read(
9999
product_team_id=device_reference_data.product_team_id,
100100
product_id=device_reference_data.product_id,
101-
device_reference_data_id=device_reference_data.id,
101+
id=device_reference_data.id,
102102
)
103103
assert created_device_reference_data == device_reference_data
104104

@@ -155,6 +155,6 @@ def test_index_with_questionnaire() -> None:
155155
created_device_reference_data = repo.read(
156156
product_team_id=device_reference_data.product_team_id,
157157
product_id=device_reference_data.product_id,
158-
device_reference_data_id=device_reference_data.id,
158+
id=device_reference_data.id,
159159
)
160160
assert created_device_reference_data == device_reference_data

src/api/searchDeviceReferenceData/src/v1/steps.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,28 @@ def parse_incoming_path_parameters(data, cache) -> CpmProductPathParams:
1818
return CpmProductPathParams(**event.path_parameters)
1919

2020

21-
def validate_product_team(data, cache) -> ProductTeam:
21+
def read_product_team(data, cache) -> ProductTeam:
2222
product_team_repo = ProductTeamRepository(
2323
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
2424
)
2525
path_params: CpmProductPathParams = data[parse_incoming_path_parameters]
2626
return product_team_repo.read(id=path_params.product_team_id)
2727

2828

29-
def validate_product(data, cache) -> CpmProduct:
29+
def read_product(data, cache) -> CpmProduct:
3030
cpm_product_repo = CpmProductRepository(
3131
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
3232
)
33+
product_team: ProductTeam = data[read_product_team]
3334
path_params: CpmProductPathParams = data[parse_incoming_path_parameters]
3435
return cpm_product_repo.read(
35-
product_team_id=path_params.product_team_id, product_id=path_params.product_id
36+
product_team_id=product_team.id, id=path_params.product_id
3637
)
3738

3839

3940
def query_device_ref_data(data, cache) -> list[dict]:
40-
product_team: ProductTeam = data[validate_product_team]
41-
product: CpmProduct = data[validate_product]
41+
product_team: ProductTeam = data[read_product_team]
42+
product: CpmProduct = data[read_product]
4243
drd_repo = DeviceReferenceDataRepository(
4344
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
4445
)
@@ -54,8 +55,8 @@ def return_device_ref_data(data, cache) -> tuple[HTTPStatus, dict]:
5455

5556
steps = [
5657
parse_incoming_path_parameters,
57-
validate_product_team,
58-
validate_product,
58+
read_product_team,
59+
read_product,
5960
query_device_ref_data,
6061
return_device_ref_data,
6162
]

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ Feature: Create MHS Device - success scenarios
77
| version | 1 |
88
| Authorization | letmein |
99

10-
Scenario: Successfully create a MHS Device
10+
Scenario Outline: Successfully create a MHS Device
1111
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
12-
| path | value |
13-
| name | My Great Product Team |
14-
| ods_code | F5H1R |
12+
| path | value |
13+
| name | My Great Product Team |
14+
| ods_code | F5H1R |
15+
| keys.0.key_type | product_team_id_alias |
16+
| keys.0.key_value | FOOBAR |
1517
And I note the response field "$.id" as "product_team_id"
1618
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
1719
| path | value |
1820
| name | My Great Product |
1921
And I note the response field "$.id" as "product_id"
20-
And I note the response field "$.keys.0.key_type" as "party_key_tag"
21-
And I note the response field "$.keys.0.key_value" as "party_key_value"
22-
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/MessageHandlingSystem" with body:
22+
And I note the response field "$.keys.0.key_value" as "party_key"
23+
When I make a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/<product_id>/Device/MessageHandlingSystem" with body:
2324
| path | value |
2425
| questionnaire_responses.spine_mhs.0.Address | http://example.com |
2526
| questionnaire_responses.spine_mhs.0.Unique Identifier | 123456 |
@@ -68,10 +69,16 @@ Feature: Create MHS Device - success scenarios
6869
| updated_on | << ignore >> |
6970
| deleted_on | << ignore >> |
7071
| keys | [] |
71-
| tags.0.0.0 | ${ note(party_key_tag) } |
72-
| tags.0.0.1 | ${ note(party_key_value) } |
72+
| tags | << ignore >> |
7373
| questionnaire_responses | << ignore >> |
7474
And the response headers contain:
7575
| name | value |
7676
| Content-Type | application/json |
7777
| Content-Length | 1147 |
78+
79+
Examples:
80+
| product_team_id | product_id |
81+
| ${ note(product_team_id) } | ${ note(product_id) } |
82+
| ${ note(product_team_id) } | ${ note(party_key) } |
83+
| FOOBAR | ${ note(product_id) } |
84+
| FOOBAR | ${ note(party_key) } |

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar
77
| version | 1 |
88
| Authorization | letmein |
99

10-
Scenario: Successfully create an "AS Additional Interactions" Device Reference Data, with no questionnaire responses
10+
Scenario Outline: Successfully create an "AS Additional Interactions" Device Reference Data, with no questionnaire responses
1111
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
12-
| path | value |
13-
| name | My Great Product Team |
14-
| ods_code | F5H1R |
12+
| path | value |
13+
| name | My Great Product Team |
14+
| ods_code | F5H1R |
15+
| keys.0.key_type | product_team_id_alias |
16+
| keys.0.key_value | FOOBAR |
1517
And I note the response field "$.id" as "product_team_id"
1618
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
1719
| path | value |
1820
| name | My Great Product |
1921
And I note the response field "$.id" as "product_id"
2022
And I note the response field "$.keys.0.key_value" as "party_key"
21-
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/AccreditedSystemsAdditionalInteractions"
23+
When I make a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/<product_id>/DeviceReferenceData/AccreditedSystemsAdditionalInteractions"
2224
Then I receive a status code "201" with body
2325
| path | value |
2426
| id | << ignore >> |
@@ -52,18 +54,27 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar
5254
| Content-Type | application/json |
5355
| Content-Length | 333 |
5456

55-
Scenario: Successfully create an "AS Additional Interactions" Device Reference Data, with questionnaire responses
57+
Examples:
58+
| product_team_id | product_id |
59+
| ${ note(product_team_id) } | ${ note(product_id) } |
60+
| ${ note(product_team_id) } | ${ note(party_key) } |
61+
| FOOBAR | ${ note(product_id) } |
62+
| FOOBAR | ${ note(party_key) } |
63+
64+
Scenario Outline: Successfully create an "AS Additional Interactions" Device Reference Data, with questionnaire responses
5665
Given I have already made a "POST" request with "default" headers to "ProductTeam" with body:
57-
| path | value |
58-
| name | My Great Product Team |
59-
| ods_code | F5H1R |
66+
| path | value |
67+
| name | My Great Product Team |
68+
| ods_code | F5H1R |
69+
| keys.0.key_type | product_team_id_alias |
70+
| keys.0.key_value | FOOBAR |
6071
And I note the response field "$.id" as "product_team_id"
6172
And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body:
6273
| path | value |
6374
| name | My Great Product |
6475
And I note the response field "$.id" as "product_id"
6576
And I note the response field "$.keys.0.key_value" as "party_key"
66-
When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/AccreditedSystemsAdditionalInteractions" with body:
77+
When I make a "POST" request with "default" headers to "ProductTeam/<product_team_id>/Product/<product_id>/DeviceReferenceData/AccreditedSystemsAdditionalInteractions" with body:
6778
| path | value |
6879
| questionnaire_responses.spine_as_additional_interactions.0.Interaction ID | urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 |
6980
| questionnaire_responses.spine_as_additional_interactions.1.Interaction ID | urn:nhs:names:services:ebs:PRSC_IN080000UK07 |
@@ -117,3 +128,10 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar
117128
| name | value |
118129
| Content-Type | application/json |
119130
| Content-Length | 938 |
131+
132+
Examples:
133+
| product_team_id | product_id |
134+
| ${ note(product_team_id) } | ${ note(product_id) } |
135+
| ${ note(product_team_id) } | ${ note(party_key) } |
136+
| FOOBAR | ${ note(product_id) } |
137+
| FOOBAR | ${ note(party_key) } |

src/layers/domain/core/device/v3.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -391,39 +391,6 @@ def add_questionnaire_response(
391391
},
392392
)
393393

394-
@event
395-
def update_questionnaire_response(
396-
self,
397-
questionnaire_response: QuestionnaireResponse,
398-
) -> QuestionnaireResponseUpdatedEvent:
399-
questionnaire_id = questionnaire_response.questionnaire_id
400-
questionnaire_responses = self.questionnaire_responses.get(questionnaire_id)
401-
created_on = questionnaire_response.created_on
402-
403-
if questionnaire_responses is None:
404-
raise QuestionnaireNotFoundError(
405-
"This device does not contain a Questionnaire "
406-
f"with id '{questionnaire_id}'"
407-
)
408-
409-
current_created_ons = [qr.created_on for qr in questionnaire_responses]
410-
if created_on in current_created_ons:
411-
raise QuestionnaireResponseNotFoundError(
412-
"This device does not contain a Questionnaire with a "
413-
f"response created on '{created_on.isoformat()}'"
414-
)
415-
questionnaire_responses.append(questionnaire_response)
416-
417-
return QuestionnaireResponseUpdatedEvent(
418-
id=self.id,
419-
keys=[k.dict() for k in self.keys],
420-
tags=[t.value for t in self.tags],
421-
questionnaire_responses={
422-
q_name: [qr.dict() for qr in qrs]
423-
for q_name, qrs in self.questionnaire_responses.items()
424-
},
425-
)
426-
427394
def is_active(self):
428395
return self.status is Status.ACTIVE
429396

src/layers/domain/repository/device_repository/tests/v3/test_device_repository_questionnaire_responses_v3.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22

3-
from domain.repository.device_repository.tests.utils import devices_exactly_equal
43
import pytest
54
from domain.core.device.v3 import Device
65
from domain.core.questionnaire.v3 import Questionnaire
@@ -105,47 +104,3 @@ def test__device_repository__with_questionnaires_and_tags(
105104
)
106105
== device
107106
)
108-
109-
110-
@pytest.mark.integration
111-
def test__device_repository__modify_questionnaire_response_that_has_been_persisted(
112-
device: Device, repository: DeviceRepository, shoe_questionnaire: Questionnaire
113-
):
114-
# Persist model before updating model
115-
repository.write(device)
116-
intermediate_device = repository.read(
117-
product_team_id=device.product_team_id,
118-
product_id=device.product_id,
119-
id=device.id,
120-
)
121-
122-
# Update the model
123-
questionnaire_responses = intermediate_device.questionnaire_responses
124-
assert len(questionnaire_responses["shoe/1"]) == 2
125-
(_questionnaire_response, _) = questionnaire_responses["shoe/1"]
126-
127-
questionnaire_response = shoe_questionnaire.validate(
128-
{"foot": "R", "shoe-size": 789}
129-
)
130-
questionnaire_response.created_on = _questionnaire_response.created_on
131-
132-
intermediate_device.update_questionnaire_response(
133-
questionnaire_response=questionnaire_response
134-
)
135-
136-
# Persist and verify consistency
137-
repository.write(intermediate_device)
138-
device_from_db = repository.read(
139-
product_team_id=intermediate_device.product_team_id,
140-
product_id=intermediate_device.product_id,
141-
id=intermediate_device.id,
142-
)
143-
assert devices_exactly_equal(device_from_db, intermediate_device)
144-
assert not devices_exactly_equal(device_from_db, device)
145-
assert device_from_db.questionnaire_responses["shoe/1"][-1].data == {
146-
"foot": ["R"],
147-
"shoe-size": [789],
148-
}
149-
150-
assert device_from_db.created_on == device.created_on
151-
assert device_from_db.updated_on > device.updated_on

src/layers/domain/repository/device_repository/v3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,10 @@ def handle_QuestionnaireResponseUpdatedEvent(
409409
)
410410

411411
# Update "questionnaire_responses" on the tag-indexed Devices
412-
tag_values = {DeviceTag(__root__=tag) for tag in event.tags}
413412
update_tag_transactions = update_tag_indexes(
414413
table_name=self.table_name,
415414
device_id=event.id,
416-
tag_values=tag_values,
415+
tag_values=event.tags,
417416
data=data,
418417
)
419418
return update_root_and_key_transactions + update_tag_transactions

0 commit comments

Comments
 (0)