Hoghoghi / tests /README.md
Really-amin's picture
Upload 74 files
77aec31 verified
|
raw
history blame
5.89 kB

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 endpoints
  • test_ocr_pipeline.py - Tests OCR pipeline functionality
  • test_db_connection.py - Tests database connectivity

Fix Validation Tests:

  • test_ocr_fixes.py - Validates OCR pipeline fixes
  • test_hf_deployment_fixes.py - Validates Hugging Face deployment fixes
  • validate_fixes.py - Comprehensive fix validation

Structure and Frontend Tests:

  • test_structure.py - Tests project structure integrity
  • verify_frontend.py - Tests frontend integration

Docker Tests (tests/docker/)

Docker Setup Tests:

  • test_docker.py - Tests Docker container functionality
  • validate_docker_setup.py - Validates Docker configuration
  • simple_validation.py - Basic Docker validation

Deployment Tests:

  • test_hf_deployment.py - Tests Hugging Face deployment
  • deployment_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

  1. Import Errors

    # Ensure you're in the project root
    cd legal_dashboard_ocr
    export PYTHONPATH=$PYTHONPATH:$(pwd)
    
  2. Missing Dependencies

    pip install -r requirements.txt
    
  3. Database Connection Issues

    # Ensure database directory exists
    mkdir -p /tmp/data
    
  4. 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

  1. Create test file in tests/backend/
  2. Follow naming convention: test_*.py
  3. Use pytest fixtures and assertions
  4. Add to test runner if needed

Docker Tests

  1. Create test file in tests/docker/
  2. Test Docker-specific functionality
  3. Validate deployment configurations
  4. 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