SurfSense/surfsense_backend/tests/unit/automations/test_persistence_enums.py
CREDO23 353755fd73 test(automations): cross-cutting registries, enums, side-effects + shared fixtures
Top-level tests that span multiple submodules:

- test_stores.py (7): the trigger + action registry contracts — register
  round-trip, unknown type → None (not raise), duplicate registration
  rejected, defensive snapshot from all_*.
- test_definition_types.py (2): params_schema property on both
  ActionDefinition and TriggerDefinition reflects the Pydantic model.
- test_persistence_enums.py (3): exact string values + member sets of
  AutomationStatus / RunStatus / TriggerType — the postgres-mirrored
  contract that breaks stored rows if drifted.
- test_import_registrations.py (2): the bundled agent_task action and
  schedule trigger self-register on package import (canary for the
  side-effect import chain).

conftest.py adds isolated_action_registry / isolated_trigger_registry
fixtures: snapshot + restore of the module-level _REGISTRY dicts so
tests that add their own definitions don't leak across the suite.

14 tests, pure unit.
2026-05-28 19:03:55 +02:00

45 lines
1.5 KiB
Python

"""Lock the persistence enum string values + members.
These enums are mirrored by Postgres enum types, embedded in stored DB
rows, and surfaced in the JSON API. Renaming a value (or removing a
member) silently breaks production data and previously-issued API
responses, so the strings + the set of members are the contract.
"""
from __future__ import annotations
import pytest
from app.automations.persistence.enums.automation_status import AutomationStatus
from app.automations.persistence.enums.run_status import RunStatus
from app.automations.persistence.enums.trigger_type import TriggerType
pytestmark = pytest.mark.unit
def test_automation_status_string_values_are_stable() -> None:
"""The exact strings persisted to Postgres and served in API JSON."""
assert {member.value for member in AutomationStatus} == {
"active",
"paused",
"archived",
}
def test_run_status_string_values_are_stable() -> None:
"""Run lifecycle states embedded in the ``automation_runs`` table."""
assert {member.value for member in RunStatus} == {
"pending",
"running",
"succeeded",
"failed",
"cancelled",
"timed_out",
}
def test_trigger_type_keeps_manual_member_even_though_unregistered() -> None:
"""``MANUAL`` is reserved (mirrors the Postgres enum) but the trigger
store does not register it in v1. The enum must keep both members so
existing DB rows and the schema migration plan stay valid."""
assert {member.value for member in TriggerType} == {"schedule", "manual"}