test: refactor async context management in approval and dependency tests
This commit is contained in:
@@ -68,6 +68,7 @@ def test_normalize_task_ids_dedupes_and_merges_sources() -> None:
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_task_counts_for_board_supports_multi_task_links_and_legacy_rows() -> None:
|
async def test_task_counts_for_board_supports_multi_task_links_and_legacy_rows() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
board_id, task_a, task_b, task_c = await _seed_board(session)
|
board_id, task_a, task_b, task_c = await _seed_board(session)
|
||||||
|
|
||||||
@@ -121,11 +122,14 @@ async def test_task_counts_for_board_supports_multi_task_links_and_legacy_rows()
|
|||||||
assert counts[task_a] == (2, 1)
|
assert counts[task_a] == (2, 1)
|
||||||
assert counts[task_b] == (2, 2)
|
assert counts[task_b] == (2, 2)
|
||||||
assert counts[task_c] == (2, 2)
|
assert counts[task_c] == (2, 2)
|
||||||
|
finally:
|
||||||
|
await engine.dispose()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_load_task_ids_by_approval_preserves_insert_order() -> None:
|
async def test_load_task_ids_by_approval_preserves_insert_order() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
board_id, task_a, task_b, task_c = await _seed_board(session)
|
board_id, task_a, task_b, task_c = await _seed_board(session)
|
||||||
|
|
||||||
@@ -145,3 +149,5 @@ async def test_load_task_ids_by_approval_preserves_insert_order() -> None:
|
|||||||
|
|
||||||
mapping = await load_task_ids_by_approval(session, approval_ids=[approval.id])
|
mapping = await load_task_ids_by_approval(session, approval_ids=[approval.id])
|
||||||
assert mapping[approval.id] == [task_a, task_b, task_c]
|
assert mapping[approval.id] == [task_a, task_b, task_c]
|
||||||
|
finally:
|
||||||
|
await engine.dispose()
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ async def _seed_board_and_tasks(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_validate_dependency_update_rejects_self_dependency() -> None:
|
async def test_validate_dependency_update_rejects_self_dependency() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
board_id = uuid4()
|
board_id = uuid4()
|
||||||
task_id = uuid4()
|
task_id = uuid4()
|
||||||
@@ -56,11 +57,14 @@ async def test_validate_dependency_update_rejects_self_dependency() -> None:
|
|||||||
depends_on_task_ids=[task_id],
|
depends_on_task_ids=[task_id],
|
||||||
)
|
)
|
||||||
assert exc.value.status_code == 422
|
assert exc.value.status_code == 422
|
||||||
|
finally:
|
||||||
|
await engine.dispose()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_validate_dependency_update_404s_when_dependency_missing() -> None:
|
async def test_validate_dependency_update_404s_when_dependency_missing() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
board_id = uuid4()
|
board_id = uuid4()
|
||||||
task_id = uuid4()
|
task_id = uuid4()
|
||||||
@@ -78,11 +82,14 @@ async def test_validate_dependency_update_404s_when_dependency_missing() -> None
|
|||||||
detail = exc.value.detail
|
detail = exc.value.detail
|
||||||
assert isinstance(detail, dict)
|
assert isinstance(detail, dict)
|
||||||
assert detail["missing_task_ids"] == [str(dep_id)]
|
assert detail["missing_task_ids"] == [str(dep_id)]
|
||||||
|
finally:
|
||||||
|
await engine.dispose()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_validate_dependency_update_detects_cycle() -> None:
|
async def test_validate_dependency_update_detects_cycle() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
board_id = uuid4()
|
board_id = uuid4()
|
||||||
a, b = uuid4(), uuid4()
|
a, b = uuid4(), uuid4()
|
||||||
@@ -101,11 +108,14 @@ async def test_validate_dependency_update_detects_cycle() -> None:
|
|||||||
depends_on_task_ids=[a],
|
depends_on_task_ids=[a],
|
||||||
)
|
)
|
||||||
assert exc.value.status_code == 409
|
assert exc.value.status_code == 409
|
||||||
|
finally:
|
||||||
|
await engine.dispose()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_dependency_queries_and_replace_and_dependents() -> None:
|
async def test_dependency_queries_and_replace_and_dependents() -> None:
|
||||||
engine = await _make_engine()
|
engine = await _make_engine()
|
||||||
|
try:
|
||||||
async with await _make_session(engine) as session:
|
async with await _make_session(engine) as session:
|
||||||
board_id = uuid4()
|
board_id = uuid4()
|
||||||
t1, t2, t3 = uuid4(), uuid4(), uuid4()
|
t1, t2, t3 = uuid4(), uuid4(), uuid4()
|
||||||
@@ -119,7 +129,9 @@ async def test_dependency_queries_and_replace_and_dependents() -> None:
|
|||||||
# cover empty input short-circuit
|
# cover empty input short-circuit
|
||||||
assert await td.dependency_ids_by_task_id(session, board_id=board_id, task_ids=[]) == {}
|
assert await td.dependency_ids_by_task_id(session, board_id=board_id, task_ids=[]) == {}
|
||||||
|
|
||||||
deps_map = await td.dependency_ids_by_task_id(session, board_id=board_id, task_ids=[t1, t2])
|
deps_map = await td.dependency_ids_by_task_id(
|
||||||
|
session, board_id=board_id, task_ids=[t1, t2]
|
||||||
|
)
|
||||||
assert deps_map[t1] == [t2, t3]
|
assert deps_map[t1] == [t2, t3]
|
||||||
assert deps_map.get(t2, []) == []
|
assert deps_map.get(t2, []) == []
|
||||||
|
|
||||||
@@ -130,7 +142,10 @@ async def test_dependency_queries_and_replace_and_dependents() -> None:
|
|||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
||||||
# cover empty input short-circuit
|
# cover empty input short-circuit
|
||||||
assert await td.dependency_status_by_id(session, board_id=board_id, dependency_ids=[]) == {}
|
assert (
|
||||||
|
await td.dependency_status_by_id(session, board_id=board_id, dependency_ids=[])
|
||||||
|
== {}
|
||||||
|
)
|
||||||
|
|
||||||
status_map = await td.dependency_status_by_id(
|
status_map = await td.dependency_status_by_id(
|
||||||
session, board_id=board_id, dependency_ids=[t2, t3]
|
session, board_id=board_id, dependency_ids=[t2, t3]
|
||||||
@@ -143,7 +158,9 @@ async def test_dependency_queries_and_replace_and_dependents() -> None:
|
|||||||
|
|
||||||
# cover early return when no deps provided
|
# cover early return when no deps provided
|
||||||
assert (
|
assert (
|
||||||
await td.blocked_by_for_task(session, board_id=board_id, task_id=t1, dependency_ids=[])
|
await td.blocked_by_for_task(
|
||||||
|
session, board_id=board_id, task_id=t1, dependency_ids=[]
|
||||||
|
)
|
||||||
== []
|
== []
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -157,10 +174,14 @@ async def test_dependency_queries_and_replace_and_dependents() -> None:
|
|||||||
await session.commit()
|
await session.commit()
|
||||||
assert out == [t3]
|
assert out == [t3]
|
||||||
|
|
||||||
deps_map2 = await td.dependency_ids_by_task_id(session, board_id=board_id, task_ids=[t1])
|
deps_map2 = await td.dependency_ids_by_task_id(
|
||||||
|
session, board_id=board_id, task_ids=[t1]
|
||||||
|
)
|
||||||
assert deps_map2[t1] == [t3]
|
assert deps_map2[t1] == [t3]
|
||||||
|
|
||||||
dependents = await td.dependent_task_ids(session, board_id=board_id, dependency_task_id=t3)
|
dependents = await td.dependent_task_ids(
|
||||||
|
session, board_id=board_id, dependency_task_id=t3
|
||||||
|
)
|
||||||
assert dependents == [t1]
|
assert dependents == [t1]
|
||||||
|
|
||||||
# also exercise explicit dependency_ids passed
|
# also exercise explicit dependency_ids passed
|
||||||
@@ -168,3 +189,5 @@ async def test_dependency_queries_and_replace_and_dependents() -> None:
|
|||||||
session, board_id=board_id, task_id=t1, dependency_ids=[t3]
|
session, board_id=board_id, task_id=t1, dependency_ids=[t3]
|
||||||
)
|
)
|
||||||
assert blocked2 == [t3]
|
assert blocked2 == [t3]
|
||||||
|
finally:
|
||||||
|
await engine.dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user