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:
@@ -91,7 +91,11 @@ class TestSprintModel:
|
||||
|
||||
def test_sprint_timestamps(self, db_session):
|
||||
"""Test that timestamps are automatically set."""
|
||||
project = Project(id=uuid.uuid4(), name="Timestamp Sprint Project", slug="timestamp-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(),
|
||||
name="Timestamp Sprint Project",
|
||||
slug="timestamp-sprint-project",
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -112,7 +116,9 @@ class TestSprintModel:
|
||||
|
||||
def test_sprint_string_representation(self, db_session):
|
||||
"""Test the string representation of a sprint."""
|
||||
project = Project(id=uuid.uuid4(), name="Repr Sprint Project", slug="repr-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Repr Sprint Project", slug="repr-sprint-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -139,7 +145,9 @@ class TestSprintStatus:
|
||||
|
||||
def test_all_sprint_statuses(self, db_session):
|
||||
"""Test that all sprint statuses can be stored."""
|
||||
project = Project(id=uuid.uuid4(), name="Status Sprint Project", slug="status-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Status Sprint Project", slug="status-sprint-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -166,7 +174,9 @@ class TestSprintLifecycle:
|
||||
|
||||
def test_start_sprint(self, db_session):
|
||||
"""Test starting a planned sprint."""
|
||||
project = Project(id=uuid.uuid4(), name="Start Sprint Project", slug="start-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Start Sprint Project", slug="start-sprint-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -194,7 +204,11 @@ class TestSprintLifecycle:
|
||||
|
||||
def test_complete_sprint(self, db_session):
|
||||
"""Test completing an active sprint."""
|
||||
project = Project(id=uuid.uuid4(), name="Complete Sprint Project", slug="complete-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(),
|
||||
name="Complete Sprint Project",
|
||||
slug="complete-sprint-project",
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -217,13 +231,17 @@ class TestSprintLifecycle:
|
||||
sprint.velocity = 18
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(Sprint).filter_by(name="Sprint to Complete").first()
|
||||
retrieved = (
|
||||
db_session.query(Sprint).filter_by(name="Sprint to Complete").first()
|
||||
)
|
||||
assert retrieved.status == SprintStatus.COMPLETED
|
||||
assert retrieved.velocity == 18
|
||||
|
||||
def test_cancel_sprint(self, db_session):
|
||||
"""Test cancelling a sprint."""
|
||||
project = Project(id=uuid.uuid4(), name="Cancel Sprint Project", slug="cancel-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Cancel Sprint Project", slug="cancel-sprint-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -254,7 +272,9 @@ class TestSprintDates:
|
||||
|
||||
def test_sprint_date_range(self, db_session):
|
||||
"""Test storing sprint date range."""
|
||||
project = Project(id=uuid.uuid4(), name="Date Range Project", slug="date-range-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Date Range Project", slug="date-range-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -278,7 +298,9 @@ class TestSprintDates:
|
||||
|
||||
def test_one_day_sprint(self, db_session):
|
||||
"""Test creating a one-day sprint."""
|
||||
project = Project(id=uuid.uuid4(), name="One Day Project", slug="one-day-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="One Day Project", slug="one-day-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -299,7 +321,9 @@ class TestSprintDates:
|
||||
|
||||
def test_long_sprint(self, db_session):
|
||||
"""Test creating a long sprint (e.g., 4 weeks)."""
|
||||
project = Project(id=uuid.uuid4(), name="Long Sprint Project", slug="long-sprint-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Long Sprint Project", slug="long-sprint-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -325,7 +349,9 @@ class TestSprintPoints:
|
||||
|
||||
def test_sprint_with_zero_points(self, db_session):
|
||||
"""Test sprint with zero planned points."""
|
||||
project = Project(id=uuid.uuid4(), name="Zero Points Project", slug="zero-points-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Zero Points Project", slug="zero-points-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -343,13 +369,17 @@ class TestSprintPoints:
|
||||
db_session.add(sprint)
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(Sprint).filter_by(name="Zero Points Sprint").first()
|
||||
retrieved = (
|
||||
db_session.query(Sprint).filter_by(name="Zero Points Sprint").first()
|
||||
)
|
||||
assert retrieved.planned_points == 0
|
||||
assert retrieved.velocity == 0
|
||||
|
||||
def test_sprint_velocity_calculation(self, db_session):
|
||||
"""Test that we can calculate velocity from points."""
|
||||
project = Project(id=uuid.uuid4(), name="Velocity Project", slug="velocity-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Velocity Project", slug="velocity-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -376,7 +406,9 @@ class TestSprintPoints:
|
||||
|
||||
def test_sprint_overdelivery(self, db_session):
|
||||
"""Test sprint where completed > planned (stretch goals)."""
|
||||
project = Project(id=uuid.uuid4(), name="Overdelivery Project", slug="overdelivery-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Overdelivery Project", slug="overdelivery-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -395,7 +427,9 @@ class TestSprintPoints:
|
||||
db_session.add(sprint)
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(Sprint).filter_by(name="Overdelivery Sprint").first()
|
||||
retrieved = (
|
||||
db_session.query(Sprint).filter_by(name="Overdelivery Sprint").first()
|
||||
)
|
||||
assert retrieved.velocity > retrieved.planned_points
|
||||
|
||||
|
||||
@@ -404,7 +438,9 @@ class TestSprintNumber:
|
||||
|
||||
def test_sequential_sprint_numbers(self, db_session):
|
||||
"""Test creating sprints with sequential numbers."""
|
||||
project = Project(id=uuid.uuid4(), name="Sequential Project", slug="sequential-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Sequential Project", slug="sequential-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -421,14 +457,21 @@ class TestSprintNumber:
|
||||
db_session.add(sprint)
|
||||
db_session.commit()
|
||||
|
||||
sprints = db_session.query(Sprint).filter_by(project_id=project.id).order_by(Sprint.number).all()
|
||||
sprints = (
|
||||
db_session.query(Sprint)
|
||||
.filter_by(project_id=project.id)
|
||||
.order_by(Sprint.number)
|
||||
.all()
|
||||
)
|
||||
assert len(sprints) == 5
|
||||
for i, sprint in enumerate(sprints, 1):
|
||||
assert sprint.number == i
|
||||
|
||||
def test_large_sprint_number(self, db_session):
|
||||
"""Test sprint with large number (e.g., long-running project)."""
|
||||
project = Project(id=uuid.uuid4(), name="Large Number Project", slug="large-number-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Large Number Project", slug="large-number-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -453,7 +496,9 @@ class TestSprintUpdate:
|
||||
|
||||
def test_update_sprint_goal(self, db_session):
|
||||
"""Test updating sprint goal."""
|
||||
project = Project(id=uuid.uuid4(), name="Update Goal Project", slug="update-goal-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Update Goal Project", slug="update-goal-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -475,14 +520,18 @@ class TestSprintUpdate:
|
||||
sprint.goal = "Updated goal with more detail"
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(Sprint).filter_by(name="Update Goal Sprint").first()
|
||||
retrieved = (
|
||||
db_session.query(Sprint).filter_by(name="Update Goal Sprint").first()
|
||||
)
|
||||
assert retrieved.goal == "Updated goal with more detail"
|
||||
assert retrieved.created_at == original_created_at
|
||||
assert retrieved.updated_at > original_created_at
|
||||
|
||||
def test_update_sprint_dates(self, db_session):
|
||||
"""Test updating sprint dates."""
|
||||
project = Project(id=uuid.uuid4(), name="Update Dates Project", slug="update-dates-project")
|
||||
project = Project(
|
||||
id=uuid.uuid4(), name="Update Dates Project", slug="update-dates-project"
|
||||
)
|
||||
db_session.add(project)
|
||||
db_session.commit()
|
||||
|
||||
@@ -502,6 +551,8 @@ class TestSprintUpdate:
|
||||
sprint.end_date = today + timedelta(days=21)
|
||||
db_session.commit()
|
||||
|
||||
retrieved = db_session.query(Sprint).filter_by(name="Update Dates Sprint").first()
|
||||
retrieved = (
|
||||
db_session.query(Sprint).filter_by(name="Update Dates Sprint").first()
|
||||
)
|
||||
delta = retrieved.end_date - retrieved.start_date
|
||||
assert delta.days == 21
|
||||
|
||||
Reference in New Issue
Block a user