From 5c49adb164f91acf15246fd62777e4244cedfd47 Mon Sep 17 00:00:00 2001 From: Stepan Henek Date: Tue, 13 Feb 2024 11:27:17 +0100 Subject: [PATCH] chore: add test of ExponentialRateLimitBackends without rate limit --- tests/test_exponential_ratelimit_backends.py | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_exponential_ratelimit_backends.py b/tests/test_exponential_ratelimit_backends.py index bafd2e6..8dd9da6 100644 --- a/tests/test_exponential_ratelimit_backends.py +++ b/tests/test_exponential_ratelimit_backends.py @@ -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", "from@example.com", ["to@example.com"]) == 2 + assert tmp["called"] is True