Add test configuration
Some checks failed
CI / test (push) Failing after 7s

This commit is contained in:
2026-02-04 17:57:42 +00:00
parent 1be96b608d
commit 1b3d947c6a

84
app/tests/conftest.py Normal file
View File

@@ -0,0 +1,84 @@
"""Test configuration and fixtures for git-commit-message-generator tests."""
import os
import tempfile
from pathlib import Path
from unittest.mock import MagicMock
import pytest
os.environ["OLLAMA_HOST"] = "http://localhost:11434"
os.environ["OLLAMA_MODEL"] = "llama3"
os.environ["PROMPT_DIR"] = str(Path(__file__).parent.parent / "prompts")
@pytest.fixture
def mock_ollama_client():
"""Create a mock Ollama client."""
client = MagicMock()
client.check_connection.return_value = True
client.check_model_available.return_value = True
client.generate_commit_message.return_value = "feat(core): add new feature"
client.generate_changelog.return_value = "# Changelog\n\n## Features\n- New feature"
return client
@pytest.fixture
def sample_diff():
"""Sample git diff for testing."""
return (
"diff --git a/src/main.py b/src/main.py\n"
"index 1234567..abcdefg 100644\n"
"--- a/src/main.py\n"
"+++ b/src/main.py\n"
"@@ -1,5 +1,10 @@\n"
"+def new_function():\n"
'+ """A new function."""\n'
"+ return 'hello'\n"
"+\n"
" def existing_function():\n"
' """Existing function."""\n'
" return 'world'\n"
)
@pytest.fixture
def sample_commit_history():
"""Sample commit history for testing."""
return [
{
"hash": "abc1234",
"full_hash": "abc1234567890",
"message": "feat(api): add user authentication",
"author": "Test User",
"author_email": "test@example.com",
"date": "2024-01-15T10:30:00",
},
{
"hash": "def5678",
"full_hash": "def5678901234",
"message": "fix(db): resolve connection timeout",
"author": "Test User",
"author_email": "test@example.com",
"date": "2024-01-14T15:45:00",
},
{
"hash": "ghi9012",
"full_hash": "ghi9012345678",
"message": "docs: update README",
"author": "Test User",
"author_email": "test@example.com",
"date": "2024-01-13T09:00:00",
},
]
@pytest.fixture
def temp_git_repo():
"""Create a temporary git repository for testing."""
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
os.system("git init")
os.system("git config user.name 'Test User'")
os.system("git config user.email 'test@example.com'")
yield tmpdir