DCRM API Testing Guide
π― Two Ways to Test the API
You have two easy options to test your DCRM API:
Option 1: HTML Frontend (Visual Testing) β RECOMMENDED
Steps:
Start the API server:
python dcrm_api.pyWait for:
Uvicorn running on http://0.0.0.0:5000Open the test frontend:
- Simply double-click
test_frontend.htmlin File Explorer - OR open it in your browser:
file:///c:/codes/dcrm/pranit/csv_kpi/combined/test_frontend.html
- Simply double-click
Test the API:
- Enter Breaker ID (default is already filled)
- Click "Choose CSV File" and select
df3_final (1).csv - Click "Upload & Analyze"
- Wait 30-60 seconds for processing
- View the complete JSON response!
Features:
β
Beautiful visual interface
β
Shows key metrics (Health Score, CBHI, Findings)
β
Displays complete JSON response
β
Copy JSON to clipboard
β
Download JSON as file
β
Real-time status updates
β
Error handling with clear messages
Option 2: Python Test Script (Command Line)
Steps:
Start the API server (in one terminal):
python dcrm_api.pyRun the test script (in another terminal):
python test_api.py
What it does:
β
Tests health check endpoint
β
Uploads sample CSV
β
Verifies analysis works
β
Tests error handling
β
Saves results to test_response.json
Option 3: FastAPI Built-in Docs (Interactive)
Steps:
Start the API server:
python dcrm_api.pyOpen Swagger UI in browser:
http://localhost:5000/docsTest the endpoint:
- Click on
POST /api/circuit-breakers/{breaker_id}/tests/upload - Click "Try it out"
- Enter breaker_id:
6926e63d4614721a79b7b24e - Upload CSV file
- Click "Execute"
- View response!
- Click on
π Quick Comparison
| Method | Best For | Pros | Cons |
|---|---|---|---|
| HTML Frontend | Visual testing, demos | Beautiful UI, easy to use, copy/download | Need to open in browser |
| Python Script | Automated testing, CI/CD | Automated, saves to file | Command line only |
| Swagger UI | API exploration | Interactive docs, built-in | Less visual appeal |
π‘ Recommended Workflow
- Development: Use HTML Frontend (
test_frontend.html) - Automated Testing: Use Python Script (
test_api.py) - API Documentation: Use Swagger UI (
/docs)
π Expected Output
All methods will return JSON with this structure:
{
"breakerId": "6926e63d4614721a79b7b24e",
"healthScore": 95,
"cbhi": {
"score": 95,
"history": [...]
},
"kpis": [...],
"phaseWiseAnalysis": [...],
"aiVerdict": {...},
"waveform": [...],
"findings": "Minor Contact Pitting & Bounce"
}
β οΈ Troubleshooting
HTML Frontend shows "Cannot connect to API":
- Make sure API server is running (
python dcrm_api.py) - Check if server is on port 5000
- Look for CORS errors in browser console (F12)
Python test script fails:
- Ensure
df3_final (1).csvexists in the directory - Check if API server is running
- Verify port 5000 is not blocked
Analysis takes too long:
- Normal processing time is 30-60 seconds
- AI processing (Gemini) can be slow
- Check your internet connection
π Quick Start (All-in-One)
# Terminal 1: Start API
python dcrm_api.py
# Terminal 2: Run automated test
python test_api.py
# Browser: Open visual test
# Double-click test_frontend.html
That's it! You're ready to test your DCRM API! π