- 라우터가 B03~B09 · 준비 화면 진입 전 현재 프로젝트를 한 번 확인 — 404 · 403 이면 기억을 비우고 「프로젝트가 없어졌습니다」 안내 + [대시보드로] - workflow-state 는 지워진 프로젝트에 404(전: 200 빈 단계) - 저장 경로 조회 실패는 ProjectNotFoundError(LookupError 하위) — 잡지 않은 자리도 앱 처리기가 404(전: 노선 API 등 500) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016PSXsvyDxjNmufteN5bqmt
84 lines
2.2 KiB
Python
84 lines
2.2 KiB
Python
"""지워진 프로젝트 — 서버가 500 이 아닌 404 로 답함(73-16).
|
|
|
|
화면(라우터)은 workflow-state 404 · 403 을 보고 기억한 현재 프로젝트를 비우고 안내를 띄운다.
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
|
|
import B03_FileInput.B03_FileInput_Router as b03_router
|
|
from B03_FileInput.B03_FileInput_Repository import (
|
|
ProjectNotFoundError,
|
|
get_project_storage_relative_path,
|
|
)
|
|
from B03_FileInput.B03_FileInput_Router_Errors import project_not_found_response
|
|
|
|
GONE = "fa76c162-71c7-46e5-a95d-fb3930665a45"
|
|
|
|
|
|
class _Cursor:
|
|
def __init__(self, row):
|
|
self.row = row
|
|
self.sql = []
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *_):
|
|
return False
|
|
|
|
async def execute(self, sql, args=None):
|
|
self.sql.append(sql)
|
|
|
|
async def fetchone(self):
|
|
return self.row
|
|
|
|
|
|
class _Conn:
|
|
def __init__(self, row):
|
|
self.row = row
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *_):
|
|
return False
|
|
|
|
def cursor(self, *_):
|
|
return _Cursor(self.row)
|
|
|
|
|
|
class _Pool:
|
|
def __init__(self, row):
|
|
self.row = row
|
|
|
|
def acquire(self):
|
|
return _Conn(self.row)
|
|
|
|
|
|
def test_저장_경로_조회는_ProjectNotFoundError_이고_LookupError_로도_잡힘():
|
|
try:
|
|
asyncio.run(get_project_storage_relative_path(_Conn(None), GONE))
|
|
except ProjectNotFoundError as exc:
|
|
assert isinstance(exc, LookupError)
|
|
else:
|
|
raise AssertionError("없는 프로젝트인데 예외가 안 남")
|
|
|
|
|
|
def test_앱_처리기는_404():
|
|
response = asyncio.run(project_not_found_response(None, ProjectNotFoundError("없음")))
|
|
assert response.status_code == 404
|
|
assert json.loads(response.body)["status"] == "error"
|
|
|
|
|
|
def test_main_앱에_처리기가_달림():
|
|
import main
|
|
|
|
assert main.app.exception_handlers.get(ProjectNotFoundError) is project_not_found_response
|
|
|
|
|
|
def test_workflow_state_는_지워진_프로젝트에_404(monkeypatch):
|
|
monkeypatch.setattr(b03_router, "get_db_pool", lambda: _Pool(None))
|
|
response = asyncio.run(b03_router.get_project_workflow_state(GONE))
|
|
assert response.status_code == 404
|