2.3 KiB
2.3 KiB
Testing Guide for API Response Utilities
This guide helps you test the new unified response format utilities before merging the PR.
Quick Test Script
Run the simple test script to verify basic functionality:
cd backend
python test_response_utilities.py
This will test:
- ✅ Import functionality
- ✅
success_response()function - ✅
error_response()function - ✅
paginated_response()function
Django Unit Tests
Run the comprehensive unit tests:
cd backend
python manage.py test igny8_core.api.tests.test_response
Expected output: All 15 test cases should pass.
Test the /api/ping/ Endpoint
Option 1: Using curl (if server is running)
# Test the ping endpoint
curl http://localhost:8011/api/ping/
# Expected response:
# {
# "success": true,
# "data": {
# "pong": true,
# "time": "2025-01-XX...",
# "version": "1.0.0"
# },
# "message": "API is live"
# }
Option 2: Using Postman or Browser
- Start Django server:
python manage.py runserver - Navigate to:
http://localhost:8000/api/ping/ - Verify response has
success: trueanddatafields
Option 3: Using Python requests
import requests
response = requests.get('http://localhost:8011/api/ping/')
data = response.json()
assert data['success'] == True
assert 'data' in data
assert 'pong' in data['data']
print("✅ Ping endpoint works!")
Verification Checklist
Before merging the PR, verify:
- Quick test script passes (
python test_response_utilities.py) - Django unit tests pass (
python manage.py test igny8_core.api.tests.test_response) /api/ping/endpoint returns unified format- No linting errors
- All imports work correctly
What to Look For
✅ Success Indicators:
- All tests pass
- Response has
success: true/falsefield - Response has
datafield (for success) orerrorfield (for errors) - No import errors
- No syntax errors
❌ Failure Indicators:
- Import errors
- Assertion errors in tests
- Missing fields in responses
- Syntax errors
Next Steps After Testing
If all tests pass:
- ✅ Merge the PR
- Continue with Section 1, Task 2 (refactoring endpoints)
- Or move to Section 2 (Authentication)
If tests fail:
- Check error messages
- Fix any issues
- Re-test
- Update PR with fixes