o2o-site-AEO/solution/backend/tests/test_booking_request.py
Mina Choi 11d30bb3d1 [chore] solution,admin,ontology: 코드 주석을 한 줄로 — 히스토리 주석 삭제
여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다.

- ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제
- 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다
- eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다

파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이).
site·frontend·admin tsc, site vitest 105 passed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 16:05:19 +09:00

102 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""예약 요청 폼 → 사장님 메일."""
import uuid
import pytest
from sqlalchemy import text
from common.enums import PlaceCategory, SiteStatus
from services import mail_service
@pytest.fixture
def sent(monkeypatch):
box = []
monkeypatch.setattr(mail_service, "is_configured", lambda: True)
monkeypatch.setattr(mail_service, "send", lambda **kw: box.append(kw) or True)
return box
async def _seed(db_engine, owner_id, *, status=SiteStatus.PUBLISHED, email="owner@example.com") -> str:
place_id = uuid.uuid4()
async with db_engine.begin() as conn:
await conn.execute(text("UPDATE users SET email = :email WHERE user_id = :uid"),
{"email": email, "uid": owner_id})
await conn.execute(
text("INSERT INTO places (place_id, owner_user_id, name, category, status) "
"VALUES (:pid, :uid, :name, :cat, 1)"),
{"pid": place_id, "uid": owner_id, "name": "스테이,머뭄", "cat": PlaceCategory.LODGING.value},
)
await conn.execute(
text("INSERT INTO sites (site_id, place_id, status) VALUES (:sid, :pid, :st)"),
{"sid": uuid.uuid4(), "pid": place_id, "st": status.value},
)
return str(place_id)
def _form(place_id, **over):
body = {
"place_id": place_id, "name": "김손님", "phone": "010-1234-5678",
"email": "guest@example.com", "stay": "9월 20일 – 21일", "guests": "2명",
"message": "늦게 도착합니다", "consent": True, "elapsed_ms": 9000,
}
body.update(over)
return body
async def test_sends_mail_to_owner(client, db_engine, owner_id, sent):
place_id = await _seed(db_engine, owner_id)
res = await client.post("/v1/site/booking-request", json=_form(place_id))
assert res.status_code == 200
assert res.json()["success"] is True
assert len(sent) == 1
assert sent[0]["to"] == "owner@example.com"
assert sent[0]["reply_to"] == "guest@example.com"
for value in ("김손님", "010-1234-5678", "늦게 도착합니다"):
assert value in sent[0]["text"]
async def test_rejects_unpublished_place(client, db_engine, owner_id, sent):
place_id = await _seed(db_engine, owner_id, status=SiteStatus.DRAFT)
res = await client.post("/v1/site/booking-request", json=_form(place_id))
assert res.json()["success"] is False
assert sent == []
async def test_unknown_place_does_not_send(client, db_engine, owner_id, sent):
res = await client.post("/v1/site/booking-request", json=_form(str(uuid.uuid4())))
assert res.json()["success"] is False
assert sent == []
async def test_honeypot_and_instant_submit_are_dropped(client, db_engine, owner_id, sent):
place_id = await _seed(db_engine, owner_id)
bot = await client.post("/v1/site/booking-request", json=_form(place_id, company="광고회사"))
fast = await client.post("/v1/site/booking-request", json=_form(place_id, elapsed_ms=10))
assert bot.json()["success"] is True
assert fast.json()["success"] is True
assert sent == []
async def test_requires_consent(client, db_engine, owner_id, sent):
place_id = await _seed(db_engine, owner_id)
res = await client.post("/v1/site/booking-request", json=_form(place_id, consent=False))
assert res.json()["success"] is False
assert sent == []
async def test_without_smtp_answers_instead_of_failing(client, db_engine, owner_id, monkeypatch):
monkeypatch.setattr(mail_service, "is_configured", lambda: False)
place_id = await _seed(db_engine, owner_id)
res = await client.post("/v1/site/booking-request", json=_form(place_id))
assert res.status_code == 200
assert res.json()["success"] is False
assert "전화" in res.json()["message"]