12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- from datetime import timedelta
- from django.core import mail
- from django.test import TestCase
- from django.utils import timezone
- from freezegun import freeze_time
- from model_bakery import baker
- from ..tasks import warn_organization_throttle
- class OrganizationWarnThrottlingTestCase(TestCase):
- def test_warn_organization_throttle(self):
- user = baker.make("users.User")
- project = baker.make(
- "projects.Project",
- organization__owner__organization_user__user=user,
- )
- plan = baker.make(
- "djstripe.Plan",
- active=True,
- amount=0,
- product__metadata={"events": "10"},
- )
- baker.make(
- "projects.Project",
- organization__owner__organization_user__user=user,
- organization__djstripe_customers__subscriptions__plan=plan,
- )
- with freeze_time(timezone.datetime(2000, 1, 1)):
- subscription = baker.make(
- "djstripe.Subscription",
- customer__subscriber=project.organization,
- livemode=False,
- plan=plan,
- status="active",
- )
- subscription.current_period_end = (
- subscription.current_period_start + timedelta(days=30)
- )
- subscription.save()
- baker.make("issue_events.IssueEvent", issue__project=project, _quantity=9)
- baker.make(
- "projects.IssueEventProjectHourlyStatistic",
- project=project,
- count=9,
- )
- warn_organization_throttle()
- self.assertEqual(len(mail.outbox), 1)
- warn_organization_throttle()
- self.assertEqual(len(mail.outbox), 1)
- with freeze_time(timezone.datetime(2000, 2, 2)):
- subscription.current_period_start = timezone.make_aware(
- timezone.datetime(2000, 2, 1)
- )
- subscription.current_period_end = (
- subscription.current_period_start + timedelta(days=30)
- )
- subscription.save()
- warn_organization_throttle()
- self.assertEqual(len(mail.outbox), 1)
- baker.make("issue_events.IssueEvent", issue__project=project, _quantity=9)
- baker.make(
- "projects.IssueEventProjectHourlyStatistic",
- project=project,
- count=9,
- )
- warn_organization_throttle()
- self.assertEqual(len(mail.outbox), 2)
|