feat: migrate receiptwitness to standalone repo with inlined common
Migrates receiptwitness to a standalone repo with inlined common models. Includes SQLite test compatibility fixes (server_default stripping for gen_random_bytes, relationship stubs for SQLAlchemy mapper). QA PASS (cartsnitch-qa): lint ✅ test ✅ 306/306 passed. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit was merged in pull request #2.
This commit is contained in:
committed by
GitHub
parent
c4880d3553
commit
2fd2cdca71
@@ -1,16 +1,31 @@
|
||||
"""Shared test fixtures for pipeline tests."""
|
||||
|
||||
import secrets
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, event
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from receiptwitness.shared.models import Base
|
||||
from receiptwitness.shared.models.user import User
|
||||
|
||||
|
||||
@event.listens_for(User, "before_insert")
|
||||
def _populate_email_inbound_token(mapper, connection, target):
|
||||
"""Populate email_inbound_token with a secure random value when unset.
|
||||
|
||||
SQLite has no gen_random_bytes() function, so we generate it in Python
|
||||
instead of relying on the PostgreSQL server_default.
|
||||
"""
|
||||
if target.email_inbound_token is None:
|
||||
target.email_inbound_token = secrets.token_urlsafe(16)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def engine():
|
||||
"""In-memory SQLite engine for unit tests."""
|
||||
eng = create_engine("sqlite:///:memory:")
|
||||
User.__table__.c.email_inbound_token.server_default = None
|
||||
Base.metadata.create_all(eng)
|
||||
yield eng
|
||||
eng.dispose()
|
||||
|
||||
Reference in New Issue
Block a user