This directory contains comprehensive testing scripts for the SAMO Emotion Detection API.
Run the setup script to configure your testing environment:
./scripts/testing/setup_test_environment.shThis will:
- Prompt you to select an API endpoint
- Set up environment variables
- Create a
.envfile for persistent configuration - Test the configuration
After setup, you can run any of the testing scripts:
# Comprehensive API testing
python scripts/testing/test_cloud_run_api_endpoints.py
# Quick health check
python scripts/testing/check_model_health.py
# Model status verification
python scripts/testing/test_model_status.pyThe testing scripts support multiple environment variables for flexibility:
API_BASE_URL- Primary API URLCLOUD_RUN_API_URL- Alternative API URLMODEL_API_BASE_URL- Model-specific API URLREQUEST_TIMEOUT- Request timeout in seconds (default: 30)RATE_LIMIT_REQUESTS- Number of requests for rate limiting tests (default: 10)
All scripts support the --base-url argument to override the configured URL:
python scripts/testing/test_cloud_run_api_endpoints.py --base-url "https://your-custom-api.com"- Minimal API (Production):
https://samo-emotion-api-minimal-71517823771.us-central1.run.app - Optimized API (Staging):
https://samo-emotion-api-optimized-secure-71517823771.us-central1.run.app
Comprehensive API testing including:
- Health endpoint validation
- Emotion detection functionality
- Model loading verification
- Invalid input handling
- Security features (rate limiting)
- Performance metrics
Output: Detailed JSON report in test_reports/cloud_run_api_test_results.json
Quick health check for:
- API availability
- Model loading status
- Basic prediction functionality
Output: Console status with pass/fail indicators
Detailed model status verification:
- Health endpoint
- Emotions support
- Model type and service info
- Prediction endpoint
Output: Console summary with detailed status
All scripts use centralized configuration through:
test_config.py- Primary configuration managementconfig.py- Alternative configuration with additional features
Consistent API client with:
- Automatic retry logic
- Error handling
- Request/response logging
- Authentication support
- Console Output: Real-time test progress and results
- JSON Reports: Detailed test results for analysis
- Exit Codes: Proper exit codes for CI/CD integration
The testing suite includes:
- API key authentication
- Rate limiting tests
- Security header validation
- Input sanitization testing
Comprehensive error handling for:
- Network connectivity issues
- API response errors
- Configuration problems
- Invalid input scenarios
Performance metrics include:
- Response time measurements
- Success rate calculation
- Throughput analysis
- Error rate monitoring
- Create a new test script in this directory
- Import the centralized configuration:
from test_config import create_test_config, create_api_client
- Use the API client for consistent request handling
- Follow the existing test structure and output format
To modify configuration behavior:
- Update
test_config.pyfor core functionality - Update
config.pyfor additional features - Ensure backward compatibility
- Update this README if needed
- No API URL configured: Run the setup script or set environment variables
- Connection errors: Check network connectivity and API availability
- Authentication failures: Verify API key configuration
- Timeout errors: Increase
REQUEST_TIMEOUTenvironment variable
Enable verbose output with the --verbose flag:
python scripts/testing/test_cloud_run_api_endpoints.py --verboseThe testing scripts are designed for CI/CD integration:
- Exit Codes: 0 for success, 1 for failure
- JSON Output: Machine-readable test results
- Environment Variables: Easy configuration in CI/CD pipelines
- Logging: Structured logging for monitoring
Example CI/CD usage:
# GitHub Actions example
- name: Run API Tests
env:
API_BASE_URL: ${{ secrets.API_BASE_URL }}
run: |
python scripts/testing/test_cloud_run_api_endpoints.py
python scripts/testing/check_model_health.py