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:
Rishi Gupta
2018-11-30 22:12:35 -08:00
parent 18e2118fc8
commit c9c842ae2b
2 changed files with 4 additions and 1 deletions

View File

@@ -356,6 +356,8 @@ def process_billing_log_entry(processor: BillingProcessor, log_row: RealmAuditLo
customer = Customer.objects.get(realm=log_row.realm)
timestamp = datetime_to_timestamp(log_row.event_time)
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]
if log_row.extra_data is not None:
extra_args = ujson.loads(log_row.extra_data)

View File

@@ -795,7 +795,8 @@ class StripeTest(ZulipTestCase):
self.assertEqual(subscription.quantity, quantity)
log_row = RealmAuditLog.objects.filter(
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))
with patch.object(stripe.Subscription, 'save', autospec=True,
side_effect=check_subscription_save):