Skip to content

Commit

Permalink
chore: add test of ExponentialRateLimitBackends without rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
shenek committed Feb 13, 2024
1 parent 7b3ae3b commit 5c49adb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_exponential_ratelimit_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,40 @@ def hook(self, email_messages):
check(False, '')
check(False, '')
check(True, ' (8)')


def test_no_exponential_rate_limit(
settings, use_exponential_ratelimit_backends, monkeypatch, clear_cache
):
settings.EMAIL_EXPONENTIAL_RATE_LIMIT_TIMEOUT = 0
settings.EMAIL_EXPONENTIAL_RATE_LIMIT_BACKENDS = [
'django.core.mail.backends.smtp.EmailBackend',
'django_ntfy.NtfyBackend',
]

for _i in range(20):
tmp = {"called": False}

def hook(self, email_messages):
assert len(email_messages) == 1
assert email_messages[0].subject == "Sub"
tmp["called"] = True
return 1

with monkeypatch.context() as m, responses.RequestsMock() as rsps:
m.setattr(EmailBackend, 'send_messages', hook)
rsps.post(
settings.NTFY_BASE_URL,
status=200,
match=[
matchers.json_params_matcher(
{
"message": "Body",
"title": "Sub",
"topic": "django-ntfy",
}
),
],
)
assert mail.send_mail("Sub", "Body", "[email protected]", ["[email protected]"]) == 2
assert tmp["called"] is True

0 comments on commit 5c49adb

Please sign in to comment.