billing: Move zilencer/lib/stripe to corporate.

This commit is contained in:
Vishnu Ks
2018-09-25 16:03:30 +05:30
committed by Rishi Gupta
parent daf3b46262
commit 93b398bc0a
7 changed files with 15 additions and 15 deletions

View File

View File

@@ -28,7 +28,7 @@ BILLING_LOG_PATH = os.path.join('/var/log/zulip'
if not settings.DEVELOPMENT
else settings.DEVELOPMENT_LOG_DIRECTORY,
'billing.log')
billing_logger = logging.getLogger('zilencer.stripe')
billing_logger = logging.getLogger('corporate.stripe')
log_to_file(billing_logger, BILLING_LOG_PATH)
log_to_file(logging.getLogger('stripe'), BILLING_LOG_PATH)

View File

@@ -15,7 +15,7 @@ from zerver.lib.response import json_error, json_success
from zerver.lib.validator import check_string
from zerver.lib.timestamp import timestamp_to_datetime
from zerver.models import UserProfile, Realm
from zilencer.lib.stripe import STRIPE_PUBLISHABLE_KEY, \
from corporate.lib.stripe import STRIPE_PUBLISHABLE_KEY, \
stripe_get_customer, stripe_get_upcoming_invoice, get_seat_count, \
extract_current_subscription, process_initial_upgrade, sign_string, \
unsign_string, BillingError, process_downgrade, do_replace_payment_source

View File

@@ -18,7 +18,7 @@ Nearly all the billing-relevant code lives in `zilencer/`.
Notes:
* Anything that talks directly to Stripe should go in
`zilencer/lib/stripe.py`.
`corporate/lib/stripe.py`.
* We generally try to store billing-related data in Stripe, rather than in
Zulip database tables. We'd rather pay the penalty of making extra stripe
API requests than deal with keeping two sources of data in sync.

View File

@@ -29,7 +29,7 @@ target_fully_covered = {path for target in [
'zerver/*.py',
'zerver/lib/*.py',
# stripe.py handles billing
'zilencer/lib/stripe.py',
'corporate/lib/stripe.py',
# Test files should have 100% coverage; test code that isn't run
# is likely a bug in the test.
'zerver/tests/*.py',

View File

@@ -15,7 +15,7 @@ from django.core.management.base import BaseCommand
from zerver.lib.context_managers import lockfile
from zerver.lib.management import sleep_forever
from zilencer.lib.stripe import StripeConnectionError, \
from corporate.lib.stripe import StripeConnectionError, \
run_billing_processor_one_step
from zilencer.models import BillingProcessor

View File

@@ -16,7 +16,7 @@ from zerver.lib.actions import do_deactivate_user, do_create_user, \
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
from zerver.models import Realm, UserProfile, get_realm, RealmAuditLog
from zilencer.lib.stripe import catch_stripe_errors, \
from corporate.lib.stripe import catch_stripe_errors, \
do_subscribe_customer_to_plan, attach_discount_to_realm, \
get_seat_count, extract_current_subscription, sign_string, unsign_string, \
get_next_billing_log_entry, run_billing_processor_one_step, \
@@ -95,7 +95,7 @@ class StripeTest(ZulipTestCase):
match = re.search(r'name=\"salt\" value=\"(\w+)\"', response.content.decode("utf-8"))
return match.group(1) if match else None
@mock.patch("zilencer.lib.stripe.billing_logger.error")
@mock.patch("corporate.lib.stripe.billing_logger.error")
def test_catch_stripe_errors(self, mock_billing_logger_error: mock.Mock) -> None:
@catch_stripe_errors
def raise_invalid_request_error() -> None:
@@ -210,7 +210,7 @@ class StripeTest(ZulipTestCase):
new_seat_count = 123
# Change the seat count while the user is going through the upgrade flow
response = self.client_get("/upgrade/")
with mock.patch('zilencer.lib.stripe.get_seat_count', return_value=new_seat_count):
with mock.patch('corporate.lib.stripe.get_seat_count', return_value=new_seat_count):
self.client_post("/upgrade/", {
'stripeToken': self.token,
'signed_seat_count': self.get_signed_seat_count_from_response(response),
@@ -545,7 +545,7 @@ class StripeTest(ZulipTestCase):
# Test STRIPE_PLAN_QUANTITY_RESET
new_seat_count = 123
# change the seat count while the user is going through the upgrade flow
with mock.patch('zilencer.lib.stripe.get_seat_count', return_value=new_seat_count):
with mock.patch('corporate.lib.stripe.get_seat_count', return_value=new_seat_count):
self.client_post("/upgrade/", {'stripeToken': self.token,
'signed_seat_count': self.signed_seat_count,
'salt': self.salt,
@@ -682,14 +682,14 @@ class BillingProcessorTest(ZulipTestCase):
realm=second_realm, log_row=entry1, state=BillingProcessor.STARTED)
Customer.objects.create(realm=get_realm('zulip'), stripe_customer_id='cust_1')
Customer.objects.create(realm=second_realm, stripe_customer_id='cust_2')
with mock.patch('zilencer.lib.stripe.do_adjust_subscription_quantity'):
with mock.patch('corporate.lib.stripe.do_adjust_subscription_quantity'):
# test return values
self.assertTrue(run_billing_processor_one_step(processor))
self.assertTrue(run_billing_processor_one_step(realm_processor))
# test no processors get added or deleted
self.assertEqual(2, BillingProcessor.objects.count())
@mock.patch("zilencer.lib.stripe.billing_logger.error")
@mock.patch("corporate.lib.stripe.billing_logger.error")
def test_run_billing_processor_with_card_error(self, mock_billing_logger_error: mock.Mock) -> None:
second_realm = Realm.objects.create(string_id='second', name='second')
entry1 = self.add_log_entry(realm=second_realm)
@@ -699,7 +699,7 @@ class BillingProcessorTest(ZulipTestCase):
Customer.objects.create(realm=second_realm, stripe_customer_id='cust_2')
# card error on global processor should create a new realm processor
with mock.patch('zilencer.lib.stripe.do_adjust_subscription_quantity',
with mock.patch('corporate.lib.stripe.do_adjust_subscription_quantity',
side_effect=stripe.error.CardError('message', 'param', 'code', json_body={})):
self.assertTrue(run_billing_processor_one_step(processor))
self.assertEqual(2, BillingProcessor.objects.count())
@@ -713,7 +713,7 @@ class BillingProcessorTest(ZulipTestCase):
realm_processor = BillingProcessor.objects.filter(realm=second_realm).first()
realm_processor.state = BillingProcessor.STARTED
realm_processor.save()
with mock.patch('zilencer.lib.stripe.do_adjust_subscription_quantity',
with mock.patch('corporate.lib.stripe.do_adjust_subscription_quantity',
side_effect=stripe.error.CardError('message', 'param', 'code', json_body={})):
self.assertTrue(run_billing_processor_one_step(realm_processor))
self.assertEqual(2, BillingProcessor.objects.count())
@@ -721,7 +721,7 @@ class BillingProcessorTest(ZulipTestCase):
realm=second_realm, log_row=entry1, state=BillingProcessor.STALLED).exists())
mock_billing_logger_error.assert_called()
@mock.patch("zilencer.lib.stripe.billing_logger.error")
@mock.patch("corporate.lib.stripe.billing_logger.error")
def test_run_billing_processor_with_uncaught_error(self, mock_billing_logger_error: mock.Mock) -> None:
# This tests three different things:
# * That run_billing_processor_one_step passes through exceptions that
@@ -733,7 +733,7 @@ class BillingProcessorTest(ZulipTestCase):
processor = BillingProcessor.objects.create(
log_row=entry1, state=BillingProcessor.DONE)
Customer.objects.create(realm=get_realm('zulip'), stripe_customer_id='cust_1')
with mock.patch('zilencer.lib.stripe.do_adjust_subscription_quantity',
with mock.patch('corporate.lib.stripe.do_adjust_subscription_quantity',
side_effect=stripe.error.StripeError('message', 'param', 'code', json_body={})):
with self.assertRaises(BillingError):
run_billing_processor_one_step(processor)