fc3a2d0b9b
Replace the scheduled-tasks bar chart with a table of all tasks assigned
per person in scope (no due date needed, filters ignored): main tasks,
subtasks (new GET /api/projects/{id}/subtasks-summary), done counts and
completion rate, plus a total row. Admin only, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
"""대시보드 담당자별 작업 합계 — 하위 작업 요약 API(subtasks-summary) 범위·권한. DB 없이 가짜 저장소로."""
|
|
import importlib
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from fastapi import FastAPI, HTTPException
|
|
from fastapi.testclient import TestClient
|
|
|
|
api = importlib.import_module("app.modules.project.router")
|
|
|
|
|
|
class FakeStore:
|
|
def __init__(self):
|
|
self.asked_projects, self.asked_parents = None, None
|
|
|
|
def list_projects(self, include_archived, member_email):
|
|
return [{"id": 1, "parent_id": None}, {"id": 2, "parent_id": None}, {"id": 5, "parent_id": 1}]
|
|
|
|
def list_tasks_for_projects(self, project_ids):
|
|
self.asked_projects = project_ids
|
|
return [{"id": 10 * pid} for pid in project_ids]
|
|
|
|
def list_subtasks_of(self, parent_ids):
|
|
self.asked_parents = parent_ids
|
|
return [{"parent_task_id": parent_ids[0], "assignee_email": "a@test", "assignee_name": "A", "done": True}]
|
|
|
|
|
|
class SubtaskSummaryTests(unittest.TestCase):
|
|
def setUp(self):
|
|
app = FastAPI()
|
|
app.include_router(api.router)
|
|
self.client = TestClient(app)
|
|
self.st = FakeStore()
|
|
|
|
def call(self, scope):
|
|
with patch.object(api, "_require_user", return_value={"email": "me@test"}), \
|
|
patch.object(api, "_db_or_503", return_value=self.st), \
|
|
patch.object(api, "_require_manage", return_value=None), \
|
|
patch.object(api, "_accessible_project_ids", return_value=None):
|
|
return self.client.get(f"/project/api/projects/1/subtasks-summary?scope={scope}")
|
|
|
|
def test_project_scope_uses_only_this_project(self):
|
|
r = self.call("project")
|
|
self.assertEqual(r.status_code, 200, r.text)
|
|
self.assertEqual(self.st.asked_projects, [1])
|
|
self.assertEqual(self.st.asked_parents, [10])
|
|
self.assertEqual(r.json()["subtasks"][0]["done"], True)
|
|
|
|
def test_all_scope_uses_top_level_projects(self):
|
|
self.call("all")
|
|
self.assertEqual(self.st.asked_projects, [1, 2]) # 서브프로젝트(5) 제외 — 스냅샷과 같은 범위
|
|
|
|
def test_no_access_is_rejected(self):
|
|
with patch.object(api, "_require_user", return_value={"email": "me@test"}), \
|
|
patch.object(api, "_db_or_503", return_value=self.st), \
|
|
patch.object(api, "_require_manage", side_effect=HTTPException(403)):
|
|
self.assertEqual(self.client.get("/project/api/projects/1/subtasks-summary").status_code, 403)
|
|
self.assertIsNone(self.st.asked_parents)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|