Files
django-lasuite/tests/marketing/test_handler.py
Manuel Raynaud 48094c2eb8 (marketing) create tooling to help backend initialization
Like we did for the malware_detection module, we want helpers allowing
use to instantiate a backend without knowing in the code how to do it,
just importing a module and the marketing service is ready to be used.
2025-12-08 15:03:18 +01:00

35 lines
1.0 KiB
Python

"""Test the marketing handler."""
import pytest
from django.core.exceptions import ImproperlyConfigured
from lasuite.marketing.backends.dummy import DummyBackend
from lasuite.marketing.handler import MarketingHandler
def test_marketing_handler_from_settings(settings):
"""Test the marketing handler from the settings."""
settings.LASUITE_MARKETING = {
"BACKEND": "lasuite.marketing.backends.dummy.DummyBackend",
}
handler = MarketingHandler()
assert isinstance(handler(), DummyBackend)
def test_marketing_handler_from_backend():
"""Test the marketing handler from the backend."""
handler = MarketingHandler(
backend={
"BACKEND": "lasuite.marketing.backends.dummy.DummyBackend",
}
)
assert isinstance(handler(), DummyBackend)
def test_marketing_backend_no_config(settings):
"""Test the marketing handler when no config set should raise an error."""
settings.LASUITE_MARKETING = None
handler = MarketingHandler()
with pytest.raises(ImproperlyConfigured):
handler()