Skip to content

Commit d8a225d

Browse files
committed
PR updates
1 parent a68d12e commit d8a225d

File tree

5 files changed

+51
-99
lines changed

5 files changed

+51
-99
lines changed

src/api/createDeviceAccreditedSystem/src/v1/steps.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66
read_product,
77
read_product_team,
88
)
9-
10-
# from domain.core import device
119
from domain.core.cpm_product import CpmProduct
12-
from domain.core.device import ( # DeviceTagAddedEvent,;; DeviceKeyAddedEvent,; DeviceReferenceDataIdAddedEvent,
10+
from domain.core.device import (
1311
Device,
1412
DeviceTagAddedEvent,
1513
QuestionnaireResponseUpdatedEvent,
1614
)
17-
18-
# from domain.core.device_key.v1 import DeviceKeyType
1915
from domain.core.device_reference_data import DeviceReferenceData
20-
from domain.core.error import ( # InvalidSpineAsResponse,
16+
from domain.core.error import (
2117
AccreditedSystemFatalError,
2218
ConfigurationError,
2319
NotEprProductError,
@@ -34,6 +30,7 @@
3430
)
3531
from domain.request_models import CpmProductPathParams, CreateAsDeviceIncomingParams
3632
from domain.response.validation_errors import mark_validation_errors_as_inbound
33+
from sds.epr.constants import EprNameTemplate
3734

3835

3936
@mark_validation_errors_as_inbound
@@ -91,10 +88,14 @@ def validate_spine_as_questionnaire_response(data, cache) -> QuestionnaireRespon
9188
def create_as_device(data, cache) -> Device:
9289
product: CpmProduct = data[read_product]
9390
payload: CreateAsDeviceIncomingParams = data[parse_as_device_payload]
91+
party_key: str = data[get_party_key]
9492

9593
# Create a new Device dictionary excluding 'questionnaire_responses'
94+
# Ticket PI-666 adds ASID generation. This will need to be sent across in the arguments instead of an empty string.
9695
device_payload = payload.dict(exclude={"questionnaire_responses"})
97-
return product.create_device(**device_payload)
96+
return product.create_device(
97+
EprNameTemplate.AS_DEVICE.format(party_key=party_key, asid=""), **device_payload
98+
)
9899

99100

100101
def create_party_key_tag(data, cache) -> DeviceTagAddedEvent:

src/api/createDeviceAccreditedSystem/tests/test_index.py

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def test_index() -> None:
425425
device = Device(**_device)
426426
assert device.product_team_id == product.product_team_id
427427
assert device.product_id == product.id
428-
assert device.name == DEVICE_NAME
428+
assert device.name == "ABC1234-987654/ - Accredited System"
429429
assert device.ods_code == ODS_CODE
430430
assert device.created_on.date() == datetime.today().date()
431431
assert device.updated_on.date() == datetime.today().date()
@@ -503,63 +503,6 @@ def test_incoming_errors(body, path_parameters, error_code, status_code):
503503
assert error_code in response["body"]
504504

505505

506-
# def test_as_already_exists() -> None:
507-
# with mock_epr_product_with_message_sets_drd() as (index, product):
508-
# # Execute the lambda
509-
# response = index.handler(
510-
# event={
511-
# "headers": {"version": VERSION},
512-
# "body": json.dumps(
513-
# {"questionnaire_responses": {"spine_as": [QUESTIONNAIRE_DATA]}}
514-
# ),
515-
# "pathParameters": {
516-
# "product_team_id": str(product.product_team_id),
517-
# "product_id": str(product.id),
518-
# },
519-
# }
520-
# )
521-
#
522-
# # Validate that the response indicates that a resource was created
523-
# assert response["statusCode"] == 201
524-
#
525-
# _device = json_loads(response["body"])
526-
# device = Device(**_device)
527-
# assert device.product_team_id == product.product_team_id
528-
# assert device.product_id == product.id
529-
# assert device.name == DEVICE_NAME
530-
#
531-
# response2 = index.handler(
532-
# event={
533-
# "headers": {"version": VERSION},
534-
# "body": json.dumps(
535-
# {"questionnaire_responses": {"spine_as": [QUESTIONNAIRE_DATA]}}
536-
# ),
537-
# "pathParameters": {
538-
# "product_team_id": str(product.product_team_id),
539-
# "product_id": str(product.id),
540-
# },
541-
# }
542-
# )
543-
#
544-
# assert response2["statusCode"] == 400
545-
# expected_error_code = "VALIDATION_ERROR"
546-
# expected_message_code = (
547-
# "There is already an existing AS Device for this Product"
548-
# )
549-
# assert expected_error_code in response2["body"]
550-
# assert expected_message_code in response2["body"]
551-
552-
# # Retrieve the created resource
553-
# repo = DeviceRepository(
554-
# table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
555-
# )
556-
# created_device = repo.read(device.id)
557-
#
558-
# # Check party_key is added to tags in the created device
559-
# expected_party_key = (str(ProductKeyType.PARTY_KEY), "abc1234-987654")
560-
# assert any(expected_party_key in tag.__root__ for tag in created_device.tags)
561-
562-
563506
@pytest.mark.parametrize(
564507
["body", "error_code", "error_message", "status_code"],
565508
[

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

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,42 +60,54 @@ Feature: Create AS Device - success scenarios
6060
| questionnaire_responses.spine_as.0.Date Requested | 2024-01-03 |
6161
| questionnaire_responses.spine_as.0.Product Key | product-key-001 |
6262
Then I receive a status code "201" with body
63-
| path | value |
64-
| id | << ignore >> |
65-
| name | Product-AS |
66-
| status | active |
67-
| product_id | ${ note(product_id) } |
68-
| product_team_id | ${ note(product_team_id) } |
69-
| ods_code | F5H1R |
70-
| keys | [] |
71-
| created_on | << ignore >> |
72-
| updated_on | << ignore >> |
73-
| deleted_on | << ignore >> |
74-
| questionnaire_responses | << ignore >> |
75-
| device_reference_data | << ignore >> |
63+
| path | value |
64+
| id | << ignore >> |
65+
| name | F5H1R-850000/ - Accredited System |
66+
| status | active |
67+
| product_id | ${ note(product_id) } |
68+
| product_team_id | ${ note(product_team_id) } |
69+
| ods_code | F5H1R |
70+
| keys | [] |
71+
| created_on | << ignore >> |
72+
| updated_on | << ignore >> |
73+
| deleted_on | << ignore >> |
74+
| questionnaire_responses.spine_as/1.0.id | << ignore >> |
75+
| questionnaire_responses.spine_as/1.0.questionnaire_name | spine_as |
76+
| questionnaire_responses.spine_as/1.0.questionnaire_version | 1 |
77+
| questionnaire_responses.spine_as/1.0.data.ODS Code | FH15R |
78+
| questionnaire_responses.spine_as/1.0.data.Client ODS Codes.0 | FH15R |
79+
| questionnaire_responses.spine_as/1.0.data.ASID | Foobar |
80+
| questionnaire_responses.spine_as/1.0.data.Party Key | P.123-XXX |
81+
| questionnaire_responses.spine_as/1.0.data.Approver URP | approver-123 |
82+
| questionnaire_responses.spine_as/1.0.data.Date Approved | 2024-01-01 |
83+
| questionnaire_responses.spine_as/1.0.data.Requestor URP | requestor-789 |
84+
| questionnaire_responses.spine_as/1.0.data.Date Requested | 2024-01-03 |
85+
| questionnaire_responses.spine_as/1.0.data.Product Key | product-key-001 |
86+
| questionnaire_responses.spine_as/1.0.created_on | << ignore >> |
87+
| device_reference_data | << ignore >> |
7688
And the response headers contain:
7789
| name | value |
7890
| Content-Type | application/json |
79-
| Content-Length | 960 |
91+
| Content-Length | 983 |
8092
And I note the response field "$.id" as "device_id"
8193
When I make a "GET" request with "default" headers to "ProductTeam/${ note(product_team_id) }/Product/${ note(product_id) }/Device/${ note(device_id) }"
8294
Then I receive a status code "200" with body
83-
| path | value |
84-
| id | ${ note(device_id) } |
85-
| name | Product-AS |
86-
| status | active |
87-
| product_id | ${ note(product_id) } |
88-
| product_team_id | ${ note(product_team_id) } |
89-
| ods_code | F5H1R |
90-
| created_on | << ignore >> |
91-
| updated_on | << ignore >> |
92-
| deleted_on | << ignore >> |
93-
| keys | [] |
94-
| tags.0.0.0 | ${ note(party_key_tag) } |
95-
| tags.0.0.1 | ${ note(party_key_tag_value) } |
96-
| questionnaire_responses | << ignore >> |
97-
| device_reference_data | << ignore >> |
95+
| path | value |
96+
| id | ${ note(device_id) } |
97+
| name | F5H1R-850000/ - Accredited System |
98+
| status | active |
99+
| product_id | ${ note(product_id) } |
100+
| product_team_id | ${ note(product_team_id) } |
101+
| ods_code | F5H1R |
102+
| created_on | << ignore >> |
103+
| updated_on | << ignore >> |
104+
| deleted_on | << ignore >> |
105+
| keys | [] |
106+
| tags.0.0.0 | ${ note(party_key_tag) } |
107+
| tags.0.0.1 | ${ note(party_key_tag_value) } |
108+
| questionnaire_responses | << ignore >> |
109+
| device_reference_data | << ignore >> |
98110
And the response headers contain:
99111
| name | value |
100112
| Content-Type | application/json |
101-
| Content-Length | 1697 |
113+
| Content-Length | 1720 |

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
UPDATED_ON = "updated_on"
2222
DEVICE_UPDATED_ON = f"device_{UPDATED_ON}"
23-
MHS_DEVICE_NAME = "Product-MHS"
24-
AS_DEVICE_NAME = "Product-AS"
2523

2624

2725
class QuestionnaireNotFoundError(Exception):

src/layers/domain/request_models/v1.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import defaultdict
22
from typing import Literal
33

4-
from domain.core.device import AS_DEVICE_NAME, MHS_DEVICE_NAME
54
from domain.core.product_team_key import ProductTeamKey
65
from domain.repository.questionnaire_repository import QuestionnaireInstance
76
from pydantic import BaseModel, Extra, Field
@@ -84,7 +83,6 @@ class CreateMhsDeviceIncomingParams(BaseModel, extra=Extra.forbid):
8483

8584

8685
class CreateAsDeviceIncomingParams(BaseModel, extra=Extra.forbid):
87-
name: str = AS_DEVICE_NAME
8886
questionnaire_responses: dict[
8987
Literal[QuestionnaireInstance.SPINE_AS], SpineAsQuestionnaireResponse
9088
] = Field(...)

0 commit comments

Comments
 (0)