"""Shared database seed and rejection helpers; no test imports.""" from uuid import uuid4 import pytest from sqlalchemy import text from sqlalchemy.exc import IntegrityError, DataError def seed(connection): org, actor, document = uuid4(), uuid4(), uuid4() connection.execute(text("INSERT INTO organizations(id,name) VALUES (:id,'test')"), {"id": org}) connection.execute(text(""" INSERT INTO users(id,organization_id,username,password_hash,role) VALUES (:id,:org,:name,'test-only','admin') """), {"id": actor, "org": org, "name": str(actor)}) connection.execute(text(""" INSERT INTO documents(id,organization_id,uploaded_by,title,original_filename, upload_request_id,upload_payload_hash,storage_key,file_sha256,mime_type, size_bytes,processing_profile) VALUES (:id,:org,:actor,'test','test.md',:request,:hash,:key,:hash,'text/markdown', 1,CAST(:profile AS jsonb)) """), {"id": document, "org": org, "actor": actor, "request": uuid4(), "hash": "a" * 64, "key": str(document), "profile": "{}"}) return org, actor, document def rejected(engine, sql, params): with pytest.raises((IntegrityError, DataError)): with engine.begin() as connection: connection.execute(text(sql), params)