11import pytest
22from domain .core .cpm_product import CpmProduct
33from domain .core .product_key import ProductKey , ProductKeyType
4- from domain .core .root import Root
54from domain .repository .cpm_product_repository import CpmProductRepository
6- from domain .repository .errors import AlreadyExistsError
7-
8- from test_helpers .sample_data import CPM_PRODUCT_TEAM_NO_ID
95
106PARTY_KEY = "ABC-123456"
117
@@ -17,32 +13,7 @@ def test__product_repository__add_key(
1713 party_key = ProductKey (key_type = ProductKeyType .PARTY_KEY , key_value = PARTY_KEY )
1814 product .add_key (** party_key .dict ())
1915 repository .write (product )
20-
2116 product_by_id = repository .read (
2217 product_team_id = product .product_team_id , id = product .id
2318 )
2419 assert product_by_id .keys == [party_key ]
25-
26-
27- @pytest .mark .integration
28- def test__product_repository__cannot_add_duplicate_key (
29- product : CpmProduct , repository : CpmProductRepository
30- ):
31- """This test guards against Party Key clashes"""
32-
33- party_key = ProductKey (key_type = ProductKeyType .PARTY_KEY , key_value = PARTY_KEY )
34- product .add_key (** party_key .dict ())
35- repository .write (product )
36-
37- # Create a second unrelated product
38- org = Root .create_ods_organisation (ods_code = CPM_PRODUCT_TEAM_NO_ID ["ods_code" ])
39- second_product_team = org .create_product_team (
40- name = CPM_PRODUCT_TEAM_NO_ID ["name" ], keys = CPM_PRODUCT_TEAM_NO_ID ["keys" ]
41- )
42- second_product = second_product_team .create_cpm_product (
43- name = "another-cpm-product-name"
44- )
45- second_product .add_key (** party_key .dict ())
46-
47- with pytest .raises (AlreadyExistsError ):
48- repository .write (second_product )
0 commit comments