mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-13 08:45:24 +00:00
- Add new routers: admin, appointments, campaigns - Add storage service and logging config - Add migrations directory and test suite with pytest config - Add supabase_migration_features.sql - Update models, dependencies, config, and existing routers - Remove whatsapp_service (deleted) - Update pyproject.toml and uv.lock dependencies Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
"""
|
|
Test fixtures for Contexta backend.
|
|
Uses unittest.mock to avoid hitting real Supabase/Qdrant in unit tests.
|
|
"""
|
|
import pytest
|
|
from unittest.mock import MagicMock, patch, AsyncMock
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
"""FastAPI test client. Patches Supabase and Qdrant at module level."""
|
|
with patch("app.database.get_supabase") as mock_sb, \
|
|
patch("app.services.vector_store.vector_store") as mock_vs:
|
|
mock_sb.return_value = _make_supabase_mock()
|
|
mock_vs.create_collection = MagicMock()
|
|
mock_vs.delete_collection = MagicMock()
|
|
mock_vs.search = MagicMock(return_value=[])
|
|
|
|
from app.main import app
|
|
yield TestClient(app)
|
|
|
|
|
|
@pytest.fixture
|
|
def supabase_mock():
|
|
"""Standalone Supabase mock for direct use."""
|
|
return _make_supabase_mock()
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_headers():
|
|
"""Mock auth headers (token is verified by patching get_current_user)."""
|
|
return {"Authorization": "Bearer test-token"}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_current_user():
|
|
"""A mock Supabase auth user object."""
|
|
user = MagicMock()
|
|
user.id = "test-user-id"
|
|
user.email = "test@example.com"
|
|
return user
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_admin_user():
|
|
"""A mock admin auth user object."""
|
|
user = MagicMock()
|
|
user.id = "admin-user-id"
|
|
user.email = "admin@example.com"
|
|
return user
|
|
|
|
|
|
def _make_supabase_mock():
|
|
"""Build a chainable Supabase client mock."""
|
|
supabase = MagicMock()
|
|
|
|
# Default table chain returns empty data
|
|
table_mock = MagicMock()
|
|
table_mock.select.return_value = table_mock
|
|
table_mock.insert.return_value = table_mock
|
|
table_mock.update.return_value = table_mock
|
|
table_mock.delete.return_value = table_mock
|
|
table_mock.upsert.return_value = table_mock
|
|
table_mock.eq.return_value = table_mock
|
|
table_mock.in_.return_value = table_mock
|
|
table_mock.limit.return_value = table_mock
|
|
table_mock.order.return_value = table_mock
|
|
table_mock.range.return_value = table_mock
|
|
table_mock.gte.return_value = table_mock
|
|
table_mock.lt.return_value = table_mock
|
|
table_mock.execute.return_value = MagicMock(data=[], count=0)
|
|
|
|
supabase.table.return_value = table_mock
|
|
supabase.auth = MagicMock()
|
|
|
|
return supabase
|