Skip to content

Commit 28d03b4

Browse files
committed
[feature/PI-503-read_device_reference_data] read device reference data
1 parent 8372db8 commit 28d03b4

File tree

13 files changed

+536
-71
lines changed

13 files changed

+536
-71
lines changed

src/api/createDeviceReferenceData/tests/test_index.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,13 @@ def test_index() -> None:
9191
repo = DeviceReferenceDataRepository(
9292
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
9393
)
94-
if hasattr(repo, "read"):
95-
raise Exception(
96-
"uncomment the following code now that you've implemented read"
97-
)
98-
created_device_reference_data = repo.read(
99-
product_team_id=device_reference_data.product_team_id,
100-
product_id=device_reference_data.product_id,
101-
device_reference_data_id=device_reference_data.id,
102-
)
103-
assert created_device_reference_data == device_reference_data
94+
95+
created_device_reference_data = repo.read(
96+
product_team_id=device_reference_data.product_team_id,
97+
product_id=device_reference_data.product_id,
98+
device_reference_data_id=device_reference_data.id,
99+
)
100+
assert created_device_reference_data == device_reference_data
104101

105102

106103
@pytest.mark.parametrize(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from api_utils.api_step_chain import execute_step_chain
2+
from event.aws.client import dynamodb_client
3+
from event.environment import BaseEnvironment
4+
from event.logging.logger import setup_logger
5+
6+
from .src.v1.steps import steps as v1_steps
7+
8+
9+
class Environment(BaseEnvironment):
10+
DYNAMODB_TABLE: str
11+
12+
13+
versioned_steps = {"1": v1_steps}
14+
cache = {
15+
**Environment.build().dict(),
16+
"DYNAMODB_CLIENT": dynamodb_client(),
17+
}
18+
19+
20+
def handler(event: dict, context=None):
21+
setup_logger(service_name=__file__)
22+
return execute_step_chain(
23+
event=event,
24+
cache=cache,
25+
versioned_steps=versioned_steps,
26+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from builder.lambda_build import build
2+
3+
if __name__ == "__main__":
4+
build(__file__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["dynamodb:Query"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["kms:Decrypt"]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
2+
from domain.core.cpm_product.v1 import CpmProduct
3+
from domain.core.device_reference_data.v1 import DeviceReferenceData
4+
from domain.core.product_team.v3 import ProductTeam
5+
from domain.repository.cpm_product_repository.v3 import CpmProductRepository
6+
from domain.repository.device_reference_data_repository.v1 import (
7+
DeviceReferenceDataRepository,
8+
)
9+
from domain.repository.product_team_repository.v2 import ProductTeamRepository
10+
from domain.request_models.v1 import DeviceReferenceDataPathParams
11+
from domain.response.validation_errors import mark_validation_errors_as_inbound
12+
from event.step_chain import StepChain
13+
14+
15+
@mark_validation_errors_as_inbound
16+
def parse_path_params(data, cache) -> DeviceReferenceDataPathParams:
17+
event = APIGatewayProxyEvent(data[StepChain.INIT])
18+
return DeviceReferenceDataPathParams(**event.path_parameters)
19+
20+
21+
def read_product_team(data, cache) -> ProductTeam:
22+
path_params: DeviceReferenceDataPathParams = data[parse_path_params]
23+
product_team_repo = ProductTeamRepository(
24+
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
25+
)
26+
return product_team_repo.read(id=path_params.product_team_id)
27+
28+
29+
def read_product(data, cache) -> CpmProduct:
30+
path_params: DeviceReferenceDataPathParams = data[parse_path_params]
31+
product_repo = CpmProductRepository(
32+
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
33+
)
34+
cpm_product = product_repo.read(
35+
product_id=path_params.product_id, product_team_id=path_params.product_team_id
36+
)
37+
return cpm_product
38+
39+
40+
def read_device_reference_data(data, cache) -> DeviceReferenceData:
41+
path_params: DeviceReferenceDataPathParams = data[parse_path_params]
42+
product_repo = DeviceReferenceDataRepository(
43+
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
44+
)
45+
return product_repo.read(
46+
product_id=path_params.product_id,
47+
product_team_id=path_params.product_team_id,
48+
device_reference_data_id=path_params.device_reference_data_id,
49+
)
50+
51+
52+
def device_reference_data_to_dict(data, cache) -> dict:
53+
device_reference_data: DeviceReferenceData = data[read_device_reference_data]
54+
return device_reference_data.state()
55+
56+
57+
steps = [
58+
parse_path_params,
59+
read_product_team,
60+
read_product,
61+
read_device_reference_data,
62+
device_reference_data_to_dict,
63+
]

0 commit comments

Comments
 (0)