feat: Add email settings management and templates functionality
- Implemented email settings configuration in the admin panel, allowing for SMTP settings and notification preferences. - Created a new template for email settings with fields for SMTP host, port, username, password, sender address, and recipients. - Added JavaScript functionality to handle loading, saving, and validating email settings. - Introduced email templates management, enabling the listing, editing, and saving of email templates. - Updated navigation to include links to email settings and templates. - Added tests for email settings and templates to ensure proper functionality and validation.
This commit is contained in:
44
tests/test_email_templates_service.py
Normal file
44
tests/test_email_templates_service.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from server.services import email_templates
|
||||
|
||||
|
||||
def test_list_templates_returns_metadata():
|
||||
templates = email_templates.list_templates()
|
||||
assert isinstance(templates, list)
|
||||
assert templates[0]["id"] == "newsletter_confirmation"
|
||||
assert "name" in templates[0]
|
||||
|
||||
|
||||
def test_load_template_uses_default_when_not_stored(monkeypatch):
|
||||
monkeypatch.setattr(email_templates, "get_app_settings", lambda: {})
|
||||
template = email_templates.load_template("newsletter_confirmation")
|
||||
assert template["content"] == email_templates.EMAIL_TEMPLATE_DEFINITIONS[
|
||||
"newsletter_confirmation"
|
||||
].default_content
|
||||
|
||||
|
||||
def test_persist_template_updates_storage(monkeypatch):
|
||||
captured: dict[str, Any] = {}
|
||||
|
||||
def fake_update(key: str, value: str) -> None:
|
||||
captured["key"] = key
|
||||
captured["value"] = value
|
||||
|
||||
# Return content via load call after persist
|
||||
monkeypatch.setattr(email_templates, "update_app_setting", fake_update)
|
||||
monkeypatch.setattr(
|
||||
email_templates,
|
||||
"get_app_settings",
|
||||
lambda: {"newsletter_confirmation_template": "stored"},
|
||||
)
|
||||
|
||||
updated = email_templates.persist_template(
|
||||
"newsletter_confirmation", " stored ")
|
||||
assert captured["key"] == "newsletter_confirmation_template"
|
||||
assert captured["value"] == "stored"
|
||||
assert updated["content"] == "stored"
|
||||
Reference in New Issue
Block a user