565006239b
Co-Authored-By: Claude Code <noreply@anthropic.com>
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""新表建模冒烟:create_all 建表 + 唯一约束生效(迁移幂等由 alembic 链保证)。"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
from app.db.models import SensitiveHit, SensitiveWord
|
|
|
|
|
|
async def test_sensitive_word_unique(make_client):
|
|
async def seed(session):
|
|
session.add(SensitiveWord(word="私单", category="飞单"))
|
|
await session.flush()
|
|
# 同词二插必须撞 UNIQUE(word)
|
|
session.add(SensitiveWord(word="私单"))
|
|
with pytest.raises(IntegrityError):
|
|
await session.flush()
|
|
|
|
client = await make_client(seed)
|
|
r = await client.get("/api/health")
|
|
assert r.status_code == 200 # app boots with new models
|
|
|
|
|
|
async def test_hit_unique_word_msg(make_client):
|
|
async def seed(session):
|
|
w = SensitiveWord(word="私单")
|
|
session.add(w)
|
|
await session.flush()
|
|
session.add(
|
|
SensitiveHit(word_id=w.id, msg_id="m1", channel="wechat")
|
|
)
|
|
session.add(
|
|
SensitiveHit(word_id=w.id, msg_id="m1", channel="wechat")
|
|
)
|
|
with pytest.raises(IntegrityError):
|
|
await session.flush()
|
|
|
|
client = await make_client(seed)
|
|
r = await client.get("/api/health")
|
|
assert r.status_code == 200 # app boots with new models
|