Files
Aislo/resources/tester/test_342_1_haul_plan_key.py
T

61 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""342-1 흙 배분 서버 — 같은 열쇠(누가토량 결과 + 계수 · 장비 경계)면 Node 를 다시 안 띄움.
묶음 실패는 500 — 성공 + 빈 배분으로 주면 화면이 그 열쇠를 다시 안 물었음.
"""
import asyncio
import json
import sys
from pathlib import Path
from uuid import uuid4
PROJECT_ROOT = Path(__file__).resolve().parents[2]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from B06_Section import B06_Section_Router_HaulPlan as router # noqa: E402
def _patch(monkeypatch, outputs: list) -> list:
calls: list = []
async def _none(_project_id):
return {}
def _run(result, context):
calls.append(result)
return outputs.pop(0)
monkeypatch.setattr(router, "haul_inputs_for", _none)
monkeypatch.setattr(router, "conversion_factors_for", _none)
monkeypatch.setattr(router, "haul_limits_for", _none)
monkeypatch.setattr(router, "_mass_haul_context", lambda *_: {"limits": []})
monkeypatch.setattr(router, "_run_view", _run)
router._KEPT.clear()
return calls
def _post(result: dict):
response = asyncio.run(router.compute_haul_plan(uuid4(), 7, {"result": result}))
return response.status_code, json.loads(response.body)
def test_같은_열쇠는_Node_한_번(monkeypatch):
calls = _patch(monkeypatch, [{"haul_plan": {"tag": "a"}}, {"haul_plan": {"tag": "b"}}])
a = {"points": [{"cumulative_volume_m3": 1.0}]}
b = {"points": [{"cumulative_volume_m3": 2.0}]}
assert _post(a) == (200, {"status": "success", "haul_plan": {"tag": "a"}})
assert _post(a)[1]["haul_plan"] == {"tag": "a"}
assert len(calls) == 1
assert _post(b)[1]["haul_plan"] == {"tag": "b"}
assert len(calls) == 2
def test_묶음_실패는_500_기억_안_함(monkeypatch):
calls = _patch(monkeypatch, [None, {"haul_plan": None}])
a = {"points": [{"cumulative_volume_m3": 1.0}]}
assert _post(a)[0] == 500
assert _post(a) == (200, {"status": "success", "haul_plan": None})
assert len(calls) == 2