File size: 878 Bytes
0990c3f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import fastapi
import pytest
from fastapi.testclient import TestClient
import api
def test_health_readiness_and_bearer_auth(monkeypatch):
client = TestClient(api.app)
assert client.get("/healthz").status_code == 200
assert client.get("/readyz").status_code == 503
monkeypatch.setenv("NAYARA_API_KEY", "test-secret")
assert client.get("/v1/models").status_code == 401
response = client.get("/v1/models", headers={"Authorization": "Bearer test-secret"})
assert response.status_code == 200
assert response.json()["data"][0]["id"] == "nayara-v1"
def test_chat_prompt_requires_user_message():
with pytest.raises(fastapi.HTTPException):
api._chat_prompt([api.ChatMessage(role="system", content="Be concise")])
prompt = api._chat_prompt([api.ChatMessage(role="user", content="hello")])
assert prompt.endswith("<|assistant|>\n")
|