Stripe webhook should skip check subscription throttle cache
This commit is contained in:
1 parent
e32c2580c9
commit
2cca440d1e
3 files changed
+13
-3
No files matched your search
@@ -6,8 +6,8 @@ from .models import Organization
|
||||
|
||||
|
||||
@shared_task
|
||||
def check_organization_throttle(organization_id: int):
|
||||
if not cache.add(f"org-throttle-{organization_id}", True):
|
||||
def check_organization_throttle(organization_id: int, bypass_cache: bool = False):
|
||||
if not bypass_cache and not cache.add(f"org-throttle-{organization_id}", True):
|
||||
return # Recent check already performed
|
||||
|
||||
org = (
|
||||
|
||||
@@ -2,6 +2,7 @@ from datetime import timedelta
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from django.core import mail
|
||||
from django.core.cache import cache
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils import timezone
|
||||
from freezegun import freeze_time
|
||||
@@ -76,6 +77,15 @@ class OrganizationThrottleCheckTestCase(TestCase):
|
||||
self.assertEqual(self.organization.event_throttle_rate, 100)
|
||||
self.assertEqual(len(mail.outbox), 2)
|
||||
|
||||
def test_bypass_organization_throttle(self):
|
||||
"""Ensure bypassing the check org throttle cache works"""
|
||||
check_organization_throttle(self.organization.id)
|
||||
self.assertTrue(cache.get(f"org-throttle-{self.organization.id}"))
|
||||
cache.clear()
|
||||
check_organization_throttle(self.organization.id, True)
|
||||
self.assertFalse(cache.get(f"org-throttle-{self.organization.id}"))
|
||||
cache.clear()
|
||||
|
||||
def test_check_all_organizations_throttle(self):
|
||||
org = self.organization
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ async def update_subscription(subscription: Subscription, request: HttpRequest):
|
||||
):
|
||||
organization.stripe_primary_subscription = primary_subscription
|
||||
await organization.asave(update_fields=["stripe_primary_subscription"])
|
||||
await async_call_celery_task(check_organization_throttle, organization.id)
|
||||
await async_call_celery_task(check_organization_throttle, organization.id, True)
|
||||
|
||||
# Primary subscription should be removed if status is not active
|
||||
elif stripe_subscription.stripe_id is organization.stripe_primary_subscription_id:
|
||||
|
||||
Reference in new issue
Block a user