32 lines
986 B
Python
32 lines
986 B
Python
import os
|
|||
|
|
import tempfile
|
||
|
|
|
||
|
|
# The DB path must be set before database.py is imported (via main)
|
||
|
|
_tmp = tempfile.TemporaryDirectory()
|
||
|
|
os.environ["OVPMON_PROFILER_DB_PATH"] = os.path.join(_tmp.name, "test.db")
|
||
|
|
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
from main import app
|
||
|
|
from database import SessionLocal
|
||
|
|
from models import UserProfile
|
||
|
|
from utils.auth import verify_token
|
||
|
|
|
||
|
|
app.dependency_overrides[verify_token] = lambda: {"sub": "test"}
|
||
|
|
client = TestClient(app)
|
||
|
|
|
||
|
|
|
||
|
|
def test_put_note_is_stored_and_listed():
|
||
|
|
db = SessionLocal()
|
||
|
|
profile = UserProfile(username="note-user", status="active")
|
||
|
|
db.add(profile)
|
||
|
|
db.commit()
|
||
|
|
profile_id = profile.id
|
||
|
|
db.close()
|
||
|
|
|
||
|
|
res = client.put(f"/api/profiles/{profile_id}/note", json={"note": "hello"})
|
||
|
|
assert res.status_code == 200
|
||
|
|
assert res.json()["note"] == "hello"
|
||
|
|
|
||
|
|
res = client.get("/api/profiles")
|
||
|
|
assert res.status_code == 200
|
||
|
|
assert [p["note"] for p in res.json() if p["id"] == profile_id] == ["hello"]
|