argos/tests/conftest.py
Luc Didry 4880c65681
💥 — Rename argos to argos-monitoring to fit the package name (fix #53)
Uninstall argos with `pip uninstall argos-monitoring` before installing this release!
2024-07-04 09:44:07 +02:00

51 lines
1.2 KiB
Python

import asyncio
import os
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
os.environ["ARGOS_YAML_FILE"] = "tests/config.yaml"
@pytest.fixture
def db() -> Session:
from argos_monitoring.server import models
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:
from argos_monitoring.server import models
app = _create_app()
models.Base.metadata.create_all(bind=app.state.engine)
yield app
models.Base.metadata.drop_all(bind=app.state.engine)
@pytest.fixture
def authorized_client(app):
with TestClient(app) as client:
token = app.state.config.service.secrets[0]
client.headers = {"Authorization": f"Bearer {token}"}
yield client
def _create_app() -> FastAPI:
from argos_monitoring.server.main import ( # local import for testing purpose
get_application,
setup_database,
connect_to_db,
)
app = get_application()
setup_database(app)
asyncio.run(connect_to_db(app))
return app