67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
"""마케터 단계 테스트."""
|
|
import json
|
|
import pytest
|
|
from unittest.mock import patch
|
|
|
|
|
|
def test_enhance_for_conversion_inserts_links():
|
|
"""마케터가 브랜드 링크를 본문에 삽입."""
|
|
from app.marketer import enhance_for_conversion
|
|
|
|
brand_links = [
|
|
{"url": "https://link.coupang.com/abc", "product_name": "갤럭시 버즈3",
|
|
"description": "노이즈캔슬링", "placement_hint": "본문 중간"},
|
|
]
|
|
|
|
mock_response = json.dumps({
|
|
"title": "마케팅된 제목",
|
|
"body": '<p>본문 <a href="https://link.coupang.com/abc">갤럭시 버즈3</a></p>',
|
|
"excerpt": "요약",
|
|
})
|
|
|
|
with patch("app.marketer._call_claude", return_value=mock_response) as mock_call, \
|
|
patch("app.marketer.get_template", return_value="초안: {draft_body}\n키워드: {keyword}\n링크:\n{brand_links_info}"):
|
|
result = enhance_for_conversion(
|
|
post_body="<p>초안 본문</p>",
|
|
post_title="초안 제목",
|
|
brand_links=brand_links,
|
|
keyword="무선 이어폰",
|
|
)
|
|
|
|
prompt_used = mock_call.call_args[0][0]
|
|
assert "갤럭시 버즈3" in prompt_used
|
|
assert "노이즈캔슬링" in prompt_used
|
|
assert result["title"] == "마케팅된 제목"
|
|
|
|
|
|
def test_enhance_requires_brand_links():
|
|
"""브랜드 링크가 없으면 ValueError."""
|
|
from app.marketer import enhance_for_conversion
|
|
|
|
with pytest.raises(ValueError, match="브랜드커넥트 링크가 필요합니다"):
|
|
enhance_for_conversion(
|
|
post_body="<p>본문</p>",
|
|
post_title="제목",
|
|
brand_links=[],
|
|
keyword="테스트",
|
|
)
|
|
|
|
|
|
def test_enhance_json_parse_fallback():
|
|
"""JSON 파싱 실패 시 원본 제목 유지."""
|
|
from app.marketer import enhance_for_conversion
|
|
|
|
brand_links = [{"url": "https://a.com", "product_name": "상품"}]
|
|
|
|
with patch("app.marketer._call_claude", return_value="잘못된 JSON"), \
|
|
patch("app.marketer.get_template", return_value="초안: {draft_body}\n키워드: {keyword}\n링크:\n{brand_links_info}"):
|
|
result = enhance_for_conversion(
|
|
post_body="<p>원본</p>",
|
|
post_title="원본 제목",
|
|
brand_links=brand_links,
|
|
keyword="테스트",
|
|
)
|
|
|
|
assert result["title"] == "원본 제목"
|
|
assert result["body"] == "잘못된 JSON"
|