mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
billing: Add randomness to idempotency key while testing.
Makes it easier to test or regenerate fixtures for test_billing_quantity_changes_end_to_end with generate=True.
This commit is contained in:
@@ -356,6 +356,8 @@ def process_billing_log_entry(processor: BillingProcessor, log_row: RealmAuditLo
|
|||||||
customer = Customer.objects.get(realm=log_row.realm)
|
customer = Customer.objects.get(realm=log_row.realm)
|
||||||
timestamp = datetime_to_timestamp(log_row.event_time)
|
timestamp = datetime_to_timestamp(log_row.event_time)
|
||||||
idempotency_key = 'process_billing_log_entry:%s' % (log_row.id,)
|
idempotency_key = 'process_billing_log_entry:%s' % (log_row.id,)
|
||||||
|
if settings.TEST_SUITE:
|
||||||
|
idempotency_key += '+' + generate_random_token(10)
|
||||||
extra_args = {} # type: Dict[str, Any]
|
extra_args = {} # type: Dict[str, Any]
|
||||||
if log_row.extra_data is not None:
|
if log_row.extra_data is not None:
|
||||||
extra_args = ujson.loads(log_row.extra_data)
|
extra_args = ujson.loads(log_row.extra_data)
|
||||||
|
|||||||
@@ -795,7 +795,8 @@ class StripeTest(ZulipTestCase):
|
|||||||
self.assertEqual(subscription.quantity, quantity)
|
self.assertEqual(subscription.quantity, quantity)
|
||||||
log_row = RealmAuditLog.objects.filter(
|
log_row = RealmAuditLog.objects.filter(
|
||||||
event_type=event_type, requires_billing_update=True).order_by('-id').first()
|
event_type=event_type, requires_billing_update=True).order_by('-id').first()
|
||||||
self.assertEqual(idempotency_key, 'process_billing_log_entry:%s' % (log_row.id,))
|
self.assertEqual(idempotency_key.split('+')[0],
|
||||||
|
'process_billing_log_entry:%s' % (log_row.id,))
|
||||||
self.assertEqual(subscription.proration_date, datetime_to_timestamp(log_row.event_time))
|
self.assertEqual(subscription.proration_date, datetime_to_timestamp(log_row.event_time))
|
||||||
with patch.object(stripe.Subscription, 'save', autospec=True,
|
with patch.object(stripe.Subscription, 'save', autospec=True,
|
||||||
side_effect=check_subscription_save):
|
side_effect=check_subscription_save):
|
||||||
|
|||||||
Reference in New Issue
Block a user