Enterprise Meeting Knowledge Management System with: Backend (FastAPI): - Authentication proxy with JWT (pj-auth-api integration) - MySQL database with 4 tables (users, meetings, conclusions, actions) - Meeting CRUD with system code generation (C-YYYYMMDD-XX, A-YYYYMMDD-XX) - Dify LLM integration for AI summarization - Excel export with openpyxl - 20 unit tests (all passing) Client (Electron): - Login page with company auth - Meeting list with create/delete - Meeting detail with real-time transcription - Editable transcript textarea (single block, easy editing) - AI summarization with conclusions/action items - 5-second segment recording (efficient for long meetings) Sidecar (Python): - faster-whisper medium model with int8 quantization - ONNX Runtime VAD (lightweight, ~20MB vs PyTorch ~2GB) - Chinese punctuation processing - OpenCC for Traditional Chinese conversion - Anti-hallucination parameters - Auto-cleanup of temp audio files OpenSpec: - add-meeting-assistant-mvp (47 tasks, archived) - add-realtime-transcription (29 tasks, archived) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
96 lines
3.2 KiB
Python
96 lines
3.2 KiB
Python
"""
|
|
Unit tests for database connection and table initialization.
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
|
|
class TestDatabaseConnection:
|
|
"""Tests for database connectivity."""
|
|
|
|
@patch("mysql.connector.pooling.MySQLConnectionPool")
|
|
def test_init_db_pool_success(self, mock_pool):
|
|
"""Test successful database pool initialization."""
|
|
mock_pool.return_value = MagicMock()
|
|
|
|
from app.database import init_db_pool
|
|
|
|
pool = init_db_pool()
|
|
assert pool is not None
|
|
mock_pool.assert_called_once()
|
|
|
|
@patch("mysql.connector.pooling.MySQLConnectionPool")
|
|
def test_init_db_pool_with_correct_config(self, mock_pool):
|
|
"""Test database pool is created with correct configuration."""
|
|
from app.database import init_db_pool
|
|
from app.config import settings
|
|
|
|
init_db_pool()
|
|
|
|
call_args = mock_pool.call_args
|
|
assert call_args.kwargs["host"] == settings.DB_HOST
|
|
assert call_args.kwargs["port"] == settings.DB_PORT
|
|
assert call_args.kwargs["user"] == settings.DB_USER
|
|
assert call_args.kwargs["database"] == settings.DB_NAME
|
|
|
|
|
|
class TestTableInitialization:
|
|
"""Tests for table creation."""
|
|
|
|
@patch("app.database.get_db_cursor")
|
|
def test_init_tables_creates_required_tables(self, mock_cursor_context):
|
|
"""Test that all required tables are created."""
|
|
mock_cursor = MagicMock()
|
|
mock_cursor_context.return_value.__enter__ = MagicMock(return_value=mock_cursor)
|
|
mock_cursor_context.return_value.__exit__ = MagicMock(return_value=False)
|
|
|
|
from app.database import init_tables
|
|
|
|
init_tables()
|
|
|
|
# Verify execute was called for each table
|
|
assert mock_cursor.execute.call_count == 4
|
|
|
|
# Check table names in SQL
|
|
calls = mock_cursor.execute.call_args_list
|
|
sql_statements = [call[0][0] for call in calls]
|
|
|
|
assert any("meeting_users" in sql for sql in sql_statements)
|
|
assert any("meeting_records" in sql for sql in sql_statements)
|
|
assert any("meeting_conclusions" in sql for sql in sql_statements)
|
|
assert any("meeting_action_items" in sql for sql in sql_statements)
|
|
|
|
|
|
class TestDatabaseHelpers:
|
|
"""Tests for database helper functions."""
|
|
|
|
@patch("app.database.connection_pool")
|
|
def test_get_db_connection_returns_connection(self, mock_pool):
|
|
"""Test that get_db_connection returns a valid connection."""
|
|
mock_conn = MagicMock()
|
|
mock_pool.get_connection.return_value = mock_conn
|
|
|
|
from app.database import get_db_connection
|
|
|
|
with get_db_connection() as conn:
|
|
assert conn == mock_conn
|
|
|
|
mock_conn.close.assert_called_once()
|
|
|
|
@patch("app.database.connection_pool")
|
|
def test_get_db_cursor_with_commit(self, mock_pool):
|
|
"""Test that get_db_cursor commits when specified."""
|
|
mock_conn = MagicMock()
|
|
mock_cursor = MagicMock()
|
|
mock_pool.get_connection.return_value = mock_conn
|
|
mock_conn.cursor.return_value = mock_cursor
|
|
|
|
from app.database import get_db_cursor
|
|
|
|
with get_db_cursor(commit=True) as cursor:
|
|
cursor.execute("SELECT 1")
|
|
|
|
mock_conn.commit.assert_called_once()
|
|
mock_cursor.close.assert_called_once()
|