mirror of
https://github.com/vee1e/bulk-questionnaire-upload.git
synced 2026-09-01 09:50:06 +00:00
- Introduced a CI workflow for automated testing of backend and frontend components. - Added pytest configuration for backend tests and Vitest configuration for frontend tests. - Enhanced file validation logic in the backend to improve error handling and reporting. - Created comprehensive test cases for various validation scenarios, including edge cases and incorrect formats. - Updated requirements to include necessary testing libraries and tools.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import os
|
|
import sys
|
|
import pytest
|
|
import pytest_asyncio
|
|
import httpx
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'backend'))
|
|
import main
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def client():
|
|
transport = httpx.ASGITransport(app=main.app)
|
|
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as c:
|
|
yield c
|
|
|
|
|
|
@pytest_asyncio.fixture(autouse=True)
|
|
async def mock_db_services(monkeypatch):
|
|
"""Mock database services to avoid requiring MongoDB"""
|
|
|
|
# Mock database connection functions
|
|
async def mock_connect_to_mongo():
|
|
pass
|
|
|
|
async def mock_close_mongo_connection():
|
|
pass
|
|
|
|
monkeypatch.setattr(main, 'connect_to_mongo', mock_connect_to_mongo)
|
|
monkeypatch.setattr(main, 'close_mongo_connection', mock_close_mongo_connection)
|
|
|
|
# Mock database service
|
|
class MockDatabaseService:
|
|
async def get_all_forms(self):
|
|
return []
|
|
|
|
async def get_form_by_id(self, form_id: str):
|
|
return None # Simulate form not found
|
|
|
|
async def get_questions_by_form_id(self, form_id: str):
|
|
return []
|
|
|
|
async def get_options_by_form_id(self, form_id: str):
|
|
return []
|
|
|
|
monkeypatch.setattr(main, 'db_service', MockDatabaseService())
|