42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import pytest
|
|
|
|
from openclaw.models import Session
|
|
|
|
BULK_URL = "/api/sessions/bulk_upsert/"
|
|
|
|
|
|
def _minimal_payload():
|
|
return {
|
|
"agent_name": "test",
|
|
"source_node": "macmini",
|
|
"sessions": [
|
|
{
|
|
"session_id": "test-session",
|
|
"model_provider": "test",
|
|
"model_id": "test-model",
|
|
}
|
|
],
|
|
"messages": [],
|
|
"tool_calls": [],
|
|
}
|
|
|
|
|
|
@pytest.mark.django_db
|
|
class TestBulkUpsertAPI:
|
|
def test_bulk_upsert_ok(self, client):
|
|
resp = client.post(BULK_URL, _minimal_payload(), content_type="application/json")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["status"] == "ok"
|
|
assert data["sessions_upserted"] == 1
|
|
|
|
def test_bulk_upsert_idempotent(self, client):
|
|
client.post(BULK_URL, _minimal_payload(), content_type="application/json")
|
|
resp = client.post(BULK_URL, _minimal_payload(), content_type="application/json")
|
|
data = resp.json()
|
|
assert data["sessions_upserted"] == 0
|
|
|
|
def test_bulk_upsert_missing_fields_returns_400(self, client):
|
|
resp = client.post(BULK_URL, {}, content_type="application/json")
|
|
assert resp.status_code == 400
|