billing: Add mypy stubs to stripe imports.

Tweaked by tabbott to add an extra type: ignore.
This commit is contained in:
Vishnu Ks 2018-07-24 18:46:50 +05:30 committed by Tim Abbott
parent 38dd9e49de
commit abf485bfcb
7 changed files with 69 additions and 7 deletions

View File

@ -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

50
stubs/stripe/__init__.pyi Normal file
View File

@ -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:
...

View File

View File

@ -0,0 +1,2 @@
class ListObject:
...

View File

@ -0,0 +1,8 @@
class StripeError(Exception):
http_status: str
class CardError(Exception):
http_status: str
class InvalidRequestError(Exception):
...

View File

@ -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:
...

View File

@ -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"