T2M API Testing Guide
This directory contains comprehensive test scripts for the T2M API endpoints.
Files
test_api_endpoints.py- Main test script with full endpoint coveragerun_api_tests.py- Simple runner using configuration filetest_config.json- Configuration file for API settingsrequirements-test.txt- Python dependencies for testing
Quick Start
1. Install Dependencies
pip install -r requirements-test.txt
2. Configure API Settings
Edit test_config.json with your API details:
{
"api_config": {
"base_url": "https://your-api-domain.com/api/v1",
"token": "your-actual-bearer-token"
}
}
3. Run Tests
Option A: Using configuration file
python run_api_tests.py
Option B: Direct command line
python test_api_endpoints.py --base-url https://your-api-domain.com/api/v1 --token your-token
Option C: Token from file
echo "your-token-here" > token.txt
python test_api_endpoints.py --base-url https://your-api-domain.com/api/v1 --token-file token.txt
Test Coverage
The test script covers all major API endpoints:
π Public Endpoints (No Auth Required)
GET /auth/health- Authentication service healthGET /system/health- System health check
π Authentication Endpoints
GET /auth/status- Authentication statusGET /auth/profile- User profileGET /auth/permissions- User permissionsGET /auth/test/protected- Protected endpoint testGET /auth/test/verified- Verified user testPOST /auth/verify- Token verification
π File Management Endpoints
POST /files/upload- Single file uploadGET /files- List files with paginationGET /files/{id}- File detailsGET /files/{id}/metadata- File metadataGET /files/{id}/thumbnail- File thumbnailGET /files/stats- File statisticsDELETE /files/{id}- File deletion (cleanup)
βοΈ Job Management Endpoints
GET /jobs- List jobsGET /jobs/{id}- Job detailsGET /jobs/{id}/logs- Job logsPOST /jobs/{id}/cancel- Cancel job (cleanup)DELETE /jobs/{id}- Delete job (cleanup)
π₯οΈ System Monitoring Endpoints
GET /system/metrics- System metricsGET /system/queue- Queue statusGET /system/cache- Cache informationGET /system/cache/metrics- Cache metricsGET /system/cache/report- Cache reportGET /system/performance- Performance summaryGET /system/connections- Connection statisticsGET /system/async- Async statisticsGET /system/deduplication- Deduplication statistics
π₯ Video Processing Endpoints
POST /videos/generate- Generate videoGET /videos/{id}/status- Video job statusGET /videos/{id}/metadata- Video metadataGET /videos/{id}/thumbnail- Video thumbnail
Test Results
After running tests, you'll get:
- Console output with real-time test results
- Summary statistics showing pass/fail rates
- JSON report saved to
api_test_results.json
Example Output
π Starting T2M API Endpoint Tests
Base URL: https://api.example.com/api/v1
Token: Provided
π Testing Public Endpoints
β
PASS GET /auth/health
Status: 200
β
PASS GET /system/health
Status: 200
π Testing Authentication Endpoints
β
PASS GET /auth/status
Status: 200
β
PASS GET /auth/profile
Status: 200
π TEST SUMMARY
==================================================
Total Tests: 25
Passed: 23 β
Failed: 2 β
Success Rate: 92.0%
Test Features
π§Ή Automatic Cleanup
- Deletes uploaded test files
- Cancels/deletes created jobs
- Prevents resource accumulation
π Comprehensive Reporting
- Real-time console feedback
- Detailed JSON results file
- Pass/fail statistics
- Error details for debugging
π§ Flexible Configuration
- Command line arguments
- Configuration file support
- Token file support
- Environment variable support
π‘οΈ Error Handling
- Network timeout handling
- Graceful failure handling
- Detailed error reporting
- Resource cleanup on failure
Advanced Usage
Testing Specific Endpoints
You can modify the test script to focus on specific endpoint groups:
# Only test public endpoints
tester.test_public_endpoints()
# Only test file operations
tester.test_file_endpoints()
# Only test system monitoring
tester.test_system_endpoints()
Custom Test Data
Modify test_config.json to customize test parameters:
{
"test_data": {
"video_generation": {
"prompt": "Your custom test prompt",
"duration": 10,
"quality": "1080p"
}
}
}
Environment Variables
You can also use environment variables:
export T2M_API_URL="https://your-api-domain.com/api/v1"
export T2M_API_TOKEN="your-token-here"
python test_api_endpoints.py --base-url $T2M_API_URL --token $T2M_API_TOKEN
Troubleshooting
Common Issues
Connection Errors
- Verify the base URL is correct
- Check network connectivity
- Ensure API server is running
Authentication Errors
- Verify token is valid and not expired
- Check token format (should be just the token, not "Bearer token")
- Ensure user has required permissions
Rate Limiting
- Tests may hit rate limits on busy servers
- Add delays between requests if needed
- Run tests during off-peak hours
Resource Cleanup Failures
- Some resources may not be cleaned up if tests fail
- Manually delete test files/jobs if needed
- Check API logs for cleanup issues
Debug Mode
For more detailed debugging, modify the test script to add verbose logging:
import logging
logging.basicConfig(level=logging.DEBUG)
Integration with CI/CD
The test script returns appropriate exit codes for CI/CD integration:
# Run tests and capture exit code
python test_api_endpoints.py --base-url $API_URL --token $API_TOKEN
if [ $? -eq 0 ]; then
echo "All tests passed"
else
echo "Some tests failed"
exit 1
fi
Contributing
To add new test cases:
- Add the endpoint to the appropriate test method
- Follow the existing pattern for error handling
- Add cleanup logic if the endpoint creates resources
- Update this README with the new endpoint coverage