From 80c482428d5f2c9bcc299a18a434682355b72e4e Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Thu, 18 Oct 2018 10:08:05 -0700 Subject: [PATCH] billing: Update test_upgrade_with_outdated_seat_count to use @mock_stripe. --- ...outdated_seat_count:Customer.create.1.json | Bin 0 -> 1583 bytes ...tdated_seat_count:Customer.retrieve.1.json | Bin 0 -> 4850 bytes ...ated_seat_count:Subscription.create.1.json | Bin 0 -> 2134 bytes ...th_outdated_seat_count:Token.create.1.json | Bin 0 -> 834 bytes corporate/tests/test_stripe.py | 35 +++++++++--------- 5 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 corporate/tests/stripe_fixtures/upgrade_with_outdated_seat_count:Customer.create.1.json create mode 100644 corporate/tests/stripe_fixtures/upgrade_with_outdated_seat_count:Customer.retrieve.1.json create mode 100644 corporate/tests/stripe_fixtures/upgrade_with_outdated_seat_count:Subscription.create.1.json create mode 100644 corporate/tests/stripe_fixtures/upgrade_with_outdated_seat_count:Token.create.1.json diff --git a/corporate/tests/stripe_fixtures/upgrade_with_outdated_seat_count:Customer.create.1.json b/corporate/tests/stripe_fixtures/upgrade_with_outdated_seat_count:Customer.create.1.json new file mode 100644 index 0000000000000000000000000000000000000000..a6f9f917d4ac1866c6f554a9c684e0e9f8e8e5d6 GIT binary patch literal 1583 zcmb_cO>Yx15WVv&Rz87L(QLkGI8jIi5-Or9t*RnqIrc2;)@yHV@3v{x|BlD&O*ha8 z4&;(##xwKg&6|06k!6H&ZW`_BiYcZ!khj@r5AECn^B}_id^TAe9E>NkdFN=X1mt+*JB@K3kj|FE8GZ6r`lSX+Zmss$j}N zGCOW%?WNJdPVO5e>+I!a{8~c$Dg{dyaSu^I#iYWRl2r=)yBPYKo2mxq1=1m2*tLI8t*HZrso(;<#yY8u4s{K9I&Ju=* zg9%~5Im)HSL6NVF%R=&mX!{9{-^N#GT85Elr#?*HJ@+;Y406nOrUlr{mykJNdpn;} zUIM?yfSS3T8OPy4-y}jqRVMrnq3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Im}U(JMYh>!zQGAnXJ8W(cSy-<`WDma^nm9eKWf;PXMQh1 z?cfwd+z;mUIGH8O%cN6?1s$-`mvAPH+QHowWxg#WZMMJKt^V9CmUreuFHKplcOZR@ zl7k*!rHvN403_0r<*DzXReVdpk%1sICD=~|RqLRX!_zx`9Yz+W(pf8Xp1NwD{%7cI zzMOyL_S1E-@7A$`Yp=e>_${=sKx^c~RSn9lbDbR@uGIo$<56#-u~ULHs4a^yW4x5O zGHCf$)v-!{IY1X$KgwA5v1D;+%x87E$MF55;)-m+V0*eZ7;+$13e%{K*xX_>y$KVi zgC@>*$$5-|21~z;Loe{5?|wuR+9P8UAp>bd$l}UjoTOt-GGfY;b|f$~V)F(#Zow1g z!^_lP(S6(f({MzLTdj=`Mli-5+GoJtDN9AnMrI=aWg{{)P!$?lhu9OQ!NpT{!Mh9Z x&{3mQ8tR*a9C_nm*g9{;MkL-1#KJ!M6EJ-mF5?$He)-mmEA73T@Z=?-AGGoF;RD1xa4i{_Mxgbi__UA$gjEvB_VP__0olQrXPG@gWmoI|S{Zs2exvLaHU|wU)|~ zrM|eG&j!ygo2@SUz5B<;$)ZxiF^R%83Tc~y^hs#lX*e9=79O(hT`_+z)VALnOh&`` zRYPrjvLs5P1}xBm01Hle|8;QcV$r3uTLJU}v~I}d>l None: + @mock_stripe("stripe.Token.create") + @mock_stripe("stripe.Customer.create") + @mock_stripe("stripe.Subscription.create") + @mock_stripe("stripe.Customer.retrieve") + def test_upgrade_with_outdated_seat_count( + self, mock4: Mock, mock3: Mock, mock2: Mock, mock1: Mock) -> None: self.login(self.example_email("hamlet")) new_seat_count = 123 # Change the seat count while the user is going through the upgrade flow response = self.client_get("/upgrade/") with patch('corporate.lib.stripe.get_seat_count', return_value=new_seat_count): self.client_post("/upgrade/", { - 'stripeToken': self.token, + 'stripeToken': stripe_create_token().id, 'signed_seat_count': self.get_signed_seat_count_from_response(response), 'salt': self.get_salt_from_response(response), 'plan': Plan.CLOUD_ANNUAL}) # Check that the subscription call used the old quantity, not new_seat_count - mock_create_subscription.assert_called_once_with( - customer=self.stripe_customer_id, - billing='charge_automatically', - items=[{ - 'plan': self.stripe_plan_id, - 'quantity': self.quantity, - }], - prorate=True, - tax_percent=0) + stripe_customer = stripe_get_customer( + Customer.objects.get(realm=get_realm('zulip')).stripe_customer_id) + stripe_subscription = extract_current_subscription(stripe_customer) + self.assertEqual(stripe_subscription.quantity, self.quantity) + # Check that we have the STRIPE_PLAN_QUANTITY_RESET entry, and that we # correctly handled the requires_billing_update field audit_log_entries = list(RealmAuditLog.objects.order_by('-id') .values_list('event_type', 'event_time', 'requires_billing_update')[:5])[::-1] self.assertEqual(audit_log_entries, [ - (RealmAuditLog.STRIPE_CUSTOMER_CREATED, timestamp_to_datetime(self.customer_created), False), - (RealmAuditLog.STRIPE_CARD_CHANGED, timestamp_to_datetime(self.customer_created), False), - (RealmAuditLog.STRIPE_PLAN_CHANGED, timestamp_to_datetime(self.subscription_created), False), - (RealmAuditLog.STRIPE_PLAN_QUANTITY_RESET, timestamp_to_datetime(self.subscription_created), True), + (RealmAuditLog.STRIPE_CUSTOMER_CREATED, timestamp_to_datetime(stripe_customer.created), False), + (RealmAuditLog.STRIPE_CARD_CHANGED, timestamp_to_datetime(stripe_customer.created), False), + # TODO: Ideally this test would force stripe_customer.created != stripe_subscription.created + (RealmAuditLog.STRIPE_PLAN_CHANGED, timestamp_to_datetime(stripe_subscription.created), False), + (RealmAuditLog.STRIPE_PLAN_QUANTITY_RESET, timestamp_to_datetime(stripe_subscription.created), True), (RealmAuditLog.REALM_PLAN_TYPE_CHANGED, Kandra(), False), ]) self.assertEqual(ujson.loads(RealmAuditLog.objects.filter(