"""사람 길 만들 때 물음(PLAN 733-2 · `M02_Library_Ask`) — 임시 storage. 같은 층 같은 내용 = 409 `{같은것: [{키, 이름, 층, 주인}], 까닭}` → `씀` = 새 문서 0 · `새로` = 새 문서 1. 길 = 새로 만들기 · [단가산출로 저장] from-line · 공유 요청 승인 · 복사 딸림 재사용(carry) · 빈 문서 · 같은 층 복사 = 안 물음. B09 내 자료집 = `test_703_b09_daega_copy` · 구조물 조합으로 = `test_705_2_hopyo_paste`. """ from __future__ import annotations import pytest from M02_MasterTemplete import M02_Labor_Ref as refs from M02_MasterTemplete import M02_MasterTemplete_Store as store from M02_MasterTemplete import M02_Sangeun_Calc as calc from M02_MasterTemplete import M02_Template_Layers as layers from resources.tester import test_706_1_share_request as share_t from resources.tester.test_706_1_share_request import URL, _as, _client world = share_t.world # 같은 임시 storage 판 TEN = "GC000421" STONE = "GF000219" LIB = "/api/m02/layers/{}/library/{}" def _count(folder, kind="precombo") -> int: return len(list((folder / kind).glob("S?-*.json"))) def _doc(name: str, code: str = TEN) -> dict: return {"문서": {"이름": name, "단위": "㎡", "담은로직": [{"로직": code}]}} def test_새로_만들기_같은_내용_409_씀_새로(world): client = _client(world) _as(world) mine = layers.personal_dir(7, 42) url = LIB.format("personal", "precombo") first = client.post(url, json=_doc("가")).json()["이름"] res = client.post(url, json=_doc("이름 다름")) # 이름이 달라도 같은 내용 assert res.status_code == 409, res.text detail = res.json()["detail"] assert detail["같은것"] == [{"키": first, "이름": "가", "층": "personal", "주인": "7/42"}] assert detail["까닭"] used = client.post(url, json={**_doc("이름 다름"), "씀": first}).json() assert used == {"이름": first, "씀": True} and _count(mine) == 1 # 그것을 씀 = 새 0 made = client.post(url, json={**_doc("이름 다름"), "새로": True}).json()["이름"] assert made != first and _count(mine) == 2 # 그래도 새로 = 새 1 bad = client.post(url, json={**_doc("다른 것", STONE), "씀": first}) assert bad.status_code == 409 and _count(mine) == 2 # 같은 내용 아닌 키 = 다시 물음 assert client.post(url, json=_doc("다른 것", STONE)).status_code == 200 # 다른 내용 = 그대로 for _ in range(2): # 빈 새 문서 = 지문 없음 · 안 물음 empty = client.post(url, json={"문서": {"이름": "빈", "담은로직": []}}) assert empty.status_code == 200, empty.text copy = {"본뜬": {"층": "personal", "주인": "7/42", "키": first}} assert client.post(url, json=copy).status_code == 200 # 같은 층 [복사] = 안 물음 def test_단가산출로_저장_같은_내용_409_씀_새로(world): mine = layers.personal_dir(7, 42) line = {"로직": TEN, "수량": {"손": 2}, "별칭": "내 줄"} with store.at(mine): first = calc.from_line(line, "줄로 만든", "㎡") with pytest.raises(store.StoreError) as e: calc.from_line(line, "또 만든", "㎡") assert e.value.status == 409 and e.value.detail["같은것"][0]["키"] == first["이름"] used = calc.from_line(line, "또 만든", "㎡", use=first["이름"]) assert used == first and _count(mine, "sangeun") == 1 # 줄 = 그 SK 참조 made = calc.from_line(line, "또 만든", "㎡", new=True) assert made["이름"] != first["이름"] and _count(mine, "sangeun") == 2 def test_공유_승인_회사_같은_내용_409_씀_새로(world): client = _client(world) _as(world) pre = client.post(LIB.format("personal", "precombo"), json=_doc("내 것")).json()["이름"] rid = client.post(URL, json={"종류": "precombo", "키": pre}).json()["id"] _as(world, "ADMIN", user=50) company = layers.company_dir(7) have = client.post(LIB.format("company", "precombo"), json=_doc("회사 것")).json()["이름"] res = client.post(f"{URL}/{rid}/approve", json={"경로": []}) assert res.status_code == 409 and res.json()["detail"]["같은것"][0]["키"] == have assert client.get(URL).json()["줄"][0]["상태"] == "요청" # 물음 뒤 그대로 ok = client.post(f"{URL}/{rid}/approve", json={"경로": [], "씀": have}).json() assert ok["상태"] == "승인" and ok["사본"] == have and _count(company) == 1 _as(world) rid = client.post(URL, json={"종류": "precombo", "키": pre}).json()["id"] _as(world, "ADMIN", user=50) ok = client.post(f"{URL}/{rid}/approve", json={"경로": [], "새로": True}).json() assert ok["사본"] != have and _count(company) == 2 def test_복사_딸림_같은_원본_재사용(world): """구조물 조합 복사 딸림(733-2) = 같은 원본 사본 재사용 · 740-1 — 일위대가 안 일위대가는 넣을 때 사본 블록(딸림 없음).""" client = _client(world) _as(world) url = LIB.format("personal", "precombo") inner = client.post(url, json=_doc("안")).json()["이름"] ref = {"층": "personal", "주인": "7/42", "키": inner} outer = {"문서": {"이름": "밖", "단위": "㎡", "담은로직": [{"참조": ref}]}} top = client.post(url, json=outer).json()["이름"] with store.at(layers.personal_dir(7, 42)): assert store.read("precombo", top)["문서"]["담은로직"][0]["참조"]["층"] == "사본" company = layers.company_dir(7) combo = {"종류": "일위대가", "열": "rv", "담은로직": [{"참조": ref}], "자재": []} with store.at(company): one = refs.carry(combo, ("personal", "7/42")) assert _count(company) == 1 # 딸린 안 = 회사 새 키 two = refs.carry(combo, ("personal", "7/42")) assert _count(company) == 1 # 다시 복사 = 앞 사본 재사용 got = [x["담은로직"][0]["참조"] for x in (one, two)] assert got[0] == got[1] and got[0]["층"] == "company"