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:
2026-01-03 01:44:11 +01:00
parent acd18ff694
commit 664415111a
28 changed files with 1530 additions and 216 deletions

View File

@@ -42,7 +42,9 @@ class TestProjectCreate:
assert result.owner_id == test_owner_crud.id
@pytest.mark.asyncio
async def test_create_project_duplicate_slug_fails(self, async_test_db, test_project_crud):
async def test_create_project_duplicate_slug_fails(
self, async_test_db, test_project_crud
):
"""Test creating project with duplicate slug raises ValueError."""
_test_engine, AsyncTestingSessionLocal = async_test_db
@@ -106,7 +108,9 @@ class TestProjectRead:
_test_engine, AsyncTestingSessionLocal = async_test_db
async with AsyncTestingSessionLocal() as session:
result = await project_crud.get_by_slug(session, slug=test_project_crud.slug)
result = await project_crud.get_by_slug(
session, slug=test_project_crud.slug
)
assert result is not None
assert result.slug == test_project_crud.slug
@@ -136,7 +140,9 @@ class TestProjectUpdate:
name="Updated Project Name",
description="Updated description",
)
result = await project_crud.update(session, db_obj=project, obj_in=update_data)
result = await project_crud.update(
session, db_obj=project, obj_in=update_data
)
assert result.name == "Updated Project Name"
assert result.description == "Updated description"
@@ -150,12 +156,16 @@ class TestProjectUpdate:
project = await project_crud.get(session, id=str(test_project_crud.id))
update_data = ProjectUpdate(status=ProjectStatus.PAUSED)
result = await project_crud.update(session, db_obj=project, obj_in=update_data)
result = await project_crud.update(
session, db_obj=project, obj_in=update_data
)
assert result.status == ProjectStatus.PAUSED
@pytest.mark.asyncio
async def test_update_project_autonomy_level(self, async_test_db, test_project_crud):
async def test_update_project_autonomy_level(
self, async_test_db, test_project_crud
):
"""Test updating project autonomy level."""
_test_engine, AsyncTestingSessionLocal = async_test_db
@@ -163,7 +173,9 @@ class TestProjectUpdate:
project = await project_crud.get(session, id=str(test_project_crud.id))
update_data = ProjectUpdate(autonomy_level=AutonomyLevel.AUTONOMOUS)
result = await project_crud.update(session, db_obj=project, obj_in=update_data)
result = await project_crud.update(
session, db_obj=project, obj_in=update_data
)
assert result.autonomy_level == AutonomyLevel.AUTONOMOUS
@@ -175,9 +187,14 @@ class TestProjectUpdate:
async with AsyncTestingSessionLocal() as session:
project = await project_crud.get(session, id=str(test_project_crud.id))
new_settings = {"mcp_servers": ["gitea", "slack"], "webhook_url": "https://example.com"}
new_settings = {
"mcp_servers": ["gitea", "slack"],
"webhook_url": "https://example.com",
}
update_data = ProjectUpdate(settings=new_settings)
result = await project_crud.update(session, db_obj=project, obj_in=update_data)
result = await project_crud.update(
session, db_obj=project, obj_in=update_data
)
assert result.settings == new_settings
@@ -273,7 +290,9 @@ class TestProjectFilters:
assert any(p.name == "Searchable Project" for p in projects)
@pytest.mark.asyncio
async def test_get_multi_with_filters_owner(self, async_test_db, test_owner_crud, test_project_crud):
async def test_get_multi_with_filters_owner(
self, async_test_db, test_owner_crud, test_project_crud
):
"""Test filtering projects by owner."""
_test_engine, AsyncTestingSessionLocal = async_test_db
@@ -287,7 +306,9 @@ class TestProjectFilters:
assert all(p.owner_id == test_owner_crud.id for p in projects)
@pytest.mark.asyncio
async def test_get_multi_with_filters_pagination(self, async_test_db, test_owner_crud):
async def test_get_multi_with_filters_pagination(
self, async_test_db, test_owner_crud
):
"""Test pagination of project results."""
_test_engine, AsyncTestingSessionLocal = async_test_db
@@ -348,7 +369,9 @@ class TestProjectSpecialMethods:
_test_engine, AsyncTestingSessionLocal = async_test_db
async with AsyncTestingSessionLocal() as session:
result = await project_crud.archive_project(session, project_id=test_project_crud.id)
result = await project_crud.archive_project(
session, project_id=test_project_crud.id
)
assert result is not None
assert result.status == ProjectStatus.ARCHIVED
@@ -359,11 +382,15 @@ class TestProjectSpecialMethods:
_test_engine, AsyncTestingSessionLocal = async_test_db
async with AsyncTestingSessionLocal() as session:
result = await project_crud.archive_project(session, project_id=uuid.uuid4())
result = await project_crud.archive_project(
session, project_id=uuid.uuid4()
)
assert result is None
@pytest.mark.asyncio
async def test_get_projects_by_owner(self, async_test_db, test_owner_crud, test_project_crud):
async def test_get_projects_by_owner(
self, async_test_db, test_owner_crud, test_project_crud
):
"""Test getting all projects by owner."""
_test_engine, AsyncTestingSessionLocal = async_test_db
@@ -377,7 +404,9 @@ class TestProjectSpecialMethods:
assert all(p.owner_id == test_owner_crud.id for p in projects)
@pytest.mark.asyncio
async def test_get_projects_by_owner_with_status(self, async_test_db, test_owner_crud):
async def test_get_projects_by_owner_with_status(
self, async_test_db, test_owner_crud
):
"""Test getting projects by owner filtered by status."""
_test_engine, AsyncTestingSessionLocal = async_test_db