Files
FabledScribe/tests/test_events_routes.py
T
bvandeusen b255a0f90e
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 1m14s
refactor: rename package fabledassistant -> scribe (code-only)
Renames src/fabledassistant -> src/scribe and all imports, plus the
default DB name and DB user/password (fabled -> scribe) in config +
compose. 952 refs / 154 files. Reverses the old 'internal name stays
fabledassistant' convention.

Code-only: live databases are still physically named 'fabledassistant'.
Deployed environments must set POSTGRES_DB / POSTGRES_USER (or rename the
DB) since the defaults now resolve to 'scribe'. Repo (FabledScribe), git
host (fabledsword), MCP (fabled-git) and the image name (fabledscribe)
are intentionally unchanged.

ruff check src/ clean locally; CI (typecheck + pytest) is the gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 15:48:35 -04:00

68 lines
2.6 KiB
Python

"""Route-level tests for the events blueprint.
Full HTTP integration tests require a live DB (not available in unit test
environment). These tests cover structural correctness and the route
module's public interface; ownership enforcement is covered by the service
tests in test_events_service.py.
"""
def test_events_blueprint_registered():
"""events_bp must be importable and have the correct name."""
from scribe.routes.events import events_bp
assert events_bp.name == "events"
assert events_bp.url_prefix == "/api/events"
def test_events_blueprint_has_five_routes():
"""Blueprint must declare routes for GET/POST '' and GET/PATCH/DELETE '/<id>'."""
from scribe.routes.events import events_bp
methods_by_rule: dict[str, set[str]] = {}
for rule in events_bp.deferred_functions:
pass # deferred; inspect via url_map after binding
# Import routes module to confirm all 5 view functions exist
from scribe.routes import events as events_module
assert callable(events_module.list_events)
assert callable(events_module.create_event)
assert callable(events_module.get_event)
assert callable(events_module.update_event)
assert callable(events_module.delete_event)
def test_events_blueprint_registered_in_app():
"""events_bp must be registered in the app factory."""
from scribe.app import create_app
app = create_app()
# Check the blueprint is present in the app's blueprints dict
assert "events" in app.blueprints
def test_events_service_ownership_enforced_on_get():
"""get_event returns None for a different user — route will 404."""
# Ownership is enforced by the service filtering by user_id.
# The service returns None when the event belongs to a different user,
# and the route converts that to a 404 response.
import inspect
from scribe.services import events as events_svc
sig = inspect.signature(events_svc.get_event)
assert "user_id" in sig.parameters
assert "event_id" in sig.parameters
def test_events_service_ownership_enforced_on_update():
"""update_event takes user_id — route passes current user's id."""
import inspect
from scribe.services import events as events_svc
sig = inspect.signature(events_svc.update_event)
assert "user_id" in sig.parameters
assert "event_id" in sig.parameters
def test_events_service_ownership_enforced_on_delete():
"""delete_event takes user_id — route verifies ownership before deleting."""
import inspect
from scribe.services import events as events_svc
sig = inspect.signature(events_svc.delete_event)
assert "user_id" in sig.parameters
assert "event_id" in sig.parameters