test(backend): add comprehensive tests for OAuth and agent endpoints
- Added tests for OAuth provider admin and consent endpoints covering edge cases. - Extended agent-related tests to handle incorrect project associations and lifecycle state transitions. - Introduced tests for sprint status transitions and validation checks. - Improved multiline formatting consistency across all test functions.
This commit is contained in:
@@ -48,7 +48,9 @@ class TestAgentInstanceModel:
|
||||
db_session.add(instance)
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(AgentInstance).filter_by(project_id=project.id).first()
|
||||
retrieved = (
|
||||
db_session.query(AgentInstance).filter_by(project_id=project.id).first()
|
||||
)
|
||||
|
||||
assert retrieved is not None
|
||||
assert retrieved.agent_type_id == agent_type.id
|
||||
@@ -92,7 +94,10 @@ class TestAgentInstanceModel:
|
||||
name="Bob",
|
||||
status=AgentStatus.WORKING,
|
||||
current_task="Implementing user authentication",
|
||||
short_term_memory={"context": "Working on auth", "recent_files": ["auth.py"]},
|
||||
short_term_memory={
|
||||
"context": "Working on auth",
|
||||
"recent_files": ["auth.py"],
|
||||
},
|
||||
long_term_memory_ref="project-123/agent-456",
|
||||
session_id="session-abc-123",
|
||||
last_activity_at=now,
|
||||
@@ -107,7 +112,10 @@ class TestAgentInstanceModel:
|
||||
|
||||
assert retrieved.status == AgentStatus.WORKING
|
||||
assert retrieved.current_task == "Implementing user authentication"
|
||||
assert retrieved.short_term_memory == {"context": "Working on auth", "recent_files": ["auth.py"]}
|
||||
assert retrieved.short_term_memory == {
|
||||
"context": "Working on auth",
|
||||
"recent_files": ["auth.py"],
|
||||
}
|
||||
assert retrieved.long_term_memory_ref == "project-123/agent-456"
|
||||
assert retrieved.session_id == "session-abc-123"
|
||||
assert retrieved.tasks_completed == 5
|
||||
@@ -116,7 +124,9 @@ class TestAgentInstanceModel:
|
||||
|
||||
def test_agent_instance_timestamps(self, db_session):
|
||||
"""Test that timestamps are automatically set."""
|
||||
project = Project(id=uuid.uuid4(), name="Timestamp Project", slug="timestamp-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Timestamp Project", slug="timestamp-project-ai"
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Timestamp Agent",
|
||||
@@ -176,7 +186,9 @@ class TestAgentInstanceStatus:
|
||||
|
||||
def test_all_agent_statuses(self, db_session):
|
||||
"""Test that all agent statuses can be stored."""
|
||||
project = Project(id=uuid.uuid4(), name="Status Project", slug="status-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Status Project", slug="status-project-ai"
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Status Agent",
|
||||
@@ -199,12 +211,18 @@ class TestAgentInstanceStatus:
|
||||
db_session.add(instance)
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(AgentInstance).filter_by(id=instance.id).first()
|
||||
retrieved = (
|
||||
db_session.query(AgentInstance).filter_by(id=instance.id).first()
|
||||
)
|
||||
assert retrieved.status == status
|
||||
|
||||
def test_status_update(self, db_session):
|
||||
"""Test updating agent instance status."""
|
||||
project = Project(id=uuid.uuid4(), name="Update Status Project", slug="update-status-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(),
|
||||
name="Update Status Project",
|
||||
slug="update-status-project-ai",
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Update Status Agent",
|
||||
@@ -237,7 +255,9 @@ class TestAgentInstanceStatus:
|
||||
|
||||
def test_terminate_agent_instance(self, db_session):
|
||||
"""Test terminating an agent instance."""
|
||||
project = Project(id=uuid.uuid4(), name="Terminate Project", slug="terminate-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Terminate Project", slug="terminate-project-ai"
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Terminate Agent",
|
||||
@@ -281,7 +301,9 @@ class TestAgentInstanceMetrics:
|
||||
|
||||
def test_increment_metrics(self, db_session):
|
||||
"""Test incrementing usage metrics."""
|
||||
project = Project(id=uuid.uuid4(), name="Metrics Project", slug="metrics-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Metrics Project", slug="metrics-project-ai"
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Metrics Agent",
|
||||
@@ -326,7 +348,9 @@ class TestAgentInstanceMetrics:
|
||||
|
||||
def test_large_token_count(self, db_session):
|
||||
"""Test handling large token counts."""
|
||||
project = Project(id=uuid.uuid4(), name="Large Tokens Project", slug="large-tokens-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Large Tokens Project", slug="large-tokens-project-ai"
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Large Tokens Agent",
|
||||
@@ -359,7 +383,9 @@ class TestAgentInstanceShortTermMemory:
|
||||
|
||||
def test_store_complex_memory(self, db_session):
|
||||
"""Test storing complex short-term memory."""
|
||||
project = Project(id=uuid.uuid4(), name="Memory Project", slug="memory-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Memory Project", slug="memory-project-ai"
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Memory Agent",
|
||||
@@ -402,7 +428,11 @@ class TestAgentInstanceShortTermMemory:
|
||||
|
||||
def test_update_memory(self, db_session):
|
||||
"""Test updating short-term memory."""
|
||||
project = Project(id=uuid.uuid4(), name="Update Memory Project", slug="update-memory-project-ai")
|
||||
project = Project(
|
||||
id=uuid.uuid4(),
|
||||
name="Update Memory Project",
|
||||
slug="update-memory-project-ai",
|
||||
)
|
||||
agent_type = AgentType(
|
||||
id=uuid.uuid4(),
|
||||
name="Update Memory Agent",
|
||||
|
||||
Reference in New Issue
Block a user