3
3
from contextlib import contextmanager
4
4
from datetime import datetime
5
5
from unittest import mock
6
- from uuid import UUID
7
6
8
7
import pytest
9
8
from domain .core .cpm_system_id .v1 import PartyKeyId , ProductId
10
9
from domain .core .enum import Status
11
- from domain .core .root import Root
10
+ from domain .core .root . v3 import Root
12
11
from domain .repository .cpm_product_repository .v3 import CpmProductRepository
13
12
from domain .repository .product_team_repository .v2 import ProductTeamRepository
14
13
from event .json import json_loads
15
14
from nhs_context_logging import app_logger
16
15
17
16
from test_helpers .dynamodb import mock_table
17
+ from test_helpers .sample_data import CPM_PRODUCT_TEAM_NO_ID
18
18
from test_helpers .uuid import consistent_uuid
19
19
20
20
TABLE_NAME = "hiya"
21
-
22
- ODS_CODE = "AAA"
21
+ ODS_CODE = "F5H1R"
23
22
PRODUCT_TEAM_ID = consistent_uuid (1 )
24
23
PRODUCT_NAME = "My Product"
24
+ PRODUCT_TEAM_KEYS = CPM_PRODUCT_TEAM_NO_ID ["keys" ]
25
25
VERSION = 1
26
26
RESOURCE_CREATED = {
27
27
"resourceType" : "OperationOutcome" ,
51
51
52
52
@contextmanager
53
53
def mock_lambda ():
54
- org = Root .create_ods_organisation (ods_code = ODS_CODE )
55
- product_team = org .create_product_team (id = PRODUCT_TEAM_ID , name = PRODUCT_NAME )
54
+ org = Root .create_ods_organisation (ods_code = CPM_PRODUCT_TEAM_NO_ID ["ods_code" ])
55
+ product_team = org .create_product_team (
56
+ name = CPM_PRODUCT_TEAM_NO_ID ["name" ], keys = CPM_PRODUCT_TEAM_NO_ID ["keys" ]
57
+ )
56
58
57
59
with mock_table (table_name = TABLE_NAME ) as client , mock .patch .dict (
58
60
os .environ ,
@@ -68,20 +70,19 @@ def mock_lambda():
68
70
69
71
index .cache ["DYNAMODB_CLIENT" ] = client
70
72
71
- yield index
73
+ yield index , product_team
72
74
73
75
74
76
def test_index ():
75
- with mock_lambda () as index :
77
+ with mock_lambda () as ( index , product_team ) :
76
78
# Execute the lambda
77
79
response = index .handler (
78
80
event = {
79
81
"headers" : {"version" : VERSION },
80
82
"body" : json .dumps ({"product_name" : PRODUCT_NAME }),
81
- "pathParameters" : {"product_team_id" : PRODUCT_TEAM_ID },
83
+ "pathParameters" : {"product_team_id" : product_team . id },
82
84
}
83
85
)
84
-
85
86
# Validate that the response indicates that a resource was created
86
87
assert response ["statusCode" ] == 201
87
88
assert json_loads (response ["body" ]) == {
@@ -94,7 +95,7 @@ def test_index():
94
95
table_name = TABLE_NAME , dynamodb_client = index .cache ["DYNAMODB_CLIENT" ]
95
96
)
96
97
created_product = repo .read (
97
- product_team_id = PRODUCT_TEAM_ID , product_id = response ["headers" ]["Location" ]
98
+ product_team_id = product_team . id , product_id = response ["headers" ]["Location" ]
98
99
).dict ()
99
100
100
101
# Sense checks on the created resource
@@ -108,7 +109,7 @@ def test_index():
108
109
"deleted_on" : None ,
109
110
"name" : PRODUCT_NAME ,
110
111
"ods_code" : ODS_CODE ,
111
- "product_team_id" : UUID ( PRODUCT_TEAM_ID ) ,
112
+ "product_team_id" : product_team . id ,
112
113
"status" : Status .ACTIVE ,
113
114
}
114
115
@@ -143,7 +144,7 @@ def test_index():
143
144
],
144
145
)
145
146
def test_incoming_errors (body , path_parameters , error_code , status_code ):
146
- with mock_lambda () as index :
147
+ with mock_lambda () as ( index , product_team ) :
147
148
# Execute the lambda
148
149
response = index .handler (
149
150
event = {
0 commit comments