mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-08 03:28:35 +03:00
adding tests for CI
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -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
2
.gitignore
vendored
@@ -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
17
src/tests/conftest.py
Normal 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
13
src/tests/test_start.py
Normal 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
|
||||
Reference in New Issue
Block a user