File size: 6,531 Bytes
50a7bf0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# 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 coverage
- `run_api_tests.py` - Simple runner using configuration file
- `test_config.json` - Configuration file for API settings
- `requirements-test.txt` - Python dependencies for testing
## Quick Start
### 1. Install Dependencies
```bash
pip install -r requirements-test.txt
```
### 2. Configure API Settings
Edit `test_config.json` with your API details:
```json
{
"api_config": {
"base_url": "https://your-api-domain.com/api/v1",
"token": "your-actual-bearer-token"
}
}
```
### 3. Run Tests
**Option A: Using configuration file**
```bash
python run_api_tests.py
```
**Option B: Direct command line**
```bash
python test_api_endpoints.py --base-url https://your-api-domain.com/api/v1 --token your-token
```
**Option C: Token from file**
```bash
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 health
- `GET /system/health` - System health check
### π Authentication Endpoints
- `GET /auth/status` - Authentication status
- `GET /auth/profile` - User profile
- `GET /auth/permissions` - User permissions
- `GET /auth/test/protected` - Protected endpoint test
- `GET /auth/test/verified` - Verified user test
- `POST /auth/verify` - Token verification
### π File Management Endpoints
- `POST /files/upload` - Single file upload
- `GET /files` - List files with pagination
- `GET /files/{id}` - File details
- `GET /files/{id}/metadata` - File metadata
- `GET /files/{id}/thumbnail` - File thumbnail
- `GET /files/stats` - File statistics
- `DELETE /files/{id}` - File deletion (cleanup)
### βοΈ Job Management Endpoints
- `GET /jobs` - List jobs
- `GET /jobs/{id}` - Job details
- `GET /jobs/{id}/logs` - Job logs
- `POST /jobs/{id}/cancel` - Cancel job (cleanup)
- `DELETE /jobs/{id}` - Delete job (cleanup)
### π₯οΈ System Monitoring Endpoints
- `GET /system/metrics` - System metrics
- `GET /system/queue` - Queue status
- `GET /system/cache` - Cache information
- `GET /system/cache/metrics` - Cache metrics
- `GET /system/cache/report` - Cache report
- `GET /system/performance` - Performance summary
- `GET /system/connections` - Connection statistics
- `GET /system/async` - Async statistics
- `GET /system/deduplication` - Deduplication statistics
### π₯ Video Processing Endpoints
- `POST /videos/generate` - Generate video
- `GET /videos/{id}/status` - Video job status
- `GET /videos/{id}/metadata` - Video metadata
- `GET /videos/{id}/thumbnail` - Video thumbnail
## Test Results
After running tests, you'll get:
1. **Console output** with real-time test results
2. **Summary statistics** showing pass/fail rates
3. **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:
```python
# 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:
```json
{
"test_data": {
"video_generation": {
"prompt": "Your custom test prompt",
"duration": 10,
"quality": "1080p"
}
}
}
```
### Environment Variables
You can also use environment variables:
```bash
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:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```
## Integration with CI/CD
The test script returns appropriate exit codes for CI/CD integration:
```bash
# 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:
1. Add the endpoint to the appropriate test method
2. Follow the existing pattern for error handling
3. Add cleanup logic if the endpoint creates resources
4. Update this README with the new endpoint coverage |