@@ -7,6 +7,17 @@ class TestAPIResource(object):
77 class MyResource (stripe .APIResource ):
88 OBJECT_NAME = "myresource"
99
10+ class MyDeletableResource (stripe .DeletableAPIResource ):
11+ OBJECT_NAME = "myresource"
12+
13+ @classmethod
14+ def my_method (cls , ** params ):
15+ return cls ._static_request (
16+ "post" ,
17+ cls .class_url (),
18+ params = params ,
19+ )
20+
1021 def test_retrieve_and_refresh (self , http_client_mock ):
1122 path = "/v1/myresources/foo%2A"
1223 query_string = "myparam=5"
@@ -122,24 +133,24 @@ def test_raise_on_incorrect_id_type(self):
122133 with pytest .raises (stripe .error .InvalidRequestError ):
123134 self .MyResource .retrieve (obj )
124135
125- def test_class_method_does_not_forward_options (self , http_client_mock ):
126- http_client_mock .stub_request (
127- "get" ,
128- "/v1/myresources/foo" ,
129- rbody = '{"id": "foo"}' ,
130- )
131-
136+ def test_class_methods_use_global_options (self , http_client_mock ):
132137 key = "newkey"
133138 stripe_version = "2023-01-01"
134139 stripe_account = "acct_foo"
135140
136- resource = self .MyResource .construct_from (
141+ resource = self .MyDeletableResource .construct_from (
137142 {"id" : "foo" },
138143 key = key ,
139144 stripe_version = stripe_version ,
140145 stripe_account = stripe_account ,
141146 )
142147
148+ http_client_mock .stub_request (
149+ "get" ,
150+ "/v1/myresources/foo" ,
151+ rbody = '{"id": "foo"}' ,
152+ )
153+
143154 resource .retrieve ("foo" )
144155
145156 http_client_mock .assert_requested (
@@ -150,6 +161,22 @@ def test_class_method_does_not_forward_options(self, http_client_mock):
150161 extra_headers = {"Stripe-Account" : None },
151162 )
152163
164+ http_client_mock .stub_request (
165+ "post" ,
166+ "/v1/myresources" ,
167+ rbody = '{"id": "foo", "object": "myresource"}' ,
168+ )
169+
170+ self .MyDeletableResource .my_method ()
171+
172+ http_client_mock .assert_requested (
173+ "post" ,
174+ path = "/v1/myresources" ,
175+ api_key = stripe .api_key ,
176+ stripe_version = stripe .api_version ,
177+ extra_headers = {"Stripe-Account" : None },
178+ )
179+
153180 def test_class_method_prefers_method_arguments (self , http_client_mock ):
154181 http_client_mock .stub_request (
155182 "get" ,
@@ -179,6 +206,83 @@ def test_class_method_prefers_method_arguments(self, http_client_mock):
179206 stripe_account = "acct_bar" ,
180207 )
181208
209+ def test_retrieve_forwards_options (self , http_client_mock ):
210+ http_client_mock .stub_request (
211+ "get" ,
212+ "/v1/myresources/foo" ,
213+ rbody = '{"id": "foo"}' ,
214+ )
215+
216+ res = self .MyDeletableResource .retrieve (
217+ "foo" ,
218+ api_key = "newkey" ,
219+ stripe_version = "2023-01-01" ,
220+ stripe_account = "foo" ,
221+ )
222+
223+ http_client_mock .assert_requested (
224+ "get" ,
225+ path = "/v1/myresources/foo" ,
226+ api_key = "newkey" ,
227+ stripe_version = "2023-01-01" ,
228+ stripe_account = "foo" ,
229+ )
230+
231+ http_client_mock .stub_request (
232+ "delete" ,
233+ "/v1/myresources/foo" ,
234+ )
235+
236+ res .delete ()
237+
238+ http_client_mock .assert_requested (
239+ "delete" ,
240+ path = "/v1/myresources/foo" ,
241+ api_key = "newkey" ,
242+ stripe_version = "2023-01-01" ,
243+ stripe_account = "foo" ,
244+ )
245+
246+ def test_class_method_forwards_options (self , http_client_mock ):
247+ from stripe ._object_classes import OBJECT_CLASSES
248+
249+ OBJECT_CLASSES ["myresource" ] = self .MyDeletableResource
250+
251+ http_client_mock .stub_request (
252+ "post" ,
253+ "/v1/myresources" ,
254+ rbody = '{"id": "foo", "object": "myresource"}' ,
255+ )
256+
257+ res = self .MyDeletableResource .my_method (
258+ api_key = "newkey" , stripe_version = "2023-01-01" , stripe_account = "foo"
259+ )
260+
261+ http_client_mock .assert_requested (
262+ "post" ,
263+ path = "/v1/myresources" ,
264+ api_key = "newkey" ,
265+ stripe_version = "2023-01-01" ,
266+ stripe_account = "foo" ,
267+ )
268+
269+ http_client_mock .stub_request (
270+ "delete" ,
271+ "/v1/myresources/foo" ,
272+ )
273+
274+ res .delete ()
275+
276+ http_client_mock .assert_requested (
277+ "delete" ,
278+ path = "/v1/myresources/foo" ,
279+ api_key = "newkey" ,
280+ stripe_version = "2023-01-01" ,
281+ stripe_account = "foo" ,
282+ )
283+
284+ del OBJECT_CLASSES ["myresource" ]
285+
182286 def test_instance_method_forwards_options (self , http_client_mock ):
183287 http_client_mock .stub_request (
184288 "get" ,
0 commit comments