1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
# pyright: strict
# we specifically test various import patterns
from typing import Any
import stripe
import subprocess
import sys
def assert_output(code: str, expected: str) -> None:
process = subprocess.Popen(
[sys.executable, "-c", f"import stripe; print({code})"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()
assert not stderr, f"Error: {stderr.decode()}"
output = stdout.decode().strip()
# assert the output
assert output == expected
def test_can_import_stripe_object() -> None:
# fmt: off
from stripe.stripe_object import StripeObject as StripeObjectFromStripeStripeObject # type: ignore
# fmt: on
from stripe import (
StripeObject as StripeObjectFromStripe,
)
# fmt: off
assert stripe.stripe_object.StripeObject is StripeObjectFromStripeStripeObject # type: ignore
# fmt: on
assert stripe.StripeObject is StripeObjectFromStripeStripeObject
assert StripeObjectFromStripe is StripeObjectFromStripeStripeObject
def test_can_import_request_options() -> None:
# fmt: off
from stripe.request_options import RequestOptions as RequestOptionsStripeRequestOptions # type: ignore
# fmt: on
from stripe import (
RequestOptions as RequestOptionsFromStripe,
)
assert stripe.RequestOptions is RequestOptionsStripeRequestOptions
assert RequestOptionsFromStripe is RequestOptionsStripeRequestOptions
def test_can_import_http_client() -> None:
from stripe.http_client import HTTPClient as HTTPClientFromStripeHTTPClient # type: ignore
# fmt: off
from stripe.http_client import PycurlClient as PycurlClientFromStripeHTTPClient # type: ignore
from stripe.http_client import RequestsClient as RequestsClientFromStripeHTTPClient # type: ignore
from stripe.http_client import UrlFetchClient as UrlFetchClientFromStripeHTTPClient # type: ignore
from stripe.http_client import new_default_http_client as new_default_http_clientFromStripeHTTPClient # type: ignore
# fmt: on
from stripe import (
HTTPClient as HTTPClientFromStripe,
PycurlClient as PycurlClientFromStripe,
RequestsClient as RequestsClientFromStripe,
UrlFetchClient as UrlFetchClientFromStripe,
new_default_http_client as new_default_http_clientFromStripe,
)
assert HTTPClientFromStripe is HTTPClientFromStripeHTTPClient
assert PycurlClientFromStripe is PycurlClientFromStripeHTTPClient
assert RequestsClientFromStripe is RequestsClientFromStripeHTTPClient
assert UrlFetchClientFromStripe is UrlFetchClientFromStripeHTTPClient
assert (
new_default_http_clientFromStripe
is new_default_http_clientFromStripeHTTPClient
)
assert stripe.HTTPClient is HTTPClientFromStripeHTTPClient
assert stripe.PycurlClient is PycurlClientFromStripeHTTPClient
assert stripe.RequestsClient is RequestsClientFromStripeHTTPClient
assert stripe.UrlFetchClient is UrlFetchClientFromStripeHTTPClient
assert (
stripe.new_default_http_client
is new_default_http_clientFromStripeHTTPClient
)
def test_can_import_webhook_members() -> None:
from stripe.webhook import Webhook as WebhookFromStripeWebhook # type: ignore
# fmt: off
from stripe.webhook import WebhookSignature as WebhookSignatureFromStripeWebhook # type: ignore
# fmt: on
from stripe import (
Webhook,
WebhookSignature,
)
assert Webhook is not None
assert WebhookSignature is not None
assert WebhookFromStripeWebhook is Webhook
assert WebhookSignatureFromStripeWebhook is WebhookSignature
def test_can_import_list_search_objects() -> None:
# This import has to be single line, mypy and pyright are producing errors
# on different lines of multiline import
# fmt: off
from stripe.api_resources import ListObject as ListObjectFromResources # type: ignore
from stripe import ListObject as LOFromStripe
from stripe.api_resources import SearchResultObject as SearchObjectFromResources # type: ignore
from stripe import SearchResultObject as SOFromStripe
# fmt: on
from stripe import StripeObject
assert (
ListObjectFromResources[StripeObject]
== stripe.ListObject[StripeObject]
)
assert (
SearchObjectFromResources[StripeObject]
== stripe.SearchResultObject[StripeObject]
)
assert ListObjectFromResources[StripeObject] == LOFromStripe[StripeObject]
assert (
SearchObjectFromResources[StripeObject] == SOFromStripe[StripeObject]
)
def test_can_import_misc_resources() -> None:
from stripe.api_resources import ErrorObject, OAuthErrorObject # type: ignore
from stripe import (
ErrorObject as ErrorObjectFromStripe,
OAuthErrorObject as OAuthErrorObjectFromStripe,
)
# fmt: off
from stripe.api_resources.error_object import ErrorObject as ErrorObjectFromStripeApiResources # type: ignore
from stripe.api_resources.error_object import OAuthErrorObject as OAuthErrorObjectFromStripeApiResources # type: ignore
# fmt: on
# FileUpload is an old alias for File, time to hide it
from stripe.api_resources import FileUpload as FileUploadFromApiResources # type: ignore
from stripe import FileUpload as FileUploadFromStripe # type: ignore
assert ErrorObject is stripe.ErrorObject
assert ErrorObjectFromStripe is stripe.ErrorObject
assert ErrorObjectFromStripe is ErrorObjectFromStripeApiResources
assert OAuthErrorObject is stripe.OAuthErrorObject
assert OAuthErrorObjectFromStripe is stripe.OAuthErrorObject
assert OAuthErrorObject is OAuthErrorObjectFromStripeApiResources
assert FileUploadFromApiResources is stripe.FileUpload # type: ignore
assert FileUploadFromApiResources is FileUploadFromStripe
assert_output("stripe.error is not None", "True")
def test_can_import_abstract() -> None:
# fmt: off
from stripe.api_resources.abstract import APIResource as APIResourceFromAbstract # type: ignore
from stripe.api_resources.abstract import SingletonAPIResource as SingletonFromAbstract # type: ignore
from stripe.api_resources.abstract import CreateableAPIResource as CreateableFromAbstract # type: ignore
from stripe.api_resources.abstract import UpdateableAPIResource as UpdateableFromAbstract # type: ignore
from stripe.api_resources.abstract import DeletableAPIResource as DeletableFromAbstract # type: ignore
from stripe.api_resources.abstract import ListableAPIResource as ListableFromAbstract # type: ignore
from stripe.api_resources.abstract import SearchableAPIResource as SearchableFromAbstract # type: ignore
from stripe.api_resources.abstract import VerifyMixin as VerifyMixinFromAbstract # type: ignore
from stripe.api_resources.abstract import APIResourceTestHelpers as APIResourceTestHelpersFromAbstract # type: ignore
from stripe.api_resources.abstract import custom_method as custom_methodFromAbstract
from stripe.api_resources.abstract import nested_resource_class_methods as nested_resource_class_methodsFromAbstract
from stripe import APIResource as APIResourceFromStripe
from stripe import SingletonAPIResource as SingletonFromStripe
from stripe import CreateableAPIResource as CreateableFromStripe
from stripe import UpdateableAPIResource as UpdateableFromStripe
from stripe import DeletableAPIResource as DeletableFromStripe
from stripe import ListableAPIResource as ListableFromStripe
from stripe import SearchableAPIResource as SearchableFromStripe
from stripe import VerifyMixin as VerifyMixinFromStripe
from stripe import APIResourceTestHelpers as APIResourceTestHelpersFromStripe
from stripe import custom_method as custom_methodFromStripe # pyright: ignore[reportDeprecated]
from stripe import nested_resource_class_methods as nested_resource_class_methodsFromStripe
# fmt: on
from stripe.stripe_object import StripeObject # type: ignore
assert (
APIResourceFromAbstract[StripeObject]
== stripe.abstract.APIResource[StripeObject] # type: ignore
)
assert (
stripe.abstract.SingletonAPIResource[StripeObject] # type: ignore
== SingletonFromAbstract[StripeObject]
)
assert (
stripe.abstract.CreateableAPIResource[StripeObject] # type: ignore
== CreateableFromAbstract[StripeObject]
)
assert (
stripe.abstract.UpdateableAPIResource[StripeObject] # type: ignore
== UpdateableFromAbstract[StripeObject]
)
assert (
stripe.abstract.DeletableAPIResource[StripeObject] # type: ignore
== DeletableFromAbstract[StripeObject]
)
assert (
stripe.abstract.ListableAPIResource[StripeObject] # type: ignore
== ListableFromAbstract[StripeObject]
)
assert (
stripe.abstract.SearchableAPIResource[StripeObject] # type: ignore
== SearchableFromAbstract[StripeObject]
)
assert stripe.abstract.VerifyMixin is VerifyMixinFromAbstract # type: ignore
assert (
stripe.abstract.custom_method is custom_methodFromAbstract # type: ignore
)
assert (
stripe.abstract.APIResourceTestHelpers[Any] # type: ignore
is APIResourceTestHelpersFromAbstract[Any]
)
assert (
stripe.abstract.nested_resource_class_methods # type: ignore
is nested_resource_class_methodsFromAbstract
)
assert APIResourceFromStripe is APIResourceFromAbstract
assert SingletonFromStripe is SingletonFromAbstract
assert CreateableFromStripe is CreateableFromAbstract
assert UpdateableFromStripe is UpdateableFromAbstract
assert DeletableFromStripe is DeletableFromAbstract
assert ListableFromStripe is ListableFromAbstract
assert SearchableFromStripe is SearchableFromAbstract
assert VerifyMixinFromStripe is VerifyMixinFromAbstract
assert (
APIResourceTestHelpersFromStripe is APIResourceTestHelpersFromAbstract
)
assert custom_methodFromStripe is custom_methodFromAbstract
assert (
nested_resource_class_methodsFromStripe
is nested_resource_class_methodsFromAbstract
)
def test_can_import_app_info() -> None:
from stripe.app_info import AppInfo as AppInfoFromStripeAppInfo # type: ignore
from stripe import AppInfo as AppInfoFromStripe
assert AppInfoFromStripeAppInfo is AppInfoFromStripe
assert AppInfoFromStripeAppInfo is stripe.AppInfo
def test_can_import_stripe_response() -> None:
# fmt: off
from stripe.stripe_response import StripeResponse as StripeResponseFromStripeResponse # type: ignore
from stripe.stripe_response import StripeResponseBase as StripeResponseBaseFromStripeResponse # type: ignore
from stripe.stripe_response import StripeStreamResponse as StripeStreamResponseFromStripeResponse # type: ignore
# fmt: on
from stripe import (
StripeResponse as StripeResponseFromStripe,
StripeResponseBase as StripeResponseBaseFromStripe,
StripeStreamResponse as StripeStreamResponseFromStripe,
)
assert (
StripeResponseFromStripeResponse
is stripe.stripe_response.StripeResponse # type: ignore
)
assert StripeResponseFromStripe is StripeResponseFromStripeResponse
assert StripeResponseFromStripe is stripe.StripeResponse
assert StripeResponseBaseFromStripe is StripeResponseBaseFromStripeResponse
assert StripeResponseBaseFromStripe is stripe.StripeResponseBase
assert (
StripeStreamResponseFromStripe
is StripeStreamResponseFromStripeResponse
)
assert StripeStreamResponseFromStripe is stripe.StripeStreamResponse
def test_can_import_oauth_members() -> None:
from stripe.oauth import OAuth as OAuthFromStripeOAuth # type: ignore
from stripe import (
OAuth,
)
assert OAuth is not None
assert OAuthFromStripeOAuth is OAuth
assert OAuthFromStripeOAuth is stripe.OAuth
def test_can_import_util() -> None:
# fmt: off
from stripe.util import convert_to_stripe_object as convert_to_stripe_objectFromStripeUtil # type: ignore
# fmt: on
from stripe import (
convert_to_stripe_object as convert_to_stripe_objectFromStripe,
)
assert (
stripe.convert_to_stripe_object is convert_to_stripe_objectFromStripe
)
assert (
convert_to_stripe_objectFromStripe
is convert_to_stripe_objectFromStripeUtil
)
assert stripe.util.io is not None # type: ignore
assert_output("stripe.util is not None", "True")
def test_can_import_errors() -> None:
# fmt: off
from stripe.error import StripeError as StripeErrorFromStripeError # type: ignore
from stripe.error import APIError as APIErrorFromStripeError # type: ignore
from stripe.error import APIConnectionError as APIConnectionErrorFromStripeError # type: ignore
from stripe.error import StripeErrorWithParamCode as StripeErrorWithParamCodeFromStripeError # type: ignore
from stripe.error import CardError as CardErrorFromStripeError # type: ignore
from stripe.error import IdempotencyError as IdempotencyErrorFromStripeError # type: ignore
from stripe.error import InvalidRequestError as InvalidRequestErrorFromStripeError # type: ignore
from stripe.error import AuthenticationError as AuthenticationErrorFromStripeError # type: ignore
from stripe.error import PermissionError as PermissionErrorFromStripeError # type: ignore
from stripe.error import RateLimitError as RateLimitErrorFromStripeError # type: ignore
from stripe.error import SignatureVerificationError as SignatureVerificationErrorFromStripeError # type: ignore
# fmt: on
from stripe import StripeError as StripeErrorFromStripe
from stripe import APIError as APIErrorFromStripe
from stripe import APIConnectionError as APIConnectionErrorFromStripe
from stripe import (
StripeErrorWithParamCode as StripeErrorWithParamCodeFromStripe,
)
from stripe import CardError as CardErrorFromStripe
from stripe import IdempotencyError as IdempotencyErrorFromStripe
from stripe import InvalidRequestError as InvalidRequestErrorFromStripe
from stripe import AuthenticationError as AuthenticationErrorFromStripe
from stripe import PermissionError as PermissionErrorFromStripe
from stripe import RateLimitError as RateLimitErrorFromStripe
from stripe import (
SignatureVerificationError as SignatureVerificationErrorFromStripe,
)
assert StripeErrorFromStripeError is StripeErrorFromStripe
assert APIErrorFromStripeError is APIErrorFromStripe
assert APIConnectionErrorFromStripeError is APIConnectionErrorFromStripe
assert (
StripeErrorWithParamCodeFromStripeError
is StripeErrorWithParamCodeFromStripe
)
assert CardErrorFromStripeError is CardErrorFromStripe
assert IdempotencyErrorFromStripeError is IdempotencyErrorFromStripe
assert InvalidRequestErrorFromStripeError is InvalidRequestErrorFromStripe
assert AuthenticationErrorFromStripeError is AuthenticationErrorFromStripe
assert PermissionErrorFromStripeError is PermissionErrorFromStripe
assert RateLimitErrorFromStripeError is RateLimitErrorFromStripe
assert (
SignatureVerificationErrorFromStripeError
is SignatureVerificationErrorFromStripe
)
def test_can_import_top_level_resource() -> None:
from stripe import Account as AccountFromStripe
from stripe.api_resources import Account as AccountFromStripeResources # type: ignore
# This import has to be single line, mypy and pyright are producing errors
# on different lines of multiline import
from stripe.api_resources.account import Account as AccFromModule # type: ignore
assert stripe.Account == AccountFromStripe
assert AccountFromStripe == AccountFromStripeResources
assert AccFromModule == AccountFromStripeResources
assert_output("stripe.api_resources.Account is not None", "True")
assert_output("stripe.api_resources.account is not None", "True")
assert_output("stripe.api_resources.account.Account is not None", "True")
def test_can_import_namespaced_resource() -> None:
from stripe import tax as TaxPackage
from stripe.tax import (
Calculation as CalculationFromStripe,
)
# This import has to be single line, mypy and pyright are producing errors
# on different lines of multiline import
from stripe.api_resources.tax import Calculation as CalcFromResources # type: ignore
# This import has to be single line, mypy and pyright are producing errors
# on different lines of multiline import
# fmt: off
from stripe.api_resources.tax.calculation import Calculation as CalcFromModule # type: ignore
# fmt: on
assert stripe.tax is TaxPackage
assert stripe.tax.Calculation is CalculationFromStripe
assert stripe.tax.Calculation is TaxPackage.Calculation
assert stripe.tax.Calculation is CalcFromResources
assert CalcFromResources is CalcFromModule
assert_output("stripe.tax is not None", "True")
assert_output("stripe.tax.Calculation is not None", "True")
def test_can_import_top_level_service() -> None:
from stripe import AccountService as AccountServiceFromStripe
assert stripe.AccountService == AccountServiceFromStripe
assert_output("stripe.AccountService is not None", "True")
def test_can_import_namespaced_service() -> None:
from stripe import tax as TaxPackage
from stripe.tax import (
CalculationService as CalculationServiceFromStripe,
)
assert stripe.tax is TaxPackage
assert stripe.tax.CalculationService is CalculationServiceFromStripe
assert stripe.tax.CalculationService is TaxPackage.CalculationService
assert_output("stripe.tax is not None", "True")
assert_output("stripe.tax.CalculationService is not None", "True")
|