from __future__ import annotations import os import pytest # Set before anything imports poorbird.config, whose Settings are cached. os.environ.setdefault("POORBIRD_LOG_LEVEL", "WARNING") os.environ.setdefault("POORBIRD_IMAGE_ROOT", "/tmp/poorbird-test/images") os.environ.setdefault("POORBIRD_THUMB_ROOT", "/tmp/poorbird-test/thumbs") os.environ.setdefault("POORBIRD_STATE_DIR", "/tmp/poorbird-test/state") # Off by default: the suite fires far more requests at an endpoint than any # camera would, and would otherwise spend its own budget and start asserting # against 429s. tests/test_ratelimit.py turns it back on deliberately. os.environ.setdefault("POORBIRD_RATE_LIMIT_ENABLED", "false") # The test client speaks http://testserver, and a Secure cookie is not stored # for an http origin -- so with this left at its production default every # session test would fail with "not signed in" and nothing to show why. The # same trap catches local development against the Vite dev server, which is # why this is a setting at all. See config.session_cookie_secure. os.environ.setdefault("POORBIRD_SESSION_COOKIE_SECURE", "false") # Pin the production default. A developer's server/.env sets this true so the # Vite dev server can show images, and an untracked file must not be able to # change what the suite asserts. Tests that care about either mode name it # explicitly -- see test_captures.py. os.environ.setdefault("POORBIRD_SERVE_IMAGES_DIRECTLY", "false") def database_is_reachable() -> bool: try: from sqlalchemy import text from poorbird.db import engine with engine.connect() as conn: conn.execute(text("SELECT 1")) return True except Exception: return False needs_db = pytest.mark.skipif( not database_is_reachable(), reason="no reachable PostgreSQL (set POORBIRD_DATABASE_URL)", ) @pytest.fixture(scope="session") def client(): from fastapi.testclient import TestClient from poorbird.api.app import create_app with TestClient(create_app()) as c: yield c