test_notification_template_sample_data.py 1.2 KB

1234567891011121314151617181920212223242526
  1. """Every event_type in EVENT_VARIABLES needs a matching SAMPLE_DATA entry.
  2. Regression: location_ha_sensor_alert (#2824) was added to EVENT_VARIABLES but
  3. never given a SAMPLE_DATA entry. The template preview endpoint falls back to
  4. an empty sample dict for an event type it has no data for, so every
  5. {placeholder} in the template silently disappears — "{location}: {sensor} is
  6. {state}" rendered as just ": is " with nothing to say what did what.
  7. """
  8. from backend.app.schemas.notification_template import EVENT_VARIABLES, SAMPLE_DATA
  9. def test_every_event_type_has_sample_data():
  10. missing = sorted(set(EVENT_VARIABLES) - set(SAMPLE_DATA))
  11. assert missing == [], f"EVENT_VARIABLES entries with no SAMPLE_DATA: {missing}"
  12. def test_sample_data_covers_every_variable_its_event_type_declares():
  13. # A partial sample (declared variable missing a sample value) produces
  14. # the same silent-blank symptom as a missing sample entirely.
  15. incomplete = {
  16. event_type: sorted(set(variables) - set(SAMPLE_DATA.get(event_type, {})))
  17. for event_type, variables in EVENT_VARIABLES.items()
  18. }
  19. incomplete = {k: v for k, v in incomplete.items() if v}
  20. assert incomplete == {}, f"Event types with variables missing from their sample data: {incomplete}"