Files
FabledCurator/tests/test_api_extension_api_key.py
bvandeusen def967a1a8 refactor(dry-S1): hoist app/client test fixtures into conftest
Removed the app/client fixtures duplicated across 36 test files (two
variants: separate app + client(app), and a self-contained client() that
called create_app inline) and the now-unused create_app imports. Both
fixtures now live once in conftest.py. test_suggestions_bulk keeps its
import (builds the app inline in two tests); test_health drops its local
client + unused pytest_asyncio.

Net -415 lines.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 11:33:05 -04:00

42 lines
1.3 KiB
Python

import pytest
from sqlalchemy import select
from backend.app.models import AppSetting
pytestmark = pytest.mark.integration
@pytest.mark.asyncio
async def test_get_seeds_a_value(client, db):
# First call seeds the row (idempotent on repeat calls).
resp = await client.get("/api/settings/extension_api_key")
assert resp.status_code == 200
body = await resp.get_json()
assert isinstance(body["key"], str) and len(body["key"]) >= 16
row = (await db.execute(
select(AppSetting.value).where(AppSetting.key == "extension_api_key")
)).scalar_one()
assert row == body["key"]
@pytest.mark.asyncio
async def test_get_is_idempotent(client):
a = (await (await client.get("/api/settings/extension_api_key")).get_json())["key"]
b = (await (await client.get("/api/settings/extension_api_key")).get_json())["key"]
assert a == b
@pytest.mark.asyncio
async def test_rotate_changes_the_value(client, db):
before = (await (await client.get("/api/settings/extension_api_key")).get_json())["key"]
rotated = await client.post("/api/settings/extension_api_key/rotate")
assert rotated.status_code == 200
after = (await rotated.get_json())["key"]
assert after != before
row = (await db.execute(
select(AppSetting.value).where(AppSetting.key == "extension_api_key")
)).scalar_one()
assert row == after