test_stripe: Keep same context after seat_count change during upgrade.

We need to emulate seat_count change after we rendered
the upgrade page. To do that, we need to render the upgrade
page with old seat count.
This commit is contained in:
Aman Agrawal 2023-12-02 05:07:57 +00:00 committed by Tim Abbott
parent 36532e9180
commit 785444b2b8
22 changed files with 14 additions and 1 deletions

View File

@ -45,6 +45,7 @@ from corporate.lib.stripe import (
AuditLogEventType,
BillingError,
BillingSessionAuditLogEventError,
InitialUpgradeRequest,
InvalidBillingScheduleError,
InvalidTierError,
RealmBillingSession,
@ -1401,8 +1402,20 @@ class StripeTest(StripeTestCase):
hamlet = self.example_user("hamlet")
self.login_user(hamlet)
new_seat_count = 23
initial_upgrade_request = InitialUpgradeRequest(
manual_license_management=False,
tier=CustomerPlan.TIER_CLOUD_STANDARD,
)
billing_session = RealmBillingSession(hamlet)
_, context_when_upgrade_page_is_rendered = billing_session.get_initial_upgrade_context(
initial_upgrade_request
)
# Change the seat count while the user is going through the upgrade flow
with patch("corporate.lib.stripe.get_latest_seat_count", return_value=new_seat_count):
with patch(
"corporate.lib.stripe.RealmBillingSession.get_initial_upgrade_context",
return_value=(_, context_when_upgrade_page_is_rendered),
):
self.add_card_and_upgrade(hamlet)
customer = Customer.objects.first()