""" 婚恋咨询 / 婚前辅导 E2E(咨询主流程)。 迁移说明:原文件依赖 3 个环境变量(import 期即 KeyError → 从未被收集执行), 并直连 psycopg2 校验通知落库,且用不存在的固定 ID 做断言。 现统一改为 conftest fixture + 真实 API;数据库断言交后端集成测试,E2E 只走 HTTP。 """ import pytest pytestmark = pytest.mark.e2e def test_counseling_intro_lists_guidance_types(api, user_token): data = api.ok("GET", "/counseling/services/intro", token=user_token) assert isinstance(data, list) and len(data) >= 2, f"咨询介绍异常:{data}" types = {item.get("type") for item in data} for expected in ("relationship_guidance", "premarital_guidance"): assert expected in types, f"咨询介绍缺少 {expected}:{sorted(types)}" def test_create_counseling_is_user_self_and_pending(api, user_token): """用户端创建咨询:source 必须恒为 user_self,不可由请求体伪造。""" data = api.ok( "POST", "/counseling/services", token=user_token, json={"serviceType": "relationship_guidance", "userRequestSummary": "恋爱沟通困难"}, ) assert data["status"] == "pending" assert data["serviceType"] == "relationship_guidance" assert data["requestSource"] == "user_self", f"来源被污染:{data}" def test_my_counseling_list_is_accessible(api, user_token): api.ok("POST", "/counseling/services", token=user_token, json={"serviceType": "relationship_guidance", "userRequestSummary": "列表用例"}) data = api.ok("GET", "/counseling/services", token=user_token) assert isinstance(data, list) def test_cancel_counseling(api, user_token): created = api.ok( "POST", "/counseling/services", token=user_token, json={"serviceType": "emotional_support", "userRequestSummary": "测试取消"}, ) cancelled = api.ok( "POST", f"/counseling/services/{created['id']}/cancel", token=user_token ) assert cancelled["status"] == "cancelled", f"取消后状态错误:{cancelled}" def test_counselor_assigned_list_is_scoped(api, operator_token): """INV-012:咨询师只能看到分配给自己的服务(列表必须可访问且为列表)。""" token = operator_token("e2e_counselor") data = api.ok("GET", "/counseling/services/operator/assigned", token=token) assert isinstance(data, list)