Skip to content

Commit 634cd76

Browse files
committed
Merge branch 'feature/PI-590-path_alias' into release/2024-11-13
2 parents 08f984f + bda5169 commit 634cd76

File tree

59 files changed

+1798
-1677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1798
-1677
lines changed

infrastructure/terraform/per_workspace/main.tf

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,15 @@ module "table" {
4343
attributes = [
4444
{ name = "pk", type = "S" },
4545
{ name = "sk", type = "S" },
46-
{ name = "pk_1", type = "S" },
47-
{ name = "sk_1", type = "S" },
48-
{ name = "pk_2", type = "S" },
49-
{ name = "sk_2", type = "S" }
46+
{ name = "pk_read", type = "S" },
47+
{ name = "sk_read", type = "S" },
5048
]
5149

5250
global_secondary_indexes = [
5351
{
54-
name = "idx_gsi_1"
55-
hash_key = "pk_1"
56-
range_key = "sk_1"
57-
projection_type = "ALL"
58-
},
59-
{
60-
name = "idx_gsi_2"
61-
hash_key = "pk_2"
62-
range_key = "sk_2"
52+
name = "idx_gsi_read"
53+
hash_key = "pk_read"
54+
range_key = "sk_read"
6355
projection_type = "ALL"
6456
}
6557
]

src/api/createCpmProductForEpr/tests/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_index():
6666
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
6767
)
6868
read_product = repo.read(
69-
product_team_id=product_team.id, product_id=created_product["id"]
69+
product_team_id=product_team.id, id=created_product["id"]
7070
).state()
7171

7272
assert created_product == read_product

src/api/createDevice/tests/test_index.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,19 @@ def test_index() -> None:
8383
assert device.name == DEVICE_NAME
8484
assert device.ods_code == ODS_CODE
8585
assert device.created_on.date() == datetime.today().date()
86-
assert device.updated_on is None
87-
assert device.deleted_on is None
86+
assert not device.updated_on
87+
assert not device.deleted_on
8888

8989
# Retrieve the created resource
9090
repo = DeviceRepository(
9191
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
9292
)
9393

94-
created_device = repo.read(device.id)
94+
created_device = repo.read(
95+
product_team_id=device.product_team_id,
96+
product_id=device.product_id,
97+
id=device.id,
98+
)
9599
assert created_device == device
96100

97101

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/createDeviceReferenceData/tests/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_index() -> None:
9696
created_device_reference_data = repo.read(
9797
product_team_id=device_reference_data.product_team_id,
9898
product_id=device_reference_data.product_id,
99-
device_reference_data_id=device_reference_data.id,
99+
id=device_reference_data.id,
100100
)
101101
assert created_device_reference_data == device_reference_data
102102

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/createDeviceReferenceDataMessageSet/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

@@ -157,6 +157,6 @@ def test_index_with_questionnaire() -> None:
157157
created_device_reference_data = repo.read(
158158
product_team_id=device_reference_data.product_team_id,
159159
product_id=device_reference_data.product_id,
160-
device_reference_data_id=device_reference_data.id,
160+
id=device_reference_data.id,
161161
)
162162
assert created_device_reference_data == device_reference_data

src/api/deleteCpmProduct/tests/test_index.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from unittest import mock
55

66
import pytest
7-
from domain.core.cpm_product.v1 import CpmProduct
87
from domain.core.cpm_system_id.v1 import ProductId
98
from domain.core.enum import Status
109
from domain.core.root.v3 import Root
11-
from domain.repository.cpm_product_repository.v3 import CpmProductRepository
10+
from domain.repository.cpm_product_repository.v3 import (
11+
CpmProductRepository,
12+
InactiveCpmProductRepository,
13+
)
1214
from domain.repository.errors import ItemNotFound
13-
from domain.repository.keys.v3 import TableKey
14-
from domain.repository.marshall import marshall, unmarshall
1515
from domain.repository.product_team_repository.v2 import ProductTeamRepository
1616

1717
from test_helpers.dynamodb import mock_table
@@ -27,26 +27,6 @@
2727
VERSION = 1
2828

2929

30-
class MockCpmProductRepository(CpmProductRepository):
31-
def read_inactive_product(
32-
self, product_team_id: str, product_id: str
33-
) -> CpmProduct:
34-
pk = TableKey.CPM_PRODUCT_STATUS.key(Status.INACTIVE, product_team_id)
35-
sk = TableKey.CPM_PRODUCT.key(product_id)
36-
args = {
37-
"TableName": self.table_name,
38-
"KeyConditionExpression": "pk = :pk AND sk = :sk",
39-
"ExpressionAttributeValues": marshall(**{":pk": pk, ":sk": sk}),
40-
}
41-
result = self.client.query(**args)
42-
items = [unmarshall(i) for i in result["Items"]]
43-
if len(items) == 0:
44-
raise ItemNotFound(product_team_id, product_id, item_type=CpmProduct)
45-
(item,) = items
46-
47-
return CpmProduct(**item)
48-
49-
5030
@contextmanager
5131
def mock_lambda():
5232
org = Root.create_ods_organisation(ods_code=CPM_PRODUCT_TEAM_NO_ID["ods_code"])
@@ -100,13 +80,13 @@ def test_index():
10080
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
10181
)
10282
with pytest.raises(ItemNotFound):
103-
repo.read(product_team_id=product_team.id, product_id=PRODUCT_ID)
83+
repo.read(product_team_id=product_team.id, id=PRODUCT_ID)
10484

105-
repo = MockCpmProductRepository(
85+
repo = InactiveCpmProductRepository(
10686
table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"]
10787
)
108-
deleted_product = repo.read_inactive_product(
109-
product_team_id=product_team.id, product_id=PRODUCT_ID
88+
deleted_product = repo.read(
89+
product_team_id=product_team.id, id=PRODUCT_ID
11090
).dict()
11191

11292
# Sense checks on the deleted resource

src/api/readDevice/src/v1/steps.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,30 @@ def read_product_team(data, cache) -> ProductTeam:
2828

2929
def read_product(data, cache) -> CpmProduct:
3030
path_params: DevicePathParams = data[parse_path_params]
31+
product_team: ProductTeam = data[read_product_team]
32+
3133
product_repo = CpmProductRepository(
3234
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
3335
)
3436
cpm_product = product_repo.read(
35-
product_id=path_params.product_id, product_team_id=path_params.product_team_id
37+
product_team_id=product_team.id, id=path_params.product_id
3638
)
3739
return cpm_product
3840

3941

4042
def read_device(data, cache) -> Device:
4143
path_params: DevicePathParams = data[parse_path_params]
44+
product_team: ProductTeam = data[read_product_team]
45+
product: CpmProduct = data[read_product]
46+
4247
device_repo = DeviceRepository(
4348
table_name=cache["DYNAMODB_TABLE"], dynamodb_client=cache["DYNAMODB_CLIENT"]
4449
)
45-
return device_repo.read(path_params.device_id)
50+
return device_repo.read(
51+
product_team_id=product_team.id,
52+
product_id=product.id,
53+
id=path_params.device_id,
54+
)
4655

4756

4857
def device_to_dict(data, cache) -> tuple[str, dict]:

src/api/readDevice/tests/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_index_no_such_device(version):
154154
"errors": [
155155
{
156156
"code": "RESOURCE_NOT_FOUND",
157-
"message": "Could not find Device for key ('does not exist')", # device saved by pk, sk = device.id still
157+
"message": f"Could not find Device for key ('{product_team.id}', 'P.XXX-YYY', 'does not exist')",
158158
}
159159
],
160160
}

0 commit comments

Comments
 (0)