# -*- coding: utf-8 -*- """초기 설계 실패 안내 메일 — 완료 메일 대신 나가는지, 문구에 관리자 문의가 있는지. 실제 SMTP는 타지 않는다. 확인 대상은 발송 여부 판정과 본문 규약이다. """ import asyncio import pytest import B03_FileInput.B03_FileInput_Email as email_mod @pytest.fixture def sent(monkeypatch): captured = {} async def _fake_send_email(*, to_email, subject, html): captured["to"] = to_email captured["subject"] = subject captured["html"] = html return True monkeypatch.setattr(email_mod, "send_email", _fake_send_email) return captured def test_failed_email_carries_reason_and_admin_contact(sent, monkeypatch): monkeypatch.setattr(email_mod, "ADMIN_EMAIL", "admin@example.com") ok = asyncio.run( email_mod.send_initial_design_failed_email( project_id="325f57d9-0617-49b9-a793-983f24781e1e", project_name="시제 프로젝트", to_email="user@example.com", reason="B06 초기 횡단 확정 실패 (status=404).", ) ) assert ok is True assert sent["to"] == "user@example.com" assert "초기 설계 실패 알림" in sent["subject"] assert "B06 초기 횡단 확정 실패 (status=404)." in sent["html"] assert "관리자에게 문의" in sent["html"] assert "admin@example.com" in sent["html"] # 되돌릴 초기값이 없다는 사실을 본문에서 알려야 한다. assert "초기값" in sent["html"] def test_failed_email_without_admin_address_still_guides(sent, monkeypatch): monkeypatch.setattr(email_mod, "ADMIN_EMAIL", "") asyncio.run( email_mod.send_initial_design_failed_email( project_id="p1", project_name="주소 없는 환경", to_email="user@example.com", reason="계획노선 CSV가 없어 초기 노선을 세울 수 없습니다.", ) ) assert "관리자에게 문의" in sent["html"] assert "mailto:" not in sent["html"]