This commit is contained in:
HyeongBaeYang committed 2026-09-22 14:17:53 +09:00
commit 95350cfdbf
4 files changed
+143 -12

No files matched your search

+76 -2
View File
@@ -14,8 +14,8 @@ from datetime import timezone
from sqlalchemy import text
from common.enums import JobType, PlaceCategory, PostStatus, PostTopicKind
from services import blog_service
from common.enums import JobType, PlaceCategory, PostStatus, PostTopicKind, SiteStatus
from services import blog_service, site_payload
BODY = (
"비가 한 차례 지나간 뒤 마당 돌이 검게 젖었습니다. 이런 날에는 대청마루에 앉아 빗소리만 들어도 "
@@ -51,6 +51,53 @@ def test_filter_drops_same_topic_twice_in_one_batch():
assert "주제 중복" in dropped[0][1]
def test_build_prompt_falls_back_to_stay_wording_for_unmapped_category():
"""업종별로 분기할 수 있는 구조만 갖춘다 — 숙소 외 업종은 아직 실구현 전이라 숙소 문구로 대체한다."""
stay = blog_service.build_prompt(
place_name="테스트펜션", region="군산", topic_kind=PostTopicKind.WEATHER.value,
material="맑음인 날", used_topics=[], place_category=PlaceCategory.LODGING.value,
)
restaurant = blog_service.build_prompt(
place_name="테스트식당", region="군산", topic_kind=PostTopicKind.WEATHER.value,
material="맑음인 날", used_topics=[], place_category=PlaceCategory.RESTAURANT.value,
)
assert "숙소" in stay
assert "숙소" in restaurant # 음식점 전용 문구가 아직 없어 숙소 문구로 폴백한다
async def test_generate_one_forwards_place_category_into_the_prompt(monkeypatch):
"""generate_one 은 place_category 를 build_prompt 로 그대로 넘긴다 — 링크는 여기서
붙이지 않는다(호출부의 길이 게이트가 이 반환값에 그대로 걸리기 때문에, 붙이면
게이트가 링크까지 세어 정상 문구도 버려진다). 공급자는 provider.active() 를 통해
고르므로(Gemini 로 고정하지 않는다) 가짜 공급자로 검증한다."""
from services.llm import provider
from services.llm.types import LlmResult, Usage
captured = {}
class FakeLlm:
DEFAULT_MODEL = "fake-model"
@staticmethod
def is_configured():
return True
@staticmethod
async def generate(client, model, *, prompt, temperature=0.2, **kwargs):
captured["prompt"] = prompt
return LlmResult(json=None, text=BODY, usage=Usage())
monkeypatch.setattr(provider, "active", lambda: FakeLlm)
result = await blog_service.generate_one(
place_name="테스트식당", region="군산", topic_kind=PostTopicKind.WEATHER.value,
material="맑음인 날", used_topics=[], place_category=PlaceCategory.RESTAURANT.value,
)
assert result == (BODY, "fake-model")
assert "숙소" in captured["prompt"] # 음식점 전용 문구가 아직 없어 숙소 문구로 폴백한다
async def _seed_post(db_engine, owner_id, *, status=PostStatus.SENT, expires_days=14):
place_id, post_id = uuid.uuid4(), uuid.uuid4()
token, token_hash, expires = blog_service.issue_token()
@@ -94,6 +141,33 @@ async def test_get_approves_immediately(client, db_engine, owner_id):
assert res.status_code == 200
assert "올렸습니다" in res.text
assert await _status(db_engine, post_id) == PostStatus.APPROVED.value
# 발행된 사이트가 없으면(이 테스트) 자동 이동 없이 확인 문구만 보여준다.
assert "meta http-equiv=\"refresh\"" not in res.text
async def test_approve_page_redirects_to_the_published_blog_section(client, db_engine, owner_id):
"""승인 확인 화면은 5초 뒤 그 업장의 발행된 사이트(미니 블로그 자리)로 자동 이동한다
(2026-09-22, 사장님 지시: "이메일 승인후에 블로그가 올라가는 페이지에 5초 정도
이후에 연결되도록"). 자동 이동을 못 믿어도 되게 같은 주소를 링크로도 남긴다."""
token, post_id = await _seed_post(db_engine, owner_id)
async with db_engine.begin() as conn:
place_id = (
await conn.execute(text("SELECT place_id FROM place_posts WHERE post_id=:p"), {"p": post_id})
).scalar_one()
await conn.execute(
text(
"INSERT INTO sites (site_id, place_id, domain, status) VALUES (:sid, :pid, :dom, :st)"
),
{"sid": uuid.uuid4(), "pid": place_id, "dom": "blog-redirect-test", "st": SiteStatus.PUBLISHED.value},
)
res = await client.get(f"/v1/site/post/approve?t={token}")
assert res.status_code == 200
assert "올렸습니다" in res.text
expected_url = site_payload.publish_origin() + "/s/blog-redirect-test#blog"
assert f'<meta http-equiv="refresh" content="5;url={expected_url}">' in res.text
assert f"href='{expected_url}'" in res.text
async def test_approve_link_is_single_use(client, db_engine, owner_id):