mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
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.
This commit is contained in:
parent
822940b09e
commit
353755fd73
6 changed files with 292 additions and 0 deletions
|
|
@ -0,0 +1,45 @@
|
|||
"""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"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue