mirror of https://github.com/zulip/zulip.git
90 lines
5.5 KiB
Python
90 lines
5.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import mock
|
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
class StripeHookTests(WebhookTestCase):
|
|
STREAM_NAME = 'test'
|
|
URL_TEMPLATE = "/api/v1/external/stripe?&api_key={api_key}&stream={stream}"
|
|
FIXTURE_DIR_NAME = 'stripe'
|
|
|
|
def test_charge_dispute_closed(self) -> None:
|
|
expected_topic = u"disputes"
|
|
expected_message = u"[Dispute](https://dashboard.stripe.com/disputes/dp_00000000000000) closed. Current status: won."
|
|
self.send_and_test_stream_message('charge_dispute_closed', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_charge_dispute_created(self) -> None:
|
|
expected_topic = u"disputes"
|
|
expected_message = u"[Dispute](https://dashboard.stripe.com/disputes/dp_00000000000000) created. Current status: needs response."
|
|
self.send_and_test_stream_message('charge_dispute_created', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_charge_failed(self) -> None:
|
|
expected_topic = u"charges"
|
|
expected_message = u"[Charge](https://dashboard.stripe.com/charges/ch_00000000000000) for 1.00 AUD failed"
|
|
self.send_and_test_stream_message('charge_failed', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_charge_succeeded(self) -> None:
|
|
expected_topic = u"charges"
|
|
expected_message = u"[Charge](https://dashboard.stripe.com/charges/ch_00000000000000) for 1.00 AUD succeeded"
|
|
self.send_and_test_stream_message('charge_succeeded', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_created(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) created"
|
|
self.send_and_test_stream_message('customer_created', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_created_email(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) created\nEmail: example@abc.com"
|
|
self.send_and_test_stream_message('customer_created_email', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_deleted(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) deleted"
|
|
self.send_and_test_stream_message('customer_deleted', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_subscription_created(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"""\
|
|
[Subscription](https://dashboard.stripe.com/subscriptions/sub_00000000000000) created
|
|
Plan: [Gold Special](https://dashboard.stripe.com/plans/gold_00000000000000)
|
|
Quantity: 1"""
|
|
self.send_and_test_stream_message('customer_subscription_created', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_subscription_deleted(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"[Subscription](https://dashboard.stripe.com/subscriptions/sub_00000000000000) deleted"
|
|
self.send_and_test_stream_message('customer_subscription_deleted', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_subscription_trial_will_end(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"[Subscription](https://dashboard.stripe.com/subscriptions/sub_00000000000000) trial will end in 3 days"
|
|
# 3 days before the end of the trial, plus a little bit to make sure the rounding is working
|
|
with mock.patch('time.time', return_value=1480892861 - 3*3600*24 + 100):
|
|
# use fixture named stripe_customer_subscription_trial_will_end
|
|
self.send_and_test_stream_message('customer_subscription_trial_will_end',
|
|
expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_customer_discount_created(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"Discount created ([25.5% off](https://dashboard.stripe.com/coupons/25_00000000000000))."
|
|
self.send_and_test_stream_message('customer_discount_created', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_invoice_payment_failed(self) -> None:
|
|
expected_topic = u"cus_00000000000000"
|
|
expected_message = u"[Invoice](https://dashboard.stripe.com/invoices/in_00000000000000) payment failed"
|
|
self.send_and_test_stream_message('invoice_payment_failed', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|