FLASK_APP / docs /TESTING_GUIDE.md
pranit144's picture
Upload 97 files
e38de99 verified

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:

  1. Start the API server:

    python dcrm_api.py
    

    Wait for: Uvicorn running on http://0.0.0.0:5000

  2. Open the test frontend:

    • Simply double-click test_frontend.html in File Explorer
    • OR open it in your browser: file:///c:/codes/dcrm/pranit/csv_kpi/combined/test_frontend.html
  3. 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:

  1. Start the API server (in one terminal):

    python dcrm_api.py
    
  2. Run 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:

  1. Start the API server:

    python dcrm_api.py
    
  2. Open Swagger UI in browser:

    http://localhost:5000/docs
    
  3. Test 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!

πŸ” 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

  1. Development: Use HTML Frontend (test_frontend.html)
  2. Automated Testing: Use Python Script (test_api.py)
  3. 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).csv exists 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! πŸš€