from fastapi.testclient import TestClient from app.main import app client = TestClient(app) def test_clean_text(): resp = client.post( "/moderation/check", json={"text": "Bán căn hộ đẹp tại quận 1", "context": "listing"}, ) assert resp.status_code == 200 data = resp.json() assert data["is_flagged"] is False assert data["score"] == 0.0 def test_phone_number_flagged(): resp = client.post( "/moderation/check", json={"text": "Liên hệ 0912345678 để xem nhà", "context": "listing"}, ) assert resp.status_code == 200 data = resp.json() assert data["is_flagged"] is True assert any(f["category"] == "contact_info" for f in data["flags"]) assert "[REDACTED]" in data["cleaned_text"] def test_scam_language_flagged(): resp = client.post( "/moderation/check", json={"text": "Cảnh báo lừa đảo từ chủ nhà", "context": "comment"}, ) assert resp.status_code == 200 data = resp.json() assert data["is_flagged"] is True assert any(f["category"] == "profanity" for f in data["flags"]) def test_prohibited_property(): resp = client.post( "/moderation/check", json={"text": "Bán lô đất rừng phòng hộ 500m2", "context": "listing"}, ) assert resp.status_code == 200 data = resp.json() assert data["is_flagged"] is True assert any(f["category"] == "prohibited_content" for f in data["flags"])