36 lines
840 B
Python
36 lines
840 B
Python
import os
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from allmende_payment_system.app import app
|
|
from allmende_payment_system.models import Base
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def client():
|
|
os.environ["APS_username"] = "test"
|
|
return TestClient(app)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def unauthorized_client():
|
|
os.environ.pop("APS_username", None)
|
|
return TestClient(app)
|
|
|
|
|
|
@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()
|