feat: add Session, Message, ToolCall models with migrations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
57
tests/test_models.py
Normal file
57
tests/test_models.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
from openclaw.models import Session, Message, ToolCall
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestModelFields:
|
||||
def test_session_creation(self):
|
||||
s = Session.objects.create(
|
||||
session_id="a" * 36,
|
||||
agent_name="xingyao",
|
||||
source_node="macmini",
|
||||
status="active",
|
||||
)
|
||||
assert s.session_id == "a" * 36
|
||||
assert s.total_tokens == 0
|
||||
assert s.message_count == 0
|
||||
|
||||
def test_message_creation(self):
|
||||
s = Session.objects.create(
|
||||
session_id="b" * 36,
|
||||
agent_name="test",
|
||||
source_node="ubuntu1",
|
||||
status="active",
|
||||
)
|
||||
msg = Message.objects.create(
|
||||
session=s,
|
||||
message_id="msg-001",
|
||||
parent_id="root",
|
||||
role="assistant",
|
||||
timestamp=datetime(2026, 4, 5, 10, 0, tzinfo=timezone.utc),
|
||||
)
|
||||
assert msg.role == "assistant"
|
||||
assert msg.tokens_total == 0
|
||||
|
||||
def test_toolcall_creation(self):
|
||||
s = Session.objects.create(
|
||||
session_id="c" * 36,
|
||||
agent_name="test",
|
||||
source_node="ubuntu2",
|
||||
status="active",
|
||||
)
|
||||
msg = Message.objects.create(
|
||||
session=s,
|
||||
message_id="msg-002",
|
||||
parent_id="root",
|
||||
role="assistant",
|
||||
timestamp=datetime(2026, 4, 5, 10, 0, tzinfo=timezone.utc),
|
||||
)
|
||||
tc = ToolCall.objects.create(
|
||||
session=s,
|
||||
message=msg,
|
||||
tool_call_id="call_0",
|
||||
tool_name="exec",
|
||||
)
|
||||
assert tc.tool_name == "exec"
|
||||
assert tc.is_error is False
|
||||
Reference in New Issue
Block a user