|
4 | 4 | from unittest import mock |
5 | 5 |
|
6 | 6 | import pytest |
7 | | -from domain.core.cpm_product.v1 import CpmProduct |
8 | 7 | from domain.core.cpm_system_id.v1 import ProductId |
9 | 8 | from domain.core.enum import Status |
10 | 9 | 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 | +) |
12 | 14 | from domain.repository.errors import ItemNotFound |
13 | | -from domain.repository.keys.v3 import TableKey |
14 | | -from domain.repository.marshall import marshall, unmarshall |
15 | 15 | from domain.repository.product_team_repository.v2 import ProductTeamRepository |
16 | 16 |
|
17 | 17 | from test_helpers.dynamodb import mock_table |
|
27 | 27 | VERSION = 1 |
28 | 28 |
|
29 | 29 |
|
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 | | - |
50 | 30 | @contextmanager |
51 | 31 | def mock_lambda(): |
52 | 32 | org = Root.create_ods_organisation(ods_code=CPM_PRODUCT_TEAM_NO_ID["ods_code"]) |
@@ -100,13 +80,13 @@ def test_index(): |
100 | 80 | table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"] |
101 | 81 | ) |
102 | 82 | 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) |
104 | 84 |
|
105 | | - repo = MockCpmProductRepository( |
| 85 | + repo = InactiveCpmProductRepository( |
106 | 86 | table_name=TABLE_NAME, dynamodb_client=index.cache["DYNAMODB_CLIENT"] |
107 | 87 | ) |
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 |
110 | 90 | ).dict() |
111 | 91 |
|
112 | 92 | # Sense checks on the deleted resource |
|
0 commit comments