55from requests_mock .adapter import Adapter
66
77from commercetools import CommercetoolsError
8- from commercetools .client import Client
98from commercetools .platform import models
9+ from commercetools .platform .client import Client
1010
1111
1212@pytest .fixture ()
@@ -34,14 +34,13 @@ def test_auto_refresh(commercetools_api):
3434 client = Client (
3535 client_id = "unittest" ,
3636 client_secret = "mysecret" ,
37- project_key = "test" ,
3837 url = "https://api.europe-west1.gcp.commercetools.com" ,
3938 token_url = "https://auth.europe-west1.gcp.commercetools.com/oauth/token" ,
40- )
41- client .products . query ()
39+ ). with_project_key ( "unittest" )
40+ client .products (). get ()
4241 time .sleep (1 )
43- client .products . query ()
44- client .products . query ()
42+ client .products (). get ()
43+ client .products (). get ()
4544
4645 auth_headers = set ()
4746 for request in commercetools_api .requests_mock .request_history :
@@ -56,7 +55,7 @@ def test_cache_token(commercetools_api):
5655 Client (
5756 client_id = "unittest" ,
5857 client_secret = "none" ,
59- project_key = " test" ,
58+ scope = [ "manage_project: test"] ,
6059 url = "https://api.europe-west1.gcp.commercetools.com" ,
6160 token_url = "https://auth.europe-west1.gcp.commercetools.com/oauth/token" ,
6261 )
@@ -90,90 +89,135 @@ def test_allows_passing_custom_http_adapter():
9089 assert len (my_adapter .request_history ) == 1
9190
9291
93- def test_resource_update_conflict (old_client ):
92+ def test_resource_update_conflict (ct_platform_client : Client ):
9493 """Test the return value of the update methods.
9594
9695 It doesn't test the actual update itself.
9796 TODO: See if this is worth testing since we're using a mocking backend
9897 """
99- product = old_client .products .create (
100- models .ProductDraft (
101- key = "test-product" ,
102- product_type = models .ProductTypeResourceIdentifier (key = "dummy" ),
103- name = {"en" : "my-product" },
104- slug = {"en" : "foo-bar" },
98+ product = (
99+ ct_platform_client .with_project_key ("unittest" )
100+ .products ()
101+ .post (
102+ models .ProductDraft (
103+ key = "test-product" ,
104+ product_type = models .ProductTypeResourceIdentifier (key = "dummy" ),
105+ name = {"en" : "my-product" },
106+ slug = {"en" : "foo-bar" },
107+ )
105108 )
106109 )
107110
108111 assert product .version == 1
109112 assert uuid .UUID (product .id )
110113 assert product .key == "test-product"
111114
112- product = old_client .products .update_by_id (
113- id = product .id ,
114- version = product .version ,
115- actions = [
116- models .ProductChangeSlugAction (slug = models .LocalizedString (nl = "nl-slug2" ))
117- ],
115+ product = (
116+ ct_platform_client .with_project_key ("unittest" )
117+ .products ()
118+ .with_id (product .id )
119+ .post (
120+ models .ProductUpdate (
121+ version = product .version ,
122+ actions = [
123+ models .ProductChangeSlugAction (
124+ slug = models .LocalizedString (nl = "nl-slug2" )
125+ )
126+ ],
127+ )
128+ )
118129 )
119130 assert product .key == "test-product"
120131 assert product .version == 2
121132
122133 # This should raise a version conflict error
123134 with pytest .raises (CommercetoolsError ) as exc :
124- product = old_client .products .update_by_id (
125- id = product .id ,
126- version = 1 ,
127- actions = [
128- models .ProductChangeSlugAction (
129- slug = models .LocalizedString (nl = "nl-slug3" )
135+ product = (
136+ ct_platform_client .with_project_key ("unittest" )
137+ .products ()
138+ .with_id (product .id )
139+ .post (
140+ models .ProductUpdate (
141+ version = 1 ,
142+ actions = [
143+ models .ProductChangeSlugAction (
144+ slug = models .LocalizedString (nl = "nl-slug3" )
145+ )
146+ ],
130147 )
131- ],
148+ )
132149 )
133150 assert exc .value .response .status_code == 409
134151 assert exc .value .response .errors [0 ].current_version == 2
135152
136153 # Force it
137- product = old_client .products .update_by_id (
138- id = product .id ,
139- version = 1 ,
140- actions = [
141- models .ProductChangeSlugAction (slug = models .LocalizedString (nl = "nl-slug2" ))
142- ],
143- force_update = True ,
154+ product = (
155+ ct_platform_client .with_project_key ("unittest" )
156+ .products ()
157+ .with_id (product .id )
158+ .post (
159+ models .ProductUpdate (
160+ version = 1 ,
161+ actions = [
162+ models .ProductChangeSlugAction (
163+ slug = models .LocalizedString (nl = "nl-slug2" )
164+ )
165+ ],
166+ ),
167+ options = {"force_version" : True },
168+ )
144169 )
145170
146171
147- def test_resource_delete_conflict (old_client ):
172+ def test_resource_delete_conflict (ct_platform_client : Client ):
148173 """Test the return value of the delete methods.
149174
150175 It doesn't test the actual delete itself.
151176 TODO: See if this is worth testing since we're using a mocking backend
152177 """
153- product = old_client .products .create (
154- models .ProductDraft (
155- key = "test-product" ,
156- product_type = models .ProductTypeResourceIdentifier (key = "dummy" ),
157- name = {"en" : "my-product" },
158- slug = {"en" : "foo-bar" },
178+ product = (
179+ ct_platform_client .with_project_key ("unittest" )
180+ .products ()
181+ .post (
182+ models .ProductDraft (
183+ key = "test-product" ,
184+ product_type = models .ProductTypeResourceIdentifier (key = "dummy" ),
185+ name = {"en" : "my-product" },
186+ slug = {"en" : "foo-bar" },
187+ )
159188 )
160189 )
161190
162- product = old_client .products .update_by_id (
163- id = product .id ,
164- version = product .version ,
165- actions = [
166- models .ProductChangeSlugAction (slug = models .LocalizedString (nl = "nl-slug2" ))
167- ],
191+ product = (
192+ ct_platform_client .with_project_key ("unittest" )
193+ .products ()
194+ .with_id (product .id )
195+ .post (
196+ models .ProductUpdate (
197+ version = product .version ,
198+ actions = [
199+ models .ProductChangeSlugAction (
200+ slug = models .LocalizedString (nl = "nl-slug2" )
201+ )
202+ ],
203+ ),
204+ )
168205 )
169206 assert product .version == 2
170207
171208 # This should raise a version conflict error
172209 with pytest .raises (CommercetoolsError ) as exc :
173- product = old_client .products .delete_by_id (id = product .id , version = 1 )
210+ product = (
211+ ct_platform_client .with_project_key ("unittest" )
212+ .products ()
213+ .with_id (product .id )
214+ .delete (version = 1 )
215+ )
174216
175217 assert exc .value .response .status_code == 409
176218 assert exc .value .response .errors [0 ].current_version == 2
177219
178220 # Force it
179- old_client .products .delete_by_id (id = product .id , version = 1 , force_delete = True )
221+ ct_platform_client .with_project_key ("unittest" ).products ().with_id (
222+ product .id
223+ ).delete (version = 1 , options = {"force_version" : True })
0 commit comments