adding tests for CI

This commit is contained in:
msramalho
2024-10-17 16:07:50 +01:00
parent 3ba20d2473
commit a39ecc0777
4 changed files with 31 additions and 3 deletions

View File

@@ -37,5 +37,5 @@ jobs:
working-directory: src
- name: Run tests
run: pipenv run PYTHONPATH=. pytest -v --color=yes tests/
run: PYTHONPATH=. pipenv run pytest -v --color=yes tests/
working-directory: src

2
.gitignore vendored
View File

@@ -12,8 +12,6 @@ __pycache
*.db
redis/data/*
.ipynb_checkpoints*
#temp
tests
src/user-groups.yaml
src/user-groups.dev.yaml
wit*

17
src/tests/conftest.py Normal file
View File

@@ -0,0 +1,17 @@
import pytest
from unittest.mock import patch
from sqlalchemy import create_engine
# from sqlalchemy_utils import create_database, database_exists, drop_database
from sqlalchemy.orm import sessionmaker
@pytest.fixture(autouse=True)
def mock_logger_add():
"""Fixture to mock loguru.logger.add for all tests."""
with patch('loguru.logger.add') as mock_add:
yield mock_add # This makes the mock available to tests
@pytest.fixture(autouse=True)
def mock_database_url():
with patch('core.config.SQLALCHEMY_DATABASE_URL', "sqlite:////app/auto-archiver.test.db") as mock_wb_url:
yield mock_wb_url

13
src/tests/test_start.py Normal file
View File

@@ -0,0 +1,13 @@
import pytest
from fastapi.testclient import TestClient
from core.config import VERSION
def test_mock_logger():
from main import app
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
r = response.json()
assert "version" in r and r["version"] == VERSION