Files
evo-sync/tests/test_notifications.py

48 lines
1.8 KiB
Python
Raw Permalink Normal View History

import logging
import pytest
from web.notifications.console import ConsoleEmailProvider, ConsoleSMSProvider
from web.notifications.registry import get_email_provider, get_sms_provider
def test_console_email_logs(caplog):
provider = ConsoleEmailProvider()
with caplog.at_level(logging.INFO, logger="web.notifications.console"):
provider.send("user@example.com", "Тест", '<a href="http://example.com/link">click</a>')
assert "user@example.com" in caplog.text
assert "Тест" in caplog.text
assert "http://example.com/link" in caplog.text
def test_console_sms_logs(caplog):
provider = ConsoleSMSProvider()
with caplog.at_level(logging.INFO, logger="web.notifications.console"):
provider.send("+79001234567", "Ваш код: 1234")
assert "+79001234567" in caplog.text
assert "Ваш код: 1234" in caplog.text
def test_registry_returns_console_email(monkeypatch):
monkeypatch.setattr("web.notifications.registry.settings.EMAIL_PROVIDER", "console")
provider = get_email_provider()
assert isinstance(provider, ConsoleEmailProvider)
def test_registry_returns_console_sms(monkeypatch):
monkeypatch.setattr("web.notifications.registry.settings.SMS_PROVIDER", "console")
provider = get_sms_provider()
assert isinstance(provider, ConsoleSMSProvider)
def test_registry_unknown_email_provider_raises(monkeypatch):
monkeypatch.setattr("web.notifications.registry.settings.EMAIL_PROVIDER", "sendgrid")
with pytest.raises(ValueError, match="sendgrid"):
get_email_provider()
def test_registry_unknown_sms_provider_raises(monkeypatch):
monkeypatch.setattr("web.notifications.registry.settings.SMS_PROVIDER", "twilio")
with pytest.raises(ValueError, match="twilio"):
get_sms_provider()