6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
"""Unit tests for pure notification metadata transitions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app.notifications.service.metadata import apply_update, start_metadata
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
class TestStartMetadata:
|
|
def test_seeds_operation_and_progress_fields(self):
|
|
"""A new notification is seeded with operation id, in-progress status, and start time."""
|
|
meta = start_metadata("op-1")
|
|
assert meta["operation_id"] == "op-1"
|
|
assert meta["status"] == "in_progress"
|
|
assert "started_at" in meta
|
|
|
|
def test_preserves_initial_fields(self):
|
|
"""Caller-provided initial metadata is carried through."""
|
|
meta = start_metadata("op-1", {"connector_id": 7})
|
|
assert meta["connector_id"] == 7
|
|
|
|
def test_does_not_mutate_caller_dict(self):
|
|
"""Seeding returns a new dict without mutating the caller's input."""
|
|
initial = {"connector_id": 7}
|
|
start_metadata("op-1", initial)
|
|
assert initial == {"connector_id": 7}
|
|
|
|
|
|
class TestApplyUpdate:
|
|
def test_completed_stamps_completed_at(self):
|
|
"""A completed status records a completion timestamp."""
|
|
meta = apply_update({"status": "in_progress"}, status="completed")
|
|
assert meta["status"] == "completed"
|
|
assert "completed_at" in meta
|
|
|
|
def test_failed_stamps_completed_at(self):
|
|
"""A failed status also records a completion timestamp."""
|
|
meta = apply_update({}, status="failed")
|
|
assert "completed_at" in meta
|
|
|
|
def test_in_progress_does_not_stamp_completed_at(self):
|
|
"""A non-terminal status leaves the completion timestamp unset."""
|
|
meta = apply_update({}, status="in_progress")
|
|
assert "completed_at" not in meta
|
|
|
|
def test_merges_metadata_updates(self):
|
|
"""Metadata updates are merged into the existing metadata."""
|
|
meta = apply_update({"a": 1}, metadata_updates={"b": 2})
|
|
assert meta == {"a": 1, "b": 2}
|
|
|
|
def test_updates_override_existing_keys(self):
|
|
"""Updates take precedence over existing keys on conflict."""
|
|
meta = apply_update({"a": 1}, metadata_updates={"a": 9})
|
|
assert meta["a"] == 9
|
|
|
|
def test_does_not_mutate_caller_dict(self):
|
|
"""Applying updates returns a new dict without mutating the caller's input."""
|
|
current = {"a": 1}
|
|
apply_update(current, status="completed", metadata_updates={"b": 2})
|
|
assert current == {"a": 1}
|