mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
40 lines
959 B
Python
40 lines
959 B
Python
from datetime import datetime
|
|
from os import environ
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from sqlalchemy.orm import Session
|
|
|
|
from argos.server import models
|
|
|
|
environ["ARGOS_APP_ENV"] = "test"
|
|
|
|
|
|
@pytest.fixture
|
|
def db() -> Session:
|
|
app = _create_app()
|
|
models.Base.metadata.create_all(bind=app.state.engine)
|
|
yield app.state.SessionLocal()
|
|
models.Base.metadata.drop_all(bind=app.state.engine)
|
|
|
|
|
|
@pytest.fixture
|
|
def app() -> FastAPI:
|
|
app = _create_app()
|
|
models.Base.metadata.create_all(bind=app.state.engine)
|
|
yield app
|
|
models.Base.metadata.drop_all(bind=app.state.engine)
|
|
|
|
|
|
def _create_app() -> FastAPI:
|
|
from argos.server.main import ( # local import for testing purpose
|
|
get_application,
|
|
setup_database,
|
|
)
|
|
|
|
app = get_application()
|
|
app.state.settings.database_url = "sqlite:////tmp/test-argos.db"
|
|
app.state.settings.yaml_file = "tests/config.yaml"
|
|
|
|
setup_database(app)
|
|
return app
|