Merge remote-tracking branch 'origin/sub_laptop_3' into main_laptop_1

This commit is contained in:
2026-10-27 20:11:46 +09:00
2 changed files with 48 additions and 7 deletions
+20 -1
View File
@@ -174,7 +174,7 @@ class _Connection:
class _Db:
def __init__(self):
self.log: list = []
self.answers: dict = {"FROM projects": [{"project_year": 2026}]}
self.answers: dict = {"FROM projects": [{"project_year": 2026, "plan_base_json": "{}"}]}
def acquire(self):
return _Connection(self)
@@ -184,6 +184,12 @@ class _Db:
def client(monkeypatch):
db = _Db()
monkeypatch.setattr(net, "get_db_pool", lambda: db)
base = {"epsg": 5186, "start": {"x": 0.0, "y": 0.0}, "end": {"x": 90.0, "y": 180.0}}
async def load_base(project_id):
return base
monkeypatch.setattr(net.plan_base, "load_base", load_base)
app = FastAPI()
app.include_router(net.router)
session = {"role": "USER", "email": "a@forest.go.kr"}
@@ -191,6 +197,7 @@ def client(monkeypatch):
test = TestClient(app)
test.db = db
test.session = session
test.base = base
return test
@@ -207,6 +214,7 @@ def test_get_saved_legacy_or_empty(client) -> None:
client.db.answers["FROM plan_networks"] = [{"network_json": json.dumps(_network())}]
got = client.get(URL).json()
assert got["legacy"] is False and len(got["derived"]["pieces"]) == 3
assert got["base"]["end"] == {"x": 90.0, "y": 180.0}
def test_put_stores_network_pieces_years(client) -> None:
@@ -226,6 +234,16 @@ def test_put_stores_network_pieces_years(client) -> None:
assert ("UPDATE projects SET project_year_end = %s WHERE id = %s", (2027, PID)) in log
stale = [a for s, a in log if "year NOT IN" in s]
assert stale == [(PID, 2026, 2027)]
assert not [s for s, _ in log if "plan_base_json = %s" in s] # 정본 칸 있음 = 안 굳힘
def test_put_freezes_folded_base_first(client) -> None:
client.db.answers["FROM projects"] = [{"project_year": 2026, "plan_base_json": None}]
assert client.put(URL, json=_network()).status_code == 200
sqls = [(s, a) for s, a in client.db.log if s.startswith("UPDATE projects SET plan_base_json")]
assert len(sqls) == 1 and json.loads(sqls[0][1][0]) == client.base
first_year = next(i for i, (s, _) in enumerate(client.db.log) if "plan_route_years" in s)
assert client.db.log.index(sqls[0]) < first_year
def test_put_reset_clears_year_routes(client) -> None:
@@ -254,5 +272,6 @@ def test_put_rejects(client) -> None:
client.db.answers["piece_id IS NULL"] = [(2027,)]
assert client.put(URL, json=one).status_code == 409
assert not [s for s, _ in client.db.log if s.startswith("INSERT")]
assert client.put(URL, json=_network(epsg=5187)).status_code == 400 # 기준 지정과 다른 좌표계
client.session["email"] = "a@gmail.com"
assert client.put(URL, json=_network()).status_code == 403