Spaces:
Sleeping
Sleeping
API Test
This directory contains comprehensive tests for the API functionality.
Test Structure
test_agent.py- Tests for the LLM agent functionalitytest_api.py- Tests for the FastAPI endpointstest_utils.py- Tests for S3 utility functionstest_db_connection.py- Tests for database connection management
Running Tests
Quick Tests (Recommended for CI/CD)
# From project root
pnpm test:api
# Or directly
cd api
pytest tests/ -v -m "not database"
All Tests (Including Database)
# From project root
pnpm test:api:all
# Or directly
cd api
pytest tests/ -v
Database Tests Only
# From project root
pnpm test:api:db
# Or directly
cd api
pytest tests/ -v -m "database"
Run Specific Test File
cd api
pytest tests/test_agent.py -v
Run with Coverage
cd api
pytest tests/ --cov=llm --cov=server --cov-report=html
Test Categories
- Unit Tests: Test individual functions and components
- Integration Tests: Test API endpoints and data flow
- Error Handling: Test error scenarios and edge cases
- Database Tests: Test database connection and management (marked with
@pytest.mark.database)
Test Environment
Tests use mocked external services (S3, LLM, Database) to ensure:
- ⚡ Fast execution (~2 seconds for non-database tests)
- 🔒 No external dependencies
- ✅ Consistent results
- 💰 No costs incurred
GitHub Actions Integration
Tests are automatically run in GitHub Actions:
- Pull Requests: All tests run to catch issues early
- Deployment: Tests must pass before deploying to Hugging Face Spaces
- Coverage: Test coverage is tracked and reported
Adding New Tests
- Create test file:
test_<module_name>.py - Follow naming convention:
test_<function_name> - Use descriptive test names
- Mock external dependencies
- Test both success and error cases
- Mark database tests with
@pytest.mark.database