mirror of https://github.com/zulip/zulip.git
billing: Add mock and test for extracting canceled subscription.
This commit is contained in:
parent
84b148728f
commit
d89e07b8a7
|
@ -15,12 +15,14 @@ class Customer:
|
|||
@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:
|
||||
...
|
||||
|
@ -28,6 +30,8 @@ class Invoice:
|
|||
class Subscription:
|
||||
created: int
|
||||
status: str
|
||||
canceled_at: int
|
||||
|
||||
@staticmethod
|
||||
def create(customer: str, billing: str, items: List[Dict[str, Any]],
|
||||
prorate: bool, tax_percent: float) -> Subscription:
|
||||
|
@ -38,6 +42,7 @@ class Card:
|
|||
|
||||
class Plan:
|
||||
id: str
|
||||
|
||||
@staticmethod
|
||||
def create(currency: str, interval: str, product: str, amount: int,
|
||||
billing_scheme: str, nickname: str, usage_type: str) -> Plan:
|
||||
|
|
|
@ -29,6 +29,12 @@ def mock_create_subscription(*args: Any, **kwargs: Any) -> stripe.Subscription:
|
|||
def mock_customer_with_active_subscription(*args: Any, **kwargs: Any) -> stripe.Customer:
|
||||
return stripe.util.convert_to_stripe_object(fixture_data["customer_with_active_subscription"])
|
||||
|
||||
def mock_customer_with_canceled_subscription(*args: Any, **kwargs: Any) -> stripe.Customer:
|
||||
customer = mock_customer_with_active_subscription()
|
||||
customer.subscriptions.data[0].status = "canceled"
|
||||
customer.subscriptions.data[0].canceled_at = 1532602160
|
||||
return customer
|
||||
|
||||
def mock_upcoming_invoice(*args: Any, **kwargs: Any) -> stripe.Invoice:
|
||||
return stripe.util.convert_to_stripe_object(fixture_data["upcoming_invoice"])
|
||||
|
||||
|
@ -245,12 +251,10 @@ class StripeTest(ZulipTestCase):
|
|||
self.assertEqual(get_seat_count(realm), initial_count)
|
||||
|
||||
def test_extract_current_subscription(self) -> 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.
|
||||
self.assertIsNone(extract_current_subscription(mock_create_customer()))
|
||||
|
||||
subscription = extract_current_subscription(mock_customer_with_active_subscription())
|
||||
self.assertEqual(subscription["id"][:4], "sub_")
|
||||
self.assertIsNone(extract_current_subscription(mock_customer_with_canceled_subscription()))
|
||||
|
||||
@mock.patch("stripe.Customer.retrieve", side_effect=mock_customer_with_active_subscription)
|
||||
def test_subscribe_customer_to_second_plan(self, mock_customer_with_active_subscription: mock.Mock) -> None:
|
||||
|
|
Loading…
Reference in New Issue