mirror of https://github.com/zulip/zulip.git
billing: Add mypy stubs to stripe imports.
Tweaked by tabbott to add an extra type: ignore.
This commit is contained in:
parent
38dd9e49de
commit
abf485bfcb
3
mypy.ini
3
mypy.ini
|
@ -243,9 +243,6 @@ ignore_missing_imports = True
|
|||
[mypy-statsd]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-stripe,stripe.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-talon]
|
||||
ignore_missing_imports = True
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import stripe.error as error
|
||||
import stripe.util as util
|
||||
|
||||
from typing import Optional, Any, Dict, List
|
||||
|
||||
api_key: Optional[str]
|
||||
|
||||
class Customer:
|
||||
default_source: Card
|
||||
created: int
|
||||
id: str
|
||||
subscriptions: List[Subscription]
|
||||
|
||||
@staticmethod
|
||||
def retrieve(customer_id: str, expand: Optional[List[str]]) -> Customer:
|
||||
...
|
||||
@staticmethod
|
||||
def create(description: str, metadata: Dict[str, Any], source: str) -> Customer:
|
||||
...
|
||||
|
||||
class Invoice:
|
||||
amount_due: int
|
||||
@staticmethod
|
||||
def upcoming(customer: str) -> Invoice:
|
||||
...
|
||||
|
||||
class Subscription:
|
||||
created: int
|
||||
status: str
|
||||
@staticmethod
|
||||
def create(customer: str, billing: str, items: List[Dict[str, Any]],
|
||||
prorate: bool, tax_percent: float) -> Subscription:
|
||||
...
|
||||
|
||||
class Card:
|
||||
last4: str
|
||||
|
||||
class Plan:
|
||||
id: str
|
||||
@staticmethod
|
||||
def create(currency: str, interval: str, product: str, amount: int,
|
||||
billing_scheme: str, nickname: str, usage_type: str) -> Plan:
|
||||
...
|
||||
|
||||
class Product:
|
||||
id: str
|
||||
|
||||
@staticmethod
|
||||
def create(name: str, type: str, statement_descriptor: str, unit_label: str) -> Product:
|
||||
...
|
|
@ -0,0 +1,2 @@
|
|||
class ListObject:
|
||||
...
|
|
@ -0,0 +1,8 @@
|
|||
class StripeError(Exception):
|
||||
http_status: str
|
||||
|
||||
class CardError(Exception):
|
||||
http_status: str
|
||||
|
||||
class InvalidRequestError(Exception):
|
||||
...
|
|
@ -0,0 +1,5 @@
|
|||
from typing import Any, Dict
|
||||
from stripe.api_resources.list_object import ListObject
|
||||
|
||||
def convert_to_stripe_object(fixture_data: Dict[Any, Any]) -> ListObject:
|
||||
...
|
|
@ -269,18 +269,18 @@ class StripeTest(ZulipTestCase):
|
|||
mock_retrieve_customer: mock.Mock) -> None:
|
||||
# Only the most basic test. In particular, doesn't include testing with a
|
||||
# canceled subscription, because we don't have a fixture for it.
|
||||
customer_without_subscription = stripe.Customer.create()
|
||||
customer_without_subscription = stripe.Customer.create() # type: ignore # Mocked out function call
|
||||
self.assertIsNone(extract_current_subscription(customer_without_subscription))
|
||||
|
||||
customer_with_subscription = stripe.Customer.retrieve()
|
||||
customer_with_subscription = stripe.Customer.retrieve() # type: ignore # Mocked out function call
|
||||
subscription = extract_current_subscription(customer_with_subscription)
|
||||
self.assertEqual(subscription["id"][:4], "sub_")
|
||||
|
||||
@mock.patch("stripe.Customer.retrieve", side_effect=mock_retrieve_customer)
|
||||
def test_subscribe_customer_to_second_plan(self, mock_retrieve_customer: mock.Mock) -> None:
|
||||
with self.assertRaisesRegex(AssertionError, "Customer already has an active subscription."):
|
||||
do_subscribe_customer_to_plan(stripe.Customer.retrieve(), self.stripe_plan_id,
|
||||
self.quantity, 0)
|
||||
do_subscribe_customer_to_plan(stripe.Customer.retrieve(), # type: ignore # Mocked out function call
|
||||
self.stripe_plan_id, self.quantity, 0)
|
||||
|
||||
def test_sign_string(self) -> None:
|
||||
string = "abc"
|
||||
|
|
Loading…
Reference in New Issue