Files
xer-mcp/tests/unit/test_table_handlers.py
Bill Ballou af8cdc1d31 feat: add driving flag to relationship query responses
Add computed driving flag to all relationship queries (list_relationships,
get_predecessors, get_successors). A relationship is marked as driving when
the predecessor's early end date plus lag determines the successor's early
start date.

Changes:
- Add early_start_date and early_end_date columns to activities schema
- Parse early dates from TASK table in XER files
- Implement is_driving_relationship() helper with 24hr tolerance for
  calendar gaps
- Update all relationship queries to compute and return driving flag
- Add contract and unit tests for driving flag functionality
- Update spec, contracts, and documentation
2026-01-07 07:21:58 -05:00

263 lines
7.5 KiB
Python

"""Unit tests for XER table handlers."""
class TestProjectHandler:
"""Tests for PROJECT table handler."""
def test_parse_project_row(self) -> None:
"""Handler should parse PROJECT row correctly."""
from xer_mcp.parser.table_handlers.project import ProjectHandler
handler = ProjectHandler()
# Minimal PROJECT fields
fields = [
"proj_id",
"proj_short_name",
"plan_start_date",
"plan_end_date",
]
values = ["1001", "Test Project", "2026-01-01 00:00", "2026-06-30 00:00"]
result = handler.parse_row(fields, values)
assert result is not None
assert result["proj_id"] == "1001"
assert result["proj_short_name"] == "Test Project"
assert result["plan_start_date"] == "2026-01-01T00:00:00"
assert result["plan_end_date"] == "2026-06-30T00:00:00"
def test_table_name(self) -> None:
"""Handler should report correct table name."""
from xer_mcp.parser.table_handlers.project import ProjectHandler
handler = ProjectHandler()
assert handler.table_name == "PROJECT"
class TestTaskHandler:
"""Tests for TASK table handler."""
def test_parse_task_row(self) -> None:
"""Handler should parse TASK row correctly."""
from xer_mcp.parser.table_handlers.task import TaskHandler
handler = TaskHandler()
fields = [
"task_id",
"proj_id",
"wbs_id",
"task_code",
"task_name",
"task_type",
"status_code",
"target_start_date",
"target_end_date",
"total_float_hr_cnt",
"driving_path_flag",
]
values = [
"2001",
"1001",
"100",
"A1000",
"Site Prep",
"TT_Task",
"TK_NotStart",
"2026-01-02 07:00",
"2026-01-08 15:00",
"0",
"Y",
]
result = handler.parse_row(fields, values)
assert result is not None
assert result["task_id"] == "2001"
assert result["task_code"] == "A1000"
assert result["task_type"] == "TT_Task"
assert result["driving_path_flag"] is True
assert result["total_float_hr_cnt"] == 0.0
def test_table_name(self) -> None:
"""Handler should report correct table name."""
from xer_mcp.parser.table_handlers.task import TaskHandler
handler = TaskHandler()
assert handler.table_name == "TASK"
def test_parse_early_dates(self) -> None:
"""Handler should parse early_start_date and early_end_date from TASK row."""
from xer_mcp.parser.table_handlers.task import TaskHandler
handler = TaskHandler()
fields = [
"task_id",
"proj_id",
"wbs_id",
"task_code",
"task_name",
"task_type",
"status_code",
"target_start_date",
"target_end_date",
"early_start_date",
"early_end_date",
"total_float_hr_cnt",
"driving_path_flag",
]
values = [
"2001",
"1001",
"100",
"A1000",
"Site Prep",
"TT_Task",
"TK_NotStart",
"2026-01-02 07:00",
"2026-01-08 15:00",
"2026-01-02 07:00",
"2026-01-08 15:00",
"0",
"Y",
]
result = handler.parse_row(fields, values)
assert result is not None
assert result["early_start_date"] == "2026-01-02T07:00:00"
assert result["early_end_date"] == "2026-01-08T15:00:00"
def test_parse_missing_early_dates(self) -> None:
"""Handler should handle missing early dates gracefully."""
from xer_mcp.parser.table_handlers.task import TaskHandler
handler = TaskHandler()
fields = [
"task_id",
"proj_id",
"task_code",
"task_name",
"task_type",
]
values = [
"2001",
"1001",
"A1000",
"Site Prep",
"TT_Task",
]
result = handler.parse_row(fields, values)
assert result is not None
assert result["early_start_date"] is None
assert result["early_end_date"] is None
class TestTaskpredHandler:
"""Tests for TASKPRED table handler."""
def test_parse_relationship_row(self) -> None:
"""Handler should parse TASKPRED row correctly."""
from xer_mcp.parser.table_handlers.taskpred import TaskpredHandler
handler = TaskpredHandler()
fields = [
"task_pred_id",
"task_id",
"pred_task_id",
"proj_id",
"pred_proj_id",
"pred_type",
"lag_hr_cnt",
]
values = ["3001", "2002", "2001", "1001", "1001", "PR_FS", "8"]
result = handler.parse_row(fields, values)
assert result is not None
assert result["task_pred_id"] == "3001"
assert result["task_id"] == "2002"
assert result["pred_task_id"] == "2001"
assert result["pred_type"] == "PR_FS"
assert result["lag_hr_cnt"] == 8.0
def test_table_name(self) -> None:
"""Handler should report correct table name."""
from xer_mcp.parser.table_handlers.taskpred import TaskpredHandler
handler = TaskpredHandler()
assert handler.table_name == "TASKPRED"
class TestProjwbsHandler:
"""Tests for PROJWBS table handler."""
def test_parse_wbs_row(self) -> None:
"""Handler should parse PROJWBS row correctly."""
from xer_mcp.parser.table_handlers.projwbs import ProjwbsHandler
handler = ProjwbsHandler()
fields = [
"wbs_id",
"proj_id",
"parent_wbs_id",
"wbs_short_name",
"wbs_name",
]
values = ["100", "1001", "", "ROOT", "Project Root"]
result = handler.parse_row(fields, values)
assert result is not None
assert result["wbs_id"] == "100"
assert result["proj_id"] == "1001"
assert result["parent_wbs_id"] == ""
assert result["wbs_short_name"] == "ROOT"
def test_table_name(self) -> None:
"""Handler should report correct table name."""
from xer_mcp.parser.table_handlers.projwbs import ProjwbsHandler
handler = ProjwbsHandler()
assert handler.table_name == "PROJWBS"
class TestCalendarHandler:
"""Tests for CALENDAR table handler."""
def test_parse_calendar_row(self) -> None:
"""Handler should parse CALENDAR row correctly."""
from xer_mcp.parser.table_handlers.calendar import CalendarHandler
handler = CalendarHandler()
fields = [
"clndr_id",
"clndr_name",
"day_hr_cnt",
"week_hr_cnt",
]
values = ["1", "Standard 5 Day", "8", "40"]
result = handler.parse_row(fields, values)
assert result is not None
assert result["clndr_id"] == "1"
assert result["clndr_name"] == "Standard 5 Day"
assert result["day_hr_cnt"] == 8.0
assert result["week_hr_cnt"] == 40.0
def test_table_name(self) -> None:
"""Handler should report correct table name."""
from xer_mcp.parser.table_handlers.calendar import CalendarHandler
handler = CalendarHandler()
assert handler.table_name == "CALENDAR"