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:
@@ -10,7 +10,7 @@ from sqlalchemy.exc import IntegrityError, OperationalError
|
||||
|
||||
from app.crud.syndarix.project import project
|
||||
from app.models.syndarix import Project
|
||||
from app.models.syndarix.enums import AutonomyLevel, ProjectStatus
|
||||
from app.models.syndarix.enums import ProjectStatus
|
||||
from app.schemas.syndarix import ProjectCreate
|
||||
|
||||
|
||||
@@ -88,7 +88,9 @@ class TestProjectCreate:
|
||||
|
||||
# Mock IntegrityError with slug in the message
|
||||
mock_orig = MagicMock()
|
||||
mock_orig.__str__ = lambda self: "duplicate key value violates unique constraint on slug"
|
||||
mock_orig.__str__ = (
|
||||
lambda self: "duplicate key value violates unique constraint on slug"
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
db_session,
|
||||
@@ -141,7 +143,7 @@ class TestProjectGetMultiWithFilters:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_multi_with_filters_success(self, db_session, test_project):
|
||||
"""Test successfully getting projects with filters."""
|
||||
results, total = await project.get_multi_with_filters(db_session)
|
||||
_results, total = await project.get_multi_with_filters(db_session)
|
||||
assert total >= 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -162,17 +164,13 @@ class TestProjectGetWithCounts:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_with_counts_not_found(self, db_session):
|
||||
"""Test getting non-existent project with counts."""
|
||||
result = await project.get_with_counts(
|
||||
db_session, project_id=uuid.uuid4()
|
||||
)
|
||||
result = await project.get_with_counts(db_session, project_id=uuid.uuid4())
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_with_counts_success(self, db_session, test_project):
|
||||
"""Test successfully getting project with counts."""
|
||||
result = await project.get_with_counts(
|
||||
db_session, project_id=test_project.id
|
||||
)
|
||||
result = await project.get_with_counts(db_session, project_id=test_project.id)
|
||||
assert result is not None
|
||||
assert result["project"].id == test_project.id
|
||||
assert result["agent_count"] == 0
|
||||
@@ -187,9 +185,7 @@ class TestProjectGetWithCounts:
|
||||
side_effect=OperationalError("Connection lost", {}, Exception()),
|
||||
):
|
||||
with pytest.raises(OperationalError):
|
||||
await project.get_with_counts(
|
||||
db_session, project_id=test_project.id
|
||||
)
|
||||
await project.get_with_counts(db_session, project_id=test_project.id)
|
||||
|
||||
|
||||
class TestProjectGetMultiWithCounts:
|
||||
@@ -233,9 +229,7 @@ class TestProjectGetByOwner:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_projects_by_owner_empty(self, db_session):
|
||||
"""Test getting projects by owner when none exist."""
|
||||
results = await project.get_projects_by_owner(
|
||||
db_session, owner_id=uuid.uuid4()
|
||||
)
|
||||
results = await project.get_projects_by_owner(db_session, owner_id=uuid.uuid4())
|
||||
assert results == []
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -247,9 +241,7 @@ class TestProjectGetByOwner:
|
||||
side_effect=OperationalError("Connection lost", {}, Exception()),
|
||||
):
|
||||
with pytest.raises(OperationalError):
|
||||
await project.get_projects_by_owner(
|
||||
db_session, owner_id=uuid.uuid4()
|
||||
)
|
||||
await project.get_projects_by_owner(db_session, owner_id=uuid.uuid4())
|
||||
|
||||
|
||||
class TestProjectArchive:
|
||||
@@ -264,9 +256,7 @@ class TestProjectArchive:
|
||||
@pytest.mark.asyncio
|
||||
async def test_archive_project_success(self, db_session, test_project):
|
||||
"""Test successfully archiving project."""
|
||||
result = await project.archive_project(
|
||||
db_session, project_id=test_project.id
|
||||
)
|
||||
result = await project.archive_project(db_session, project_id=test_project.id)
|
||||
assert result is not None
|
||||
assert result.status == ProjectStatus.ARCHIVED
|
||||
|
||||
@@ -279,6 +269,4 @@ class TestProjectArchive:
|
||||
side_effect=OperationalError("Connection lost", {}, Exception()),
|
||||
):
|
||||
with pytest.raises(OperationalError):
|
||||
await project.archive_project(
|
||||
db_session, project_id=test_project.id
|
||||
)
|
||||
await project.archive_project(db_session, project_id=test_project.id)
|
||||
|
||||
Reference in New Issue
Block a user