"""평가자 단계 테스트 — 6기준 60점.""" import json import pytest from unittest.mock import patch def test_review_post_has_6_criteria(): """6개 기준으로 채점하는지 확인.""" from app.quality_reviewer import review_post mock_response = json.dumps({ "scores": { "empathy": 8, "click_appeal": 7, "conversion": 9, "seo": 8, "format": 7, "link_natural": 9, }, "total": 48, "pass": True, "feedback": "전체적으로 우수합니다", }) with patch("app.quality_reviewer._get_client") as mock_client_fn, \ patch("app.quality_reviewer.get_template", return_value="제목: {title}\n본문: {body}"): mock_client = mock_client_fn.return_value mock_client.messages.create.return_value.content = [type("C", (), {"text": mock_response})()] result = review_post("테스트 제목", "
본문
") assert "link_natural" in result["scores"] assert len(result["scores"]) == 6 assert result["total"] == 48 assert result["pass"] is True def test_review_pass_threshold_is_42(): """통과 기준이 42점인지 확인.""" from app.quality_reviewer import PASS_THRESHOLD assert PASS_THRESHOLD == 42 def test_review_fails_below_42(): """42점 미만이면 불통과.""" from app.quality_reviewer import review_post mock_response = json.dumps({ "scores": { "empathy": 5, "click_appeal": 5, "conversion": 5, "seo": 5, "format": 5, "link_natural": 5, }, "total": 30, "pass": False, "feedback": "개선 필요", }) with patch("app.quality_reviewer._get_client") as mock_client_fn, \ patch("app.quality_reviewer.get_template", return_value="제목: {title}\n본문: {body}"): mock_client = mock_client_fn.return_value mock_client.messages.create.return_value.content = [type("C", (), {"text": mock_response})()] result = review_post("제목", "본문
") assert result["pass"] is False def test_review_handles_parse_failure(): """JSON 파싱 실패 시 기본값 반환 (6개 기준).""" from app.quality_reviewer import review_post with patch("app.quality_reviewer._get_client") as mock_client_fn, \ patch("app.quality_reviewer.get_template", return_value="제목: {title}\n본문: {body}"): mock_client = mock_client_fn.return_value mock_client.messages.create.return_value.content = [type("C", (), {"text": "잘못된 응답"})()] result = review_post("제목", "본문
") assert result["pass"] is False assert "link_natural" in result["scores"] assert result["total"] == 0