🌱 Let's start with the Gitlab CI

This commit is contained in:
Alexis Métaireau 2023-10-18 21:49:48 +02:00
parent 9885a5809a
commit a9f823fbfa
4 changed files with 27 additions and 6 deletions

15
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,15 @@
image: python:3.11
stages:
- test
before_script:
- python -V
- python -m venv venv
- ./venv/bin/pip install -e ".[dev]"
pytest:
stage: test
script:
- ./venv/bin/pytest

View file

@ -23,7 +23,9 @@ class DevSettings(Settings):
class TestSettings(Settings): class TestSettings(Settings):
pass app_env: str = "test"
yaml_file: str = "tests/config.yaml"
database_url: str = "sqlite:////tmp/test-argos.db"
class ProdSettings(Settings): class ProdSettings(Settings):

View file

@ -63,4 +63,5 @@ testpaths = [
"tests", "tests",
"argos" "argos"
] ]
fixture_path = "tests/fixtures.py"
pythonpath = "." pythonpath = "."

View file

@ -1,17 +1,16 @@
from datetime import datetime import os
from os import environ
import pytest import pytest
from fastapi import FastAPI from fastapi import FastAPI
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from argos.server import models os.environ["ARGOS_APP_ENV"] = "test"
environ["ARGOS_APP_ENV"] = "test"
@pytest.fixture @pytest.fixture
def db() -> Session: def db() -> Session:
from argos.server import models
app = _create_app() app = _create_app()
models.Base.metadata.create_all(bind=app.state.engine) models.Base.metadata.create_all(bind=app.state.engine)
yield app.state.SessionLocal() yield app.state.SessionLocal()
@ -20,6 +19,8 @@ def db() -> Session:
@pytest.fixture @pytest.fixture
def app() -> FastAPI: def app() -> FastAPI:
from argos.server import models
app = _create_app() app = _create_app()
models.Base.metadata.create_all(bind=app.state.engine) models.Base.metadata.create_all(bind=app.state.engine)
yield app yield app
@ -33,6 +34,8 @@ def _create_app() -> FastAPI:
) )
app = get_application() app = get_application()
# Hardcode the database url and the yaml file for testing purpose
# Otherwise, the app will try to read the .env file or the environment variables
app.state.settings.database_url = "sqlite:////tmp/test-argos.db" app.state.settings.database_url = "sqlite:////tmp/test-argos.db"
app.state.settings.yaml_file = "tests/config.yaml" app.state.settings.yaml_file = "tests/config.yaml"