test_notification_template_editor_events.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Every notification event can be edited with its variables and a preview (CE-7).
  2. The print outcome confirmation (#1898) had no entry in the editor's variable
  3. list, sample data or names: the editor listed no variables for it and the
  4. preview left {printer}, {filename} and {confirm_url} empty. Seven other
  5. events had no display name.
  6. """
  7. import pytest
  8. from httpx import AsyncClient
  9. from backend.app.api.routes.notification_templates import EVENT_NAMES
  10. from backend.app.models.notification_template import DEFAULT_TEMPLATES
  11. from backend.app.schemas.notification_template import EVENT_VARIABLES, SAMPLE_DATA
  12. pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
  13. SEEDED = sorted({t["event_type"] for t in DEFAULT_TEMPLATES})
  14. @pytest.mark.parametrize("event_type", SEEDED)
  15. async def test_each_seeded_event_has_variables_samples_and_a_name(event_type):
  16. assert event_type in EVENT_VARIABLES
  17. assert set(EVENT_VARIABLES[event_type]) <= set(SAMPLE_DATA[event_type])
  18. assert event_type in EVENT_NAMES
  19. async def test_the_confirmation_request_previews_its_link(async_client: AsyncClient):
  20. template = next(t for t in DEFAULT_TEMPLATES if t["event_type"] == "print_confirm_request")
  21. response = await async_client.post(
  22. "/api/v1/notification-templates/preview",
  23. json={
  24. "event_type": "print_confirm_request",
  25. "title_template": template["title_template"],
  26. "body_template": template["body_template"],
  27. },
  28. )
  29. assert response.status_code == 200
  30. body = response.json()["body"]
  31. assert SAMPLE_DATA["print_confirm_request"]["printer"] in body
  32. assert SAMPLE_DATA["print_confirm_request"]["confirm_url"] in body