• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-python / 10567939360

26 Aug 2024 10:02PM UTC coverage: 96.388% (+0.001%) from 96.387%
10567939360

Pull #1380

github

web-flow
Merge 1a7a18201 into 4b36e4111
Pull Request #1380: Update generated code for beta

1343 of 2037 branches covered (65.93%)

Branch coverage included in aggregate %.

42 of 42 new or added lines in 10 files covered. (100.0%)

180 existing lines in 7 files now uncovered.

84818 of 87353 relevant lines covered (97.1%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.57
/stripe/test_helpers/_test_clock.py
1
# -*- coding: utf-8 -*-
2
# File generated from our OpenAPI spec
3
from stripe._createable_api_resource import CreateableAPIResource
1✔
4
from stripe._deletable_api_resource import DeletableAPIResource
1✔
5
from stripe._list_object import ListObject
1✔
6
from stripe._listable_api_resource import ListableAPIResource
1✔
7
from stripe._request_options import RequestOptions
1✔
8
from stripe._util import class_method_variant, sanitize_id
1✔
9
from typing import ClassVar, List, Optional, cast, overload
1✔
10
from typing_extensions import Literal, NotRequired, Unpack
1✔
11

12

13
class TestClock(
1✔
14
    CreateableAPIResource["TestClock"],
15
    DeletableAPIResource["TestClock"],
16
    ListableAPIResource["TestClock"],
17
):
18
    """
19
    A test clock enables deterministic control over objects in testmode. With a test clock, you can create
20
    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,
21
    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.
22
    """
23

24
    OBJECT_NAME: ClassVar[Literal["test_helpers.test_clock"]] = (
1✔
25
        "test_helpers.test_clock"
26
    )
27

28
    class AdvanceParams(RequestOptions):
1✔
29
        expand: NotRequired[List[str]]
1✔
30
        """
1✔
31
        Specifies which fields in the response should be expanded.
32
        """
33
        frozen_time: int
1✔
34
        """
1✔
35
        The time to advance the test clock. Must be after the test clock's current frozen time. Cannot be more than two intervals in the future from the shortest subscription in this test clock. If there are no subscriptions in this test clock, it cannot be more than two years in the future.
36
        """
37

38
    class CreateParams(RequestOptions):
1✔
39
        expand: NotRequired[List[str]]
1✔
40
        """
1✔
41
        Specifies which fields in the response should be expanded.
42
        """
43
        frozen_time: int
1✔
44
        """
1✔
45
        The initial frozen time for this test clock.
46
        """
47
        name: NotRequired[str]
1✔
48
        """
1✔
49
        The name for this test clock.
50
        """
51

52
    class DeleteParams(RequestOptions):
1✔
53
        pass
1✔
54

55
    class ListParams(RequestOptions):
1✔
56
        ending_before: NotRequired[str]
1✔
57
        """
1✔
58
        A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
59
        """
60
        expand: NotRequired[List[str]]
1✔
61
        """
1✔
62
        Specifies which fields in the response should be expanded.
63
        """
64
        limit: NotRequired[int]
1✔
65
        """
1✔
66
        A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
67
        """
68
        starting_after: NotRequired[str]
1✔
69
        """
1✔
70
        A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
71
        """
72

73
    class RetrieveParams(RequestOptions):
1✔
74
        expand: NotRequired[List[str]]
1✔
75
        """
1✔
76
        Specifies which fields in the response should be expanded.
77
        """
78

79
    created: int
1✔
80
    """
1✔
81
    Time at which the object was created. Measured in seconds since the Unix epoch.
82
    """
83
    deletes_after: int
1✔
84
    """
1✔
85
    Time at which this clock is scheduled to auto delete.
86
    """
87
    frozen_time: int
1✔
88
    """
1✔
89
    Time at which all objects belonging to this clock are frozen.
90
    """
91
    id: str
1✔
92
    """
1✔
93
    Unique identifier for the object.
94
    """
95
    livemode: bool
1✔
96
    """
1✔
97
    Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
98
    """
99
    name: Optional[str]
1✔
100
    """
1✔
101
    The custom name supplied at creation.
102
    """
103
    object: Literal["test_helpers.test_clock"]
1✔
104
    """
1✔
105
    String representing the object's type. Objects of the same type share the same value.
106
    """
107
    status: Literal["advancing", "internal_failure", "ready"]
1✔
108
    """
1✔
109
    The status of the Test Clock.
110
    """
111
    deleted: Optional[Literal[True]]
1✔
112
    """
1✔
113
    Always true for a deleted object
114
    """
115

116
    @classmethod
1✔
117
    def _cls_advance(
1✔
118
        cls, test_clock: str, **params: Unpack["TestClock.AdvanceParams"]
119
    ) -> "TestClock":
120
        """
121
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
122
        """
123
        return cast(
1✔
124
            "TestClock",
125
            cls._static_request(
126
                "post",
127
                "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
128
                    test_clock=sanitize_id(test_clock)
129
                ),
130
                params=params,
131
            ),
132
        )
133

134
    @overload
1✔
135
    @staticmethod
1✔
136
    def advance(
1✔
137
        test_clock: str, **params: Unpack["TestClock.AdvanceParams"]
138
    ) -> "TestClock":
139
        """
140
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
141
        """
UNCOV
142
        ...
×
143

144
    @overload
1✔
145
    def advance(
1✔
146
        self, **params: Unpack["TestClock.AdvanceParams"]
147
    ) -> "TestClock":
148
        """
149
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
150
        """
UNCOV
151
        ...
×
152

153
    @class_method_variant("_cls_advance")
1✔
154
    def advance(  # pyright: ignore[reportGeneralTypeIssues]
1✔
155
        self, **params: Unpack["TestClock.AdvanceParams"]
156
    ) -> "TestClock":
157
        """
158
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
159
        """
UNCOV
160
        return cast(
×
161
            "TestClock",
162
            self._request(
163
                "post",
164
                "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
165
                    test_clock=sanitize_id(self.get("id"))
166
                ),
167
                params=params,
168
            ),
169
        )
170

171
    @classmethod
1✔
172
    async def _cls_advance_async(
1✔
173
        cls, test_clock: str, **params: Unpack["TestClock.AdvanceParams"]
174
    ) -> "TestClock":
175
        """
176
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
177
        """
178
        return cast(
1✔
179
            "TestClock",
180
            await cls._static_request_async(
181
                "post",
182
                "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
183
                    test_clock=sanitize_id(test_clock)
184
                ),
185
                params=params,
186
            ),
187
        )
188

189
    @overload
1✔
190
    @staticmethod
1✔
191
    async def advance_async(
1✔
192
        test_clock: str, **params: Unpack["TestClock.AdvanceParams"]
193
    ) -> "TestClock":
194
        """
195
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
196
        """
UNCOV
197
        ...
×
198

199
    @overload
1✔
200
    async def advance_async(
1✔
201
        self, **params: Unpack["TestClock.AdvanceParams"]
202
    ) -> "TestClock":
203
        """
204
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
205
        """
UNCOV
206
        ...
×
207

208
    @class_method_variant("_cls_advance_async")
1✔
209
    async def advance_async(  # pyright: ignore[reportGeneralTypeIssues]
1✔
210
        self, **params: Unpack["TestClock.AdvanceParams"]
211
    ) -> "TestClock":
212
        """
213
        Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
214
        """
UNCOV
215
        return cast(
×
216
            "TestClock",
217
            await self._request_async(
218
                "post",
219
                "/v1/test_helpers/test_clocks/{test_clock}/advance".format(
220
                    test_clock=sanitize_id(self.get("id"))
221
                ),
222
                params=params,
223
            ),
224
        )
225

226
    @classmethod
1✔
227
    def create(cls, **params: Unpack["TestClock.CreateParams"]) -> "TestClock":
1✔
228
        """
229
        Creates a new test clock that can be attached to new customers and quotes.
230
        """
231
        return cast(
1✔
232
            "TestClock",
233
            cls._static_request(
234
                "post",
235
                cls.class_url(),
236
                params=params,
237
            ),
238
        )
239

240
    @classmethod
1✔
241
    async def create_async(
1✔
242
        cls, **params: Unpack["TestClock.CreateParams"]
243
    ) -> "TestClock":
244
        """
245
        Creates a new test clock that can be attached to new customers and quotes.
246
        """
247
        return cast(
1✔
248
            "TestClock",
249
            await cls._static_request_async(
250
                "post",
251
                cls.class_url(),
252
                params=params,
253
            ),
254
        )
255

256
    @classmethod
1✔
257
    def _cls_delete(
1✔
258
        cls, sid: str, **params: Unpack["TestClock.DeleteParams"]
259
    ) -> "TestClock":
260
        """
261
        Deletes a test clock.
262
        """
263
        url = "%s/%s" % (cls.class_url(), sanitize_id(sid))
1✔
264
        return cast(
1✔
265
            "TestClock",
266
            cls._static_request(
267
                "delete",
268
                url,
269
                params=params,
270
            ),
271
        )
272

273
    @overload
1✔
274
    @staticmethod
1✔
275
    def delete(
1✔
276
        sid: str, **params: Unpack["TestClock.DeleteParams"]
277
    ) -> "TestClock":
278
        """
279
        Deletes a test clock.
280
        """
UNCOV
281
        ...
×
282

283
    @overload
1✔
284
    def delete(
1✔
285
        self, **params: Unpack["TestClock.DeleteParams"]
286
    ) -> "TestClock":
287
        """
288
        Deletes a test clock.
289
        """
UNCOV
290
        ...
×
291

292
    @class_method_variant("_cls_delete")
1✔
293
    def delete(  # pyright: ignore[reportGeneralTypeIssues]
1✔
294
        self, **params: Unpack["TestClock.DeleteParams"]
295
    ) -> "TestClock":
296
        """
297
        Deletes a test clock.
298
        """
UNCOV
299
        return self._request_and_refresh(
×
300
            "delete",
301
            self.instance_url(),
302
            params=params,
303
        )
304

305
    @classmethod
1✔
306
    async def _cls_delete_async(
1✔
307
        cls, sid: str, **params: Unpack["TestClock.DeleteParams"]
308
    ) -> "TestClock":
309
        """
310
        Deletes a test clock.
311
        """
312
        url = "%s/%s" % (cls.class_url(), sanitize_id(sid))
1✔
313
        return cast(
1✔
314
            "TestClock",
315
            await cls._static_request_async(
316
                "delete",
317
                url,
318
                params=params,
319
            ),
320
        )
321

322
    @overload
1✔
323
    @staticmethod
1✔
324
    async def delete_async(
1✔
325
        sid: str, **params: Unpack["TestClock.DeleteParams"]
326
    ) -> "TestClock":
327
        """
328
        Deletes a test clock.
329
        """
UNCOV
330
        ...
×
331

332
    @overload
1✔
333
    async def delete_async(
1✔
334
        self, **params: Unpack["TestClock.DeleteParams"]
335
    ) -> "TestClock":
336
        """
337
        Deletes a test clock.
338
        """
UNCOV
339
        ...
×
340

341
    @class_method_variant("_cls_delete_async")
1✔
342
    async def delete_async(  # pyright: ignore[reportGeneralTypeIssues]
1✔
343
        self, **params: Unpack["TestClock.DeleteParams"]
344
    ) -> "TestClock":
345
        """
346
        Deletes a test clock.
347
        """
UNCOV
348
        return await self._request_and_refresh_async(
×
349
            "delete",
350
            self.instance_url(),
351
            params=params,
352
        )
353

354
    @classmethod
1✔
355
    def list(
1✔
356
        cls, **params: Unpack["TestClock.ListParams"]
357
    ) -> ListObject["TestClock"]:
358
        """
359
        Returns a list of your test clocks.
360
        """
361
        result = cls._static_request(
1✔
362
            "get",
363
            cls.class_url(),
364
            params=params,
365
        )
366
        if not isinstance(result, ListObject):
1!
UNCOV
367
            raise TypeError(
×
368
                "Expected list object from API, got %s"
369
                % (type(result).__name__)
370
            )
371

372
        return result
1✔
373

374
    @classmethod
1✔
375
    async def list_async(
1✔
376
        cls, **params: Unpack["TestClock.ListParams"]
377
    ) -> ListObject["TestClock"]:
378
        """
379
        Returns a list of your test clocks.
380
        """
381
        result = await cls._static_request_async(
1✔
382
            "get",
383
            cls.class_url(),
384
            params=params,
385
        )
386
        if not isinstance(result, ListObject):
1!
UNCOV
387
            raise TypeError(
×
388
                "Expected list object from API, got %s"
389
                % (type(result).__name__)
390
            )
391

392
        return result
1✔
393

394
    @classmethod
1✔
395
    def retrieve(
1✔
396
        cls, id: str, **params: Unpack["TestClock.RetrieveParams"]
397
    ) -> "TestClock":
398
        """
399
        Retrieves a test clock.
400
        """
401
        instance = cls(id, **params)
1✔
402
        instance.refresh()
1✔
403
        return instance
1✔
404

405
    @classmethod
1✔
406
    async def retrieve_async(
1✔
407
        cls, id: str, **params: Unpack["TestClock.RetrieveParams"]
408
    ) -> "TestClock":
409
        """
410
        Retrieves a test clock.
411
        """
412
        instance = cls(id, **params)
1✔
413
        await instance.refresh_async()
1✔
414
        return instance
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc