Add shopping cart and related models

This commit is contained in:
2025-11-11 12:08:06 +01:00
parent b3166811e5
commit f4618f4d05
8 changed files with 148 additions and 41 deletions

View File

@@ -1,14 +1,38 @@
import os
from unittest import mock
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy import StaticPool, create_engine
from sqlalchemy.orm import sessionmaker
from allmende_payment_system.api.dependencies import get_session
from allmende_payment_system.app import app
from allmende_payment_system.models import Base
def make_db():
engine = create_engine(
"sqlite:///:memory:",
connect_args={"check_same_thread": False},
poolclass=StaticPool,
)
Base.metadata.create_all(bind=engine) # Create tables
return sessionmaker(autocommit=False, autoflush=False, bind=engine)
def make_in_memory_session():
db = make_db()
session = db()
try:
yield session
finally:
session.close()
app.dependency_overrides[get_session] = make_in_memory_session
@pytest.fixture(scope="session")
def client():
os.environ["APS_username"] = "test"
@@ -23,13 +47,5 @@ def unauthorized_client():
@pytest.fixture
def test_db():
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(bind=engine) # Create tables
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Provide a session and the engine
db = TestingSessionLocal()
try:
yield db
finally:
db.close()
db = make_db()
return db()