Tasks assigned to someone (BT, SM, ...) were skipped, so their facesheets were never downloaded. Only GG tasks must be skipped now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
5.6 KiB
Python
136 lines
5.6 KiB
Python
"""Assigned tasks download like any other; only "Facesheets Needed (GG)" is skipped.
|
|
|
|
A task assigned to someone (BT, SM, ...) with a facesheet attached must still be
|
|
downloaded. GG tasks are never downloaded and their status is never touched.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pandas as pd
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
SRC = ROOT / "src"
|
|
for _p in (str(ROOT), str(SRC)):
|
|
if _p not in sys.path:
|
|
sys.path.insert(0, _p)
|
|
|
|
from onedrive_planner_http import _is_gg_task, _task_assignee_ids, _write_summary # noqa: E402
|
|
|
|
|
|
class TestTaskAssigneeIds:
|
|
def test_unassigned_task_has_no_assignees(self):
|
|
assert _task_assignee_ids({"title": "8.24.26"}) == []
|
|
assert _task_assignee_ids({"title": "8.21.26", "assignments": {}}) == []
|
|
assert _task_assignee_ids({"assignments": None}) == []
|
|
|
|
def test_assigned_task_returns_every_user_id(self):
|
|
task = {
|
|
"title": "Facesheets Needed (GG)",
|
|
"assignments": {
|
|
"aaaaaaaa-1111-2222-3333-444444444444": {"orderHint": "8"},
|
|
"bbbbbbbb-5555-6666-7777-888888888888": {"orderHint": "9"},
|
|
},
|
|
}
|
|
assert sorted(_task_assignee_ids(task)) == [
|
|
"aaaaaaaa-1111-2222-3333-444444444444",
|
|
"bbbbbbbb-5555-6666-7777-888888888888",
|
|
]
|
|
|
|
def test_blank_user_id_is_ignored(self):
|
|
assert _task_assignee_ids({"assignments": {"": {}}}) == []
|
|
|
|
|
|
class TestGgSkip:
|
|
def test_gg_title_is_skipped(self):
|
|
assert _is_gg_task({"title": "Facesheets Needed (GG)"})
|
|
assert _is_gg_task({"title": " facesheets needed (gg) "})
|
|
|
|
def test_assigned_non_gg_task_is_downloaded(self):
|
|
# Reo Vista / Balboa misses: assigned to BT / SM, must NOT be skipped.
|
|
assert not _is_gg_task({"title": "10.26.26", "assignments": {"u1": {}}})
|
|
assert not _is_gg_task(
|
|
{"title": "Melzer, Gilbert 8/23/63-Need Medi-Cal ID", "assignments": {"u2": {}}}
|
|
)
|
|
assert not _is_gg_task({"title": None})
|
|
|
|
|
|
class TestSummaryWorkbook:
|
|
def _write(self, tmp_path: Path, payload: dict) -> Path:
|
|
out = tmp_path / "Download_Summary_HTTP_test.xlsx"
|
|
_write_summary({"Balboa Nursing and Rehab": payload}, [], out, "2026-08-24 18:00")
|
|
return out
|
|
|
|
def _balboa_payload(self) -> dict:
|
|
"""The real Balboa plan: 2 downloaded (one assigned), 2 GG skipped."""
|
|
return {
|
|
"original": [Path("a.pdf"), Path("b.pdf")],
|
|
"tasks_total": 4,
|
|
"tasks_with_attachments": 2,
|
|
"tasks_with_downloads": 2,
|
|
"tasks_skipped_no_attachment": 0,
|
|
"tasks_skipped_gg": 2,
|
|
"status_changed": 2,
|
|
"task_rows": [
|
|
{"Facility Name": "Balboa Nursing and Rehab", "Task Name": "10.26.26",
|
|
"Assigned To": "B T", "Attachments": 1, "Downloaded": "Yes",
|
|
"Reason": "Downloaded 1/1 attachment(s)"},
|
|
{"Facility Name": "Balboa Nursing and Rehab", "Task Name": "8.21.26",
|
|
"Assigned To": "", "Attachments": 1, "Downloaded": "Yes",
|
|
"Reason": "Downloaded 1/1 attachment(s)"},
|
|
{"Facility Name": "Balboa Nursing and Rehab",
|
|
"Task Name": "Facesheets Needed (GG)", "Assigned To": "A S",
|
|
"Attachments": "", "Downloaded": "No",
|
|
"Reason": "Skipped — Facesheets Needed (GG)"},
|
|
{"Facility Name": "Balboa Nursing and Rehab",
|
|
"Task Name": "Facesheets Needed (GG)", "Assigned To": "D M",
|
|
"Attachments": "", "Downloaded": "No",
|
|
"Reason": "Skipped — Facesheets Needed (GG)"},
|
|
],
|
|
}
|
|
|
|
def test_download_sheet_reports_gg_skips(self, tmp_path):
|
|
out = self._write(tmp_path, self._balboa_payload())
|
|
df = pd.read_excel(out, sheet_name="Download")
|
|
assert df.loc[0, "Tasks Skipped (GG)"] == 2
|
|
assert df.loc[0, "Files Downloaded"] == 2
|
|
assert df.loc[0, "Status"] == "Success"
|
|
|
|
def test_tasks_sheet_has_a_yes_no_row_per_task(self, tmp_path):
|
|
out = self._write(tmp_path, self._balboa_payload())
|
|
df = pd.read_excel(out, sheet_name="Tasks")
|
|
assert list(df.columns) == [
|
|
"Facility Name", "Task Name", "Assigned To",
|
|
"Attachments", "Downloaded", "Reason",
|
|
]
|
|
assert list(df["Downloaded"]) == ["Yes", "Yes", "No", "No"]
|
|
facesheets = df[df["Task Name"] == "Facesheets Needed (GG)"]
|
|
assert len(facesheets) == 2
|
|
assert all(facesheets["Downloaded"] == "No")
|
|
assert all("GG" in r for r in facesheets["Reason"])
|
|
|
|
def test_facility_whose_tasks_are_all_gg(self, tmp_path):
|
|
out = self._write(tmp_path, {
|
|
"original": [],
|
|
"tasks_total": 3,
|
|
"tasks_with_attachments": 0,
|
|
"tasks_with_downloads": 0,
|
|
"tasks_skipped_no_attachment": 0,
|
|
"tasks_skipped_gg": 3,
|
|
"status_changed": 0,
|
|
"task_rows": [],
|
|
})
|
|
df = pd.read_excel(out, sheet_name="Download")
|
|
assert df.loc[0, "Status"] == "All GG — skipped"
|
|
|
|
def test_tasks_sheet_exists_even_with_no_task_rows(self, tmp_path):
|
|
out = self._write(tmp_path, {
|
|
"original": [], "tasks_total": 0, "tasks_with_attachments": 0,
|
|
"tasks_with_downloads": 0, "tasks_skipped_no_attachment": 0,
|
|
"tasks_skipped_gg": 0, "status_changed": 0, "task_rows": [],
|
|
})
|
|
df = pd.read_excel(out, sheet_name="Tasks")
|
|
assert df.empty
|
|
assert "Downloaded" in df.columns
|