Spaces:
Paused
Legal Dashboard OCR - Test Suite
This directory contains all test files for the Legal Dashboard OCR project, organized by category for better maintainability and discovery.
π Directory Structure
tests/
βββ backend/ # Backend API and service tests
β βββ test_api_endpoints.py
β βββ test_ocr_pipeline.py
β βββ test_ocr_fixes.py
β βββ test_hf_deployment_fixes.py
β βββ test_db_connection.py
β βββ test_structure.py
β βββ validate_fixes.py
β βββ verify_frontend.py
β
βββ docker/ # Docker and deployment tests
βββ test_docker.py
βββ validate_docker_setup.py
βββ simple_validation.py
βββ test_hf_deployment.py
βββ deployment_validation.py
π§ͺ Test Categories
Backend Tests (tests/backend/
)
API Endpoint Tests:
test_api_endpoints.py
- Tests all FastAPI endpointstest_ocr_pipeline.py
- Tests OCR pipeline functionalitytest_db_connection.py
- Tests database connectivity
Fix Validation Tests:
test_ocr_fixes.py
- Validates OCR pipeline fixestest_hf_deployment_fixes.py
- Validates Hugging Face deployment fixesvalidate_fixes.py
- Comprehensive fix validation
Structure and Frontend Tests:
test_structure.py
- Tests project structure integrityverify_frontend.py
- Tests frontend integration
Docker Tests (tests/docker/
)
Docker Setup Tests:
test_docker.py
- Tests Docker container functionalityvalidate_docker_setup.py
- Validates Docker configurationsimple_validation.py
- Basic Docker validation
Deployment Tests:
test_hf_deployment.py
- Tests Hugging Face deploymentdeployment_validation.py
- Comprehensive deployment validation
π Running Tests
Method 1: Using the Test Runner
# Run all tests
python run_tests.py
# Run only backend tests
python run_tests.py --backend
# Run only docker tests
python run_tests.py --docker
# Run with pytest
python run_tests.py --pytest
Method 2: Using pytest directly
# Run all tests
pytest tests/
# Run backend tests only
pytest tests/backend/
# Run docker tests only
pytest tests/docker/
# Run with verbose output
pytest tests/ -v
# Run specific test file
pytest tests/backend/test_api_endpoints.py
Method 3: Running Individual Tests
# Backend tests
python tests/backend/test_api_endpoints.py
python tests/backend/test_ocr_pipeline.py
python tests/backend/test_ocr_fixes.py
# Docker tests
python tests/docker/test_docker.py
python tests/docker/validate_docker_setup.py
π Test Configuration
pytest.ini
The project includes a pytest.ini
file that configures:
- Test discovery paths
- Python file patterns
- Test class and function patterns
- Output formatting
Test Runner Script
The run_tests.py
script provides:
- Categorized test execution
- Detailed output formatting
- Error handling and reporting
- Support for different test types
π§ Test Dependencies
All tests require the following dependencies (already in requirements.txt
):
pytest==7.4.3
pytest-asyncio==0.21.1
fastapi
transformers
torch
- Other project dependencies
π Test Coverage
Backend Coverage
- β API endpoint functionality
- β OCR pipeline operations
- β Database operations
- β Error handling
- β Fix validation
Docker Coverage
- β Container build process
- β Environment setup
- β Service initialization
- β Deployment validation
π Troubleshooting
Common Issues
Import Errors
# Ensure you're in the project root cd legal_dashboard_ocr export PYTHONPATH=$PYTHONPATH:$(pwd)
Missing Dependencies
pip install -r requirements.txt
Database Connection Issues
# Ensure database directory exists mkdir -p /tmp/data
Docker Issues
# Ensure Docker is running docker --version docker-compose --version
Debug Mode
Run tests with debug output:
python run_tests.py --pytest -v
π Adding New Tests
Backend Tests
- Create test file in
tests/backend/
- Follow naming convention:
test_*.py
- Use pytest fixtures and assertions
- Add to test runner if needed
Docker Tests
- Create test file in
tests/docker/
- Test Docker-specific functionality
- Validate deployment configurations
- Ensure proper cleanup
Test Guidelines
- Use descriptive test names
- Include setup and teardown
- Handle errors gracefully
- Provide clear failure messages
- Clean up resources after tests
π Continuous Integration
Tests can be integrated into CI/CD pipelines:
# Example GitHub Actions
- name: Run Backend Tests
run: python run_tests.py --backend
- name: Run Docker Tests
run: python run_tests.py --docker
- name: Run All Tests
run: python run_tests.py --pytest
π Test Documentation
Each test file includes:
- Purpose and scope
- Dependencies and setup
- Expected outcomes
- Error scenarios
- Cleanup procedures
π― Success Criteria
Tests are considered successful when:
- β All test files execute without errors
- β API endpoints respond correctly
- β OCR pipeline processes documents
- β Database operations complete
- β Docker containers build and run
- β Deployment configurations validate
- β Error handling works as expected
Last Updated: Project reorganization completed
Test Coverage: Comprehensive backend and docker testing
Status: β
Ready for production deployment