import pytest from django.test import override_settings from apps.accounts.models import OtpChannel from apps.accounts.services.otp import OtpRateLimitError, create_and_send_otp @pytest.mark.django_db @override_settings(OTP_MAX_PER_WINDOW=1, OTP_WINDOW_MINUTES=15, OTP_RESEND_COOLDOWN_SECONDS=0) def test_otp_rate_limit(): create_and_send_otp("+966512345678", OtpChannel.SMS) with pytest.raises(OtpRateLimitError): create_and_send_otp("+966512345678", OtpChannel.SMS)