Files

27 lines
874 B
Python

import httpx
import pytest
from tests.conftest import FAKE_KEY
async def test_missing_key_401(client: httpx.AsyncClient):
r = await client.post("/v1/images/generations", json={"prompt": "x"}, headers={"Authorization": ""})
assert r.status_code == 401
assert r.json()["error"]["code"] == "invalid_api_key"
async def test_wrong_key_401(client: httpx.AsyncClient):
r = await client.post("/v1/images/generations", json={"prompt": "x"}, headers={"Authorization": "Bearer sk-wrong"})
assert r.status_code == 401
async def test_valid_key_accepted(client: httpx.AsyncClient):
r = await client.get("/v1/models")
assert r.status_code == 200
async def test_health_open_without_key(client: httpx.AsyncClient):
r = await client.get("/health", headers={"Authorization": ""})
assert r.status_code == 200
assert r.json() == {"status": "ok"}