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:
@@ -17,7 +17,9 @@ class TestAgentInstanceCreate:
|
||||
"""Tests for agent instance creation."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_agent_instance_success(self, async_test_db, test_project_crud, test_agent_type_crud):
|
||||
async def test_create_agent_instance_success(
|
||||
self, async_test_db, test_project_crud, test_agent_type_crud
|
||||
):
|
||||
"""Test successfully creating an agent instance."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -41,7 +43,9 @@ class TestAgentInstanceCreate:
|
||||
assert result.short_term_memory == {"context": "initial"}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_agent_instance_minimal(self, async_test_db, test_project_crud, test_agent_type_crud):
|
||||
async def test_create_agent_instance_minimal(
|
||||
self, async_test_db, test_project_crud, test_agent_type_crud
|
||||
):
|
||||
"""Test creating agent instance with minimal fields."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -62,12 +66,16 @@ class TestAgentInstanceRead:
|
||||
"""Tests for agent instance read operations."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_agent_instance_by_id(self, async_test_db, test_agent_instance_crud):
|
||||
async def test_get_agent_instance_by_id(
|
||||
self, async_test_db, test_agent_instance_crud
|
||||
):
|
||||
"""Test getting agent instance by ID."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
async with AsyncTestingSessionLocal() as session:
|
||||
result = await agent_instance_crud.get(session, id=str(test_agent_instance_crud.id))
|
||||
result = await agent_instance_crud.get(
|
||||
session, id=str(test_agent_instance_crud.id)
|
||||
)
|
||||
|
||||
assert result is not None
|
||||
assert result.id == test_agent_instance_crud.id
|
||||
@@ -102,33 +110,48 @@ class TestAgentInstanceUpdate:
|
||||
"""Tests for agent instance update operations."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_agent_instance_status(self, async_test_db, test_agent_instance_crud):
|
||||
async def test_update_agent_instance_status(
|
||||
self, async_test_db, test_agent_instance_crud
|
||||
):
|
||||
"""Test updating agent instance status."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
async with AsyncTestingSessionLocal() as session:
|
||||
instance = await agent_instance_crud.get(session, id=str(test_agent_instance_crud.id))
|
||||
instance = await agent_instance_crud.get(
|
||||
session, id=str(test_agent_instance_crud.id)
|
||||
)
|
||||
|
||||
update_data = AgentInstanceUpdate(
|
||||
status=AgentStatus.WORKING,
|
||||
current_task="Processing feature request",
|
||||
)
|
||||
result = await agent_instance_crud.update(session, db_obj=instance, obj_in=update_data)
|
||||
result = await agent_instance_crud.update(
|
||||
session, db_obj=instance, obj_in=update_data
|
||||
)
|
||||
|
||||
assert result.status == AgentStatus.WORKING
|
||||
assert result.current_task == "Processing feature request"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_agent_instance_memory(self, async_test_db, test_agent_instance_crud):
|
||||
async def test_update_agent_instance_memory(
|
||||
self, async_test_db, test_agent_instance_crud
|
||||
):
|
||||
"""Test updating agent instance short-term memory."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
async with AsyncTestingSessionLocal() as session:
|
||||
instance = await agent_instance_crud.get(session, id=str(test_agent_instance_crud.id))
|
||||
instance = await agent_instance_crud.get(
|
||||
session, id=str(test_agent_instance_crud.id)
|
||||
)
|
||||
|
||||
new_memory = {"conversation": ["msg1", "msg2"], "decisions": {"key": "value"}}
|
||||
new_memory = {
|
||||
"conversation": ["msg1", "msg2"],
|
||||
"decisions": {"key": "value"},
|
||||
}
|
||||
update_data = AgentInstanceUpdate(short_term_memory=new_memory)
|
||||
result = await agent_instance_crud.update(session, db_obj=instance, obj_in=update_data)
|
||||
result = await agent_instance_crud.update(
|
||||
session, db_obj=instance, obj_in=update_data
|
||||
)
|
||||
|
||||
assert result.short_term_memory == new_memory
|
||||
|
||||
@@ -172,7 +195,9 @@ class TestAgentInstanceTerminate:
|
||||
"""Tests for agent instance termination."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_terminate_agent_instance(self, async_test_db, test_project_crud, test_agent_type_crud):
|
||||
async def test_terminate_agent_instance(
|
||||
self, async_test_db, test_project_crud, test_agent_type_crud
|
||||
):
|
||||
"""Test terminating an agent instance."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -189,7 +214,9 @@ class TestAgentInstanceTerminate:
|
||||
|
||||
# Terminate
|
||||
async with AsyncTestingSessionLocal() as session:
|
||||
result = await agent_instance_crud.terminate(session, instance_id=instance_id)
|
||||
result = await agent_instance_crud.terminate(
|
||||
session, instance_id=instance_id
|
||||
)
|
||||
|
||||
assert result is not None
|
||||
assert result.status == AgentStatus.TERMINATED
|
||||
@@ -203,7 +230,9 @@ class TestAgentInstanceTerminate:
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
async with AsyncTestingSessionLocal() as session:
|
||||
result = await agent_instance_crud.terminate(session, instance_id=uuid.uuid4())
|
||||
result = await agent_instance_crud.terminate(
|
||||
session, instance_id=uuid.uuid4()
|
||||
)
|
||||
assert result is None
|
||||
|
||||
|
||||
@@ -211,7 +240,9 @@ class TestAgentInstanceMetrics:
|
||||
"""Tests for agent instance metrics operations."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_record_task_completion(self, async_test_db, test_agent_instance_crud):
|
||||
async def test_record_task_completion(
|
||||
self, async_test_db, test_agent_instance_crud
|
||||
):
|
||||
"""Test recording task completion with metrics."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -230,7 +261,9 @@ class TestAgentInstanceMetrics:
|
||||
assert result.last_activity_at is not None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_record_multiple_task_completions(self, async_test_db, test_project_crud, test_agent_type_crud):
|
||||
async def test_record_multiple_task_completions(
|
||||
self, async_test_db, test_project_crud, test_agent_type_crud
|
||||
):
|
||||
"""Test recording multiple task completions accumulates metrics."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -267,7 +300,9 @@ class TestAgentInstanceMetrics:
|
||||
assert result.cost_incurred == Decimal("0.0300")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_project_metrics(self, async_test_db, test_project_crud, test_agent_instance_crud):
|
||||
async def test_get_project_metrics(
|
||||
self, async_test_db, test_project_crud, test_agent_instance_crud
|
||||
):
|
||||
"""Test getting aggregated metrics for a project."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -290,7 +325,9 @@ class TestAgentInstanceByProject:
|
||||
"""Tests for getting instances by project."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_by_project(self, async_test_db, test_project_crud, test_agent_instance_crud):
|
||||
async def test_get_by_project(
|
||||
self, async_test_db, test_project_crud, test_agent_instance_crud
|
||||
):
|
||||
"""Test getting instances by project."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -304,7 +341,9 @@ class TestAgentInstanceByProject:
|
||||
assert all(i.project_id == test_project_crud.id for i in instances)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_by_project_with_status(self, async_test_db, test_project_crud, test_agent_type_crud):
|
||||
async def test_get_by_project_with_status(
|
||||
self, async_test_db, test_project_crud, test_agent_type_crud
|
||||
):
|
||||
"""Test getting instances by project filtered by status."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -340,7 +379,9 @@ class TestAgentInstanceByAgentType:
|
||||
"""Tests for getting instances by agent type."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_by_agent_type(self, async_test_db, test_agent_type_crud, test_agent_instance_crud):
|
||||
async def test_get_by_agent_type(
|
||||
self, async_test_db, test_agent_type_crud, test_agent_instance_crud
|
||||
):
|
||||
"""Test getting instances by agent type."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
@@ -358,7 +399,9 @@ class TestBulkTerminate:
|
||||
"""Tests for bulk termination of instances."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bulk_terminate_by_project(self, async_test_db, test_project_crud, test_agent_type_crud):
|
||||
async def test_bulk_terminate_by_project(
|
||||
self, async_test_db, test_project_crud, test_agent_type_crud
|
||||
):
|
||||
"""Test bulk terminating all instances in a project."""
|
||||
_test_engine, AsyncTestingSessionLocal = async_test_db
|
||||
|
||||
|
||||
Reference in New Issue
Block a user