diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b08c02f..7dc87d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 271c3d9..4ae5a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,6 @@ __pycache *.db redis/data/* .ipynb_checkpoints* -#temp -tests src/user-groups.yaml src/user-groups.dev.yaml wit* diff --git a/src/tests/conftest.py b/src/tests/conftest.py new file mode 100644 index 0000000..94f5358 --- /dev/null +++ b/src/tests/conftest.py @@ -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 diff --git a/src/tests/test_start.py b/src/tests/test_start.py new file mode 100644 index 0000000..4fec658 --- /dev/null +++ b/src/tests/test_start.py @@ -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 \ No newline at end of file