From bda51690475d7214953fc0793f01723418645fd6 Mon Sep 17 00:00:00 2001 From: Joel Klinger Date: Wed, 13 Nov 2024 13:04:29 +0000 Subject: [PATCH] [feature/PI-590-path_alias] fix-forward: resolve merge conflict --- .../tests/test_index.py | 8 +++- .../tests/test_index.py | 4 +- .../searchDeviceReferenceData/src/v1/steps.py | 15 ++++--- ...eviceMessageHandlingSystem.success.feature | 25 +++++++---- ...DataAdditionalInteractions.success.feature | 38 +++++++++++----- src/layers/domain/core/device/v3.py | 33 -------------- ...e_repository_questionnaire_responses_v3.py | 45 ------------------- .../domain/repository/device_repository/v3.py | 3 +- 8 files changed, 61 insertions(+), 110 deletions(-) diff --git a/src/api/createDeviceMessageHandlingSystem/tests/test_index.py b/src/api/createDeviceMessageHandlingSystem/tests/test_index.py index f70dfc0b..6f8910ef 100644 --- a/src/api/createDeviceMessageHandlingSystem/tests/test_index.py +++ b/src/api/createDeviceMessageHandlingSystem/tests/test_index.py @@ -136,7 +136,7 @@ def test_index() -> None: assert device.ods_code == ODS_CODE assert device.created_on.date() == datetime.today().date() assert device.updated_on.date() == datetime.today().date() - assert device.deleted_on is None + assert not device.deleted_on questionnaire_responses = device.questionnaire_responses["spine_mhs/1"] assert len(questionnaire_responses) == 1 @@ -147,7 +147,11 @@ def test_index() -> None: repo = DeviceRepository( table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"] ) - created_device = repo.read(device.id) + created_device = repo.read( + product_team_id=device.product_team_id, + product_id=device.product_id, + id=device.id, + ) # Check party_key is added to tags in the created device expected_party_key = (str(ProductKeyType.PARTY_KEY), "abc1234-987654") diff --git a/src/api/createDeviceReferenceDataASActions/tests/test_index.py b/src/api/createDeviceReferenceDataASActions/tests/test_index.py index 47036070..72b3e7a5 100644 --- a/src/api/createDeviceReferenceDataASActions/tests/test_index.py +++ b/src/api/createDeviceReferenceDataASActions/tests/test_index.py @@ -98,7 +98,7 @@ def test_index_without_questionnaire() -> None: created_device_reference_data = repo.read( product_team_id=device_reference_data.product_team_id, product_id=device_reference_data.product_id, - device_reference_data_id=device_reference_data.id, + id=device_reference_data.id, ) assert created_device_reference_data == device_reference_data @@ -155,6 +155,6 @@ def test_index_with_questionnaire() -> None: created_device_reference_data = repo.read( product_team_id=device_reference_data.product_team_id, product_id=device_reference_data.product_id, - device_reference_data_id=device_reference_data.id, + id=device_reference_data.id, ) assert created_device_reference_data == device_reference_data diff --git a/src/api/searchDeviceReferenceData/src/v1/steps.py b/src/api/searchDeviceReferenceData/src/v1/steps.py index a0cb7e9c..ffa71bfe 100644 --- a/src/api/searchDeviceReferenceData/src/v1/steps.py +++ b/src/api/searchDeviceReferenceData/src/v1/steps.py @@ -18,7 +18,7 @@ def parse_incoming_path_parameters(data, cache) -> CpmProductPathParams: return CpmProductPathParams(**event.path_parameters) -def validate_product_team(data, cache) -> ProductTeam: +def read_product_team(data, cache) -> ProductTeam: product_team_repo = ProductTeamRepository( table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"] ) @@ -26,19 +26,20 @@ def validate_product_team(data, cache) -> ProductTeam: return product_team_repo.read(id=path_params.product_team_id) -def validate_product(data, cache) -> CpmProduct: +def read_product(data, cache) -> CpmProduct: cpm_product_repo = CpmProductRepository( table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"] ) + product_team: ProductTeam = data[read_product_team] path_params: CpmProductPathParams = data[parse_incoming_path_parameters] return cpm_product_repo.read( - product_team_id=path_params.product_team_id, product_id=path_params.product_id + product_team_id=product_team.id, id=path_params.product_id ) def query_device_ref_data(data, cache) -> list[dict]: - product_team: ProductTeam = data[validate_product_team] - product: CpmProduct = data[validate_product] + product_team: ProductTeam = data[read_product_team] + product: CpmProduct = data[read_product] drd_repo = DeviceReferenceDataRepository( table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"] ) @@ -54,8 +55,8 @@ def return_device_ref_data(data, cache) -> tuple[HTTPStatus, dict]: steps = [ parse_incoming_path_parameters, - validate_product_team, - validate_product, + read_product_team, + read_product, query_device_ref_data, return_device_ref_data, ] diff --git a/src/api/tests/feature_tests/features/createDeviceMessageHandlingSystem.success.feature b/src/api/tests/feature_tests/features/createDeviceMessageHandlingSystem.success.feature index d7df743c..6c415d57 100644 --- a/src/api/tests/feature_tests/features/createDeviceMessageHandlingSystem.success.feature +++ b/src/api/tests/feature_tests/features/createDeviceMessageHandlingSystem.success.feature @@ -7,19 +7,20 @@ Feature: Create MHS Device - success scenarios | version | 1 | | Authorization | letmein | - Scenario: Successfully create a MHS Device + Scenario Outline: Successfully create a MHS Device Given I have already made a "POST" request with "default" headers to "ProductTeam" with body: - | path | value | - | name | My Great Product Team | - | ods_code | F5H1R | + | path | value | + | name | My Great Product Team | + | ods_code | F5H1R | + | keys.0.key_type | product_team_id_alias | + | keys.0.key_value | FOOBAR | And I note the response field "$.id" as "product_team_id" And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body: | path | value | | name | My Great Product | And I note the response field "$.id" as "product_id" - And I note the response field "$.keys.0.key_type" as "party_key_tag" - And I note the response field "$.keys.0.key_value" as "party_key_value" - When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/MessageHandlingSystem" with body: + And I note the response field "$.keys.0.key_value" as "party_key" + When I make a "POST" request with "default" headers to "ProductTeam//Product//Device/MessageHandlingSystem" with body: | path | value | | questionnaire_responses.spine_mhs.0.Address | http://example.com | | questionnaire_responses.spine_mhs.0.Unique Identifier | 123456 | @@ -68,10 +69,16 @@ Feature: Create MHS Device - success scenarios | updated_on | << ignore >> | | deleted_on | << ignore >> | | keys | [] | - | tags.0.0.0 | ${ note(party_key_tag) } | - | tags.0.0.1 | ${ note(party_key_value) } | + | tags | << ignore >> | | questionnaire_responses | << ignore >> | And the response headers contain: | name | value | | Content-Type | application/json | | Content-Length | 1147 | + + Examples: + | product_team_id | product_id | + | ${ note(product_team_id) } | ${ note(product_id) } | + | ${ note(product_team_id) } | ${ note(party_key) } | + | FOOBAR | ${ note(product_id) } | + | FOOBAR | ${ note(party_key) } | diff --git a/src/api/tests/feature_tests/features/createDeviceReferenceDataAdditionalInteractions.success.feature b/src/api/tests/feature_tests/features/createDeviceReferenceDataAdditionalInteractions.success.feature index 4802fb52..c806cb39 100644 --- a/src/api/tests/feature_tests/features/createDeviceReferenceDataAdditionalInteractions.success.feature +++ b/src/api/tests/feature_tests/features/createDeviceReferenceDataAdditionalInteractions.success.feature @@ -7,18 +7,20 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar | version | 1 | | Authorization | letmein | - Scenario: Successfully create an "AS Additional Interactions" Device Reference Data, with no questionnaire responses + Scenario Outline: Successfully create an "AS Additional Interactions" Device Reference Data, with no questionnaire responses Given I have already made a "POST" request with "default" headers to "ProductTeam" with body: - | path | value | - | name | My Great Product Team | - | ods_code | F5H1R | + | path | value | + | name | My Great Product Team | + | ods_code | F5H1R | + | keys.0.key_type | product_team_id_alias | + | keys.0.key_value | FOOBAR | And I note the response field "$.id" as "product_team_id" And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body: | path | value | | name | My Great Product | And I note the response field "$.id" as "product_id" And I note the response field "$.keys.0.key_value" as "party_key" - When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/AccreditedSystemsAdditionalInteractions" + When I make a "POST" request with "default" headers to "ProductTeam//Product//DeviceReferenceData/AccreditedSystemsAdditionalInteractions" Then I receive a status code "201" with body | path | value | | id | << ignore >> | @@ -52,18 +54,27 @@ Feature: Create "Additional Interactions" Device Reference Data - success scenar | Content-Type | application/json | | Content-Length | 333 | - Scenario: Successfully create an "AS Additional Interactions" Device Reference Data, with questionnaire responses + Examples: + | product_team_id | product_id | + | ${ note(product_team_id) } | ${ note(product_id) } | + | ${ note(product_team_id) } | ${ note(party_key) } | + | FOOBAR | ${ note(product_id) } | + | FOOBAR | ${ note(party_key) } | + + Scenario Outline: Successfully create an "AS Additional Interactions" Device Reference Data, with questionnaire responses Given I have already made a "POST" request with "default" headers to "ProductTeam" with body: - | path | value | - | name | My Great Product Team | - | ods_code | F5H1R | + | path | value | + | name | My Great Product Team | + | ods_code | F5H1R | + | keys.0.key_type | product_team_id_alias | + | keys.0.key_value | FOOBAR | And I note the response field "$.id" as "product_team_id" And I have already made a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/Epr" with body: | path | value | | name | My Great Product | And I note the response field "$.id" as "product_id" And I note the response field "$.keys.0.key_value" as "party_key" - When I make a "POST" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/DeviceReferenceData/AccreditedSystemsAdditionalInteractions" with body: + When I make a "POST" request with "default" headers to "ProductTeam//Product//DeviceReferenceData/AccreditedSystemsAdditionalInteractions" with body: | path | value | | questionnaire_responses.spine_as_additional_interactions.0.Interaction ID | urn:nhs:names:services:ers:READ_PRACTITIONER_ROLE_R4_V001 | | 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 | name | value | | Content-Type | application/json | | Content-Length | 938 | + + Examples: + | product_team_id | product_id | + | ${ note(product_team_id) } | ${ note(product_id) } | + | ${ note(product_team_id) } | ${ note(party_key) } | + | FOOBAR | ${ note(product_id) } | + | FOOBAR | ${ note(party_key) } | diff --git a/src/layers/domain/core/device/v3.py b/src/layers/domain/core/device/v3.py index c0625efb..0f892408 100644 --- a/src/layers/domain/core/device/v3.py +++ b/src/layers/domain/core/device/v3.py @@ -391,39 +391,6 @@ def add_questionnaire_response( }, ) - @event - def update_questionnaire_response( - self, - questionnaire_response: QuestionnaireResponse, - ) -> QuestionnaireResponseUpdatedEvent: - questionnaire_id = questionnaire_response.questionnaire_id - questionnaire_responses = self.questionnaire_responses.get(questionnaire_id) - created_on = questionnaire_response.created_on - - if questionnaire_responses is None: - raise QuestionnaireNotFoundError( - "This device does not contain a Questionnaire " - f"with id '{questionnaire_id}'" - ) - - current_created_ons = [qr.created_on for qr in questionnaire_responses] - if created_on in current_created_ons: - raise QuestionnaireResponseNotFoundError( - "This device does not contain a Questionnaire with a " - f"response created on '{created_on.isoformat()}'" - ) - questionnaire_responses.append(questionnaire_response) - - return QuestionnaireResponseUpdatedEvent( - id=self.id, - keys=[k.dict() for k in self.keys], - tags=[t.value for t in self.tags], - questionnaire_responses={ - q_name: [qr.dict() for qr in qrs] - for q_name, qrs in self.questionnaire_responses.items() - }, - ) - def is_active(self): return self.status is Status.ACTIVE diff --git a/src/layers/domain/repository/device_repository/tests/v3/test_device_repository_questionnaire_responses_v3.py b/src/layers/domain/repository/device_repository/tests/v3/test_device_repository_questionnaire_responses_v3.py index 26f60d1c..790ae555 100644 --- a/src/layers/domain/repository/device_repository/tests/v3/test_device_repository_questionnaire_responses_v3.py +++ b/src/layers/domain/repository/device_repository/tests/v3/test_device_repository_questionnaire_responses_v3.py @@ -1,6 +1,5 @@ import json -from domain.repository.device_repository.tests.utils import devices_exactly_equal import pytest from domain.core.device.v3 import Device from domain.core.questionnaire.v3 import Questionnaire @@ -105,47 +104,3 @@ def test__device_repository__with_questionnaires_and_tags( ) == device ) - - -@pytest.mark.integration -def test__device_repository__modify_questionnaire_response_that_has_been_persisted( - device: Device, repository: DeviceRepository, shoe_questionnaire: Questionnaire -): - # Persist model before updating model - repository.write(device) - intermediate_device = repository.read( - product_team_id=device.product_team_id, - product_id=device.product_id, - id=device.id, - ) - - # Update the model - questionnaire_responses = intermediate_device.questionnaire_responses - assert len(questionnaire_responses["shoe/1"]) == 2 - (_questionnaire_response, _) = questionnaire_responses["shoe/1"] - - questionnaire_response = shoe_questionnaire.validate( - {"foot": "R", "shoe-size": 789} - ) - questionnaire_response.created_on = _questionnaire_response.created_on - - intermediate_device.update_questionnaire_response( - questionnaire_response=questionnaire_response - ) - - # Persist and verify consistency - repository.write(intermediate_device) - device_from_db = repository.read( - product_team_id=intermediate_device.product_team_id, - product_id=intermediate_device.product_id, - id=intermediate_device.id, - ) - assert devices_exactly_equal(device_from_db, intermediate_device) - assert not devices_exactly_equal(device_from_db, device) - assert device_from_db.questionnaire_responses["shoe/1"][-1].data == { - "foot": ["R"], - "shoe-size": [789], - } - - assert device_from_db.created_on == device.created_on - assert device_from_db.updated_on > device.updated_on diff --git a/src/layers/domain/repository/device_repository/v3.py b/src/layers/domain/repository/device_repository/v3.py index 30d58db3..95a61eed 100644 --- a/src/layers/domain/repository/device_repository/v3.py +++ b/src/layers/domain/repository/device_repository/v3.py @@ -409,11 +409,10 @@ def handle_QuestionnaireResponseUpdatedEvent( ) # Update "questionnaire_responses" on the tag-indexed Devices - tag_values = {DeviceTag(__root__=tag) for tag in event.tags} update_tag_transactions = update_tag_indexes( table_name=self.table_name, device_id=event.id, - tag_values=tag_values, + tag_values=event.tags, data=data, ) return update_root_and_key_transactions + update_tag_transactions