Debian Codegraph @

stripe/test_helpers/_test_clock.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._createable_api_resource import CreateableAPIResource
4 from stripe._deletable_api_resource import DeletableAPIResource
5 from stripe._list_object import ListObject
6 from stripe._listable_api_resource import ListableAPIResource
7 from stripe._stripe_object import StripeObject
8 from stripe._util import class_method_variant, sanitize_id
9 from typing import ClassVar, Optional, cast, overload
10 from typing_extensions import Literal, Unpack, TYPE_CHECKING
11
12 if TYPE_CHECKING:
13 from stripe.params.test_helpers._test_clock_advance_params import (
14 TestClockAdvanceParams,
15 )
16 from stripe.params.test_helpers._test_clock_create_params import (
17 TestClockCreateParams,
18 )
19 from stripe.params.test_helpers._test_clock_delete_params import (
20 TestClockDeleteParams,
21 )
22 from stripe.params.test_helpers._test_clock_list_params import (
23 TestClockListParams,
24 )
25 from stripe.params.test_helpers._test_clock_retrieve_params import (
26 TestClockRetrieveParams,
27 )
28
29
30 class TestClock(
31 CreateableAPIResource["TestClock"],
32 DeletableAPIResource["TestClock"],
33 ListableAPIResource["TestClock"],
34 ):
35 """
36 A test clock enables deterministic control over objects in testmode. With a test clock, you can create
37 objects at a frozen time in the past or future, and advance to a specific future time to observe webhooks and state changes. After the clock advances,
38 you can either validate the current state of your scenario (and test your assumptions), change the current state of your scenario (and test more complex scenarios), or keep advancing forward in time.
39 """
40
41 OBJECT_NAME: ClassVar[Literal["test_helpers.test_clock"]] = (
42 "test_helpers.test_clock"
43 )
44
45 class StatusDetails(StripeObject):
46 class Advancing(StripeObject):
47 target_frozen_time: int
48 """
49 The `frozen_time` that the Test Clock is advancing towards.
50 """
51
52 advancing: Optional[Advancing]
53 _inner_class_types = {"advancing": Advancing}
54
55 created: int
56 """
57 Time at which the object was created. Measured in seconds since the Unix epoch.
58 """
59 deleted: Optional[Literal[True]]
60 """
61 Always true for a deleted object
62 """
63 deletes_after: int
64 """
65 Time at which this clock is scheduled to auto delete.
66 """
67 frozen_time: int
68 """
69 Time at which all objects belonging to this clock are frozen.
70 """
71 id: str
72 """
73 Unique identifier for the object.
74 """
75 livemode: bool
76 """
77 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
78 """
79 name: Optional[str]
80 """
81 The custom name supplied at creation.
82 """
83 object: Literal["test_helpers.test_clock"]
84 """
85 String representing the object's type. Objects of the same type share the same value.
86 """
87 status: Literal["advancing", "internal_failure", "ready"]
88 """
89 The status of the Test Clock.
90 """
91 status_details: StatusDetails
92
93 @classmethod
94 def _cls_advance(
95 cls, test_clock: str, **params: Unpack["TestClockAdvanceParams"]
96 ) -> "TestClock":
97 """
98 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
99 """
100 return cast(
101 "TestClock",
102 cls._static_request(
103 "post",
104 "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
105 test_clock=sanitize_id(test_clock)
106 ),
107 params=params,
108 ),
109 )
110
111 @overload
112 @staticmethod
113 def advance(
114 test_clock: str, **params: Unpack["TestClockAdvanceParams"]
115 ) -> "TestClock":
116 """
117 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
118 """
119 ...
120
121 @overload
122 def advance(
123 self, **params: Unpack["TestClockAdvanceParams"]
124 ) -> "TestClock":
125 """
126 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
127 """
128 ...
129
130 @class_method_variant("_cls_advance")
131 def advance( # pyright: ignore[reportGeneralTypeIssues]
132 self, **params: Unpack["TestClockAdvanceParams"]
133 ) -> "TestClock":
134 """
135 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
136 """
137 return cast(
138 "TestClock",
139 self._request(
140 "post",
141 "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
142 test_clock=sanitize_id(self.get("id"))
143 ),
144 params=params,
145 ),
146 )
147
148 @classmethod
149 async def _cls_advance_async(
150 cls, test_clock: str, **params: Unpack["TestClockAdvanceParams"]
151 ) -> "TestClock":
152 """
153 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
154 """
155 return cast(
156 "TestClock",
157 await cls._static_request_async(
158 "post",
159 "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
160 test_clock=sanitize_id(test_clock)
161 ),
162 params=params,
163 ),
164 )
165
166 @overload
167 @staticmethod
168 async def advance_async(
169 test_clock: str, **params: Unpack["TestClockAdvanceParams"]
170 ) -> "TestClock":
171 """
172 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
173 """
174 ...
175
176 @overload
177 async def advance_async(
178 self, **params: Unpack["TestClockAdvanceParams"]
179 ) -> "TestClock":
180 """
181 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
182 """
183 ...
184
185 @class_method_variant("_cls_advance_async")
186 async def advance_async( # pyright: ignore[reportGeneralTypeIssues]
187 self, **params: Unpack["TestClockAdvanceParams"]
188 ) -> "TestClock":
189 """
190 Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
191 """
192 return cast(
193 "TestClock",
194 await self._request_async(
195 "post",
196 "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
197 test_clock=sanitize_id(self.get("id"))
198 ),
199 params=params,
200 ),
201 )
202
203 @classmethod
204 def create(cls, **params: Unpack["TestClockCreateParams"]) -> "TestClock":
205 """
206 Creates a new test clock that can be attached to new customers and quotes.
207 """
208 return cast(
209 "TestClock",
210 cls._static_request(
211 "post",
212 cls.class_url(),
213 params=params,
214 ),
215 )
216
217 @classmethod
218 async def create_async(
219 cls, **params: Unpack["TestClockCreateParams"]
220 ) -> "TestClock":
221 """
222 Creates a new test clock that can be attached to new customers and quotes.
223 """
224 return cast(
225 "TestClock",
226 await cls._static_request_async(
227 "post",
228 cls.class_url(),
229 params=params,
230 ),
231 )
232
233 @classmethod
234 def _cls_delete(
235 cls, sid: str, **params: Unpack["TestClockDeleteParams"]
236 ) -> "TestClock":
237 """
238 Deletes a test clock.
239 """
240 url = "%s/%s" % (cls.class_url(), sanitize_id(sid))
241 return cast(
242 "TestClock",
243 cls._static_request(
244 "delete",
245 url,
246 params=params,
247 ),
248 )
249
250 @overload
251 @staticmethod
252 def delete(
253 sid: str, **params: Unpack["TestClockDeleteParams"]
254 ) -> "TestClock":
255 """
256 Deletes a test clock.
257 """
258 ...
259
260 @overload
261 def delete(self, **params: Unpack["TestClockDeleteParams"]) -> "TestClock":
262 """
263 Deletes a test clock.
264 """
265 ...
266
267 @class_method_variant("_cls_delete")
268 def delete( # pyright: ignore[reportGeneralTypeIssues]
269 self, **params: Unpack["TestClockDeleteParams"]
270 ) -> "TestClock":
271 """
272 Deletes a test clock.
273 """
274 return self._request_and_refresh(
275 "delete",
276 self.instance_url(),
277 params=params,
278 )
279
280 @classmethod
281 async def _cls_delete_async(
282 cls, sid: str, **params: Unpack["TestClockDeleteParams"]
283 ) -> "TestClock":
284 """
285 Deletes a test clock.
286 """
287 url = "%s/%s" % (cls.class_url(), sanitize_id(sid))
288 return cast(
289 "TestClock",
290 await cls._static_request_async(
291 "delete",
292 url,
293 params=params,
294 ),
295 )
296
297 @overload
298 @staticmethod
299 async def delete_async(
300 sid: str, **params: Unpack["TestClockDeleteParams"]
301 ) -> "TestClock":
302 """
303 Deletes a test clock.
304 """
305 ...
306
307 @overload
308 async def delete_async(
309 self, **params: Unpack["TestClockDeleteParams"]
310 ) -> "TestClock":
311 """
312 Deletes a test clock.
313 """
314 ...
315
316 @class_method_variant("_cls_delete_async")
317 async def delete_async( # pyright: ignore[reportGeneralTypeIssues]
318 self, **params: Unpack["TestClockDeleteParams"]
319 ) -> "TestClock":
320 """
321 Deletes a test clock.
322 """
323 return await self._request_and_refresh_async(
324 "delete",
325 self.instance_url(),
326 params=params,
327 )
328
329 @classmethod
330 def list(
331 cls, **params: Unpack["TestClockListParams"]
332 ) -> ListObject["TestClock"]:
333 """
334 Returns a list of your test clocks.
335 """
336 result = cls._static_request(
337 "get",
338 cls.class_url(),
339 params=params,
340 )
341 if not isinstance(result, ListObject):
342 raise TypeError(
343 "Expected list object from API, got %s"
344 % (type(result).__name__)
345 )
346
347 return result
348
349 @classmethod
350 async def list_async(
351 cls, **params: Unpack["TestClockListParams"]
352 ) -> ListObject["TestClock"]:
353 """
354 Returns a list of your test clocks.
355 """
356 result = await cls._static_request_async(
357 "get",
358 cls.class_url(),
359 params=params,
360 )
361 if not isinstance(result, ListObject):
362 raise TypeError(
363 "Expected list object from API, got %s"
364 % (type(result).__name__)
365 )
366
367 return result
368
369 @classmethod
370 def retrieve(
371 cls, id: str, **params: Unpack["TestClockRetrieveParams"]
372 ) -> "TestClock":
373 """
374 Retrieves a test clock.
375 """
376 instance = cls(id, **params)
377 instance.refresh()
378 return instance
379
380 @classmethod
381 async def retrieve_async(
382 cls, id: str, **params: Unpack["TestClockRetrieveParams"]
383 ) -> "TestClock":
384 """
385 Retrieves a test clock.
386 """
387 instance = cls(id, **params)
388 await instance.refresh_async()
389 return instance
390
391 _inner_class_types = {"status_details": StatusDetails}