Spaces:
Running
Running
π§ͺ Testing Guide - Step by Step
Pre-requisites
# Make sure dependencies are installed
pip install -r requirements.txt
# Start the server
python main.py
Server should start at: http://localhost:8000
β Test 1: Access Swagger UI (API Documentation)
Steps:
- Open browser: http://localhost:8000/docs
- You should see:
- "Vietnamese Product Rating Prediction API" title
- Three sections: Authentication, Prediction, Dashboard
- All endpoints listed with descriptions
What to show teacher:
- This is automatic API documentation (bonus points!)
- Click any endpoint to see request/response schemas
- Click "Try it out" to test endpoints interactively
Status: β PASS / β FAIL
β Test 2: User Registration
Steps:
- Go to: http://localhost:8000/register
- Fill in:
- Username:
testuser1 - Email:
[email protected] - Password:
password123
- Username:
- Click "Register"
- Should redirect to login page
Expected Result:
- Green success message appears
- Redirects to
/loginafter 1.5 seconds
Status: β PASS / β FAIL
β Test 3: User Login
Steps:
- Go to: http://localhost:8000/login
- Enter:
- Username:
testuser1 - Password:
password123
- Username:
- Click "Login"
Expected Result:
- Green "Login successful!" message
- Redirects to
/dashboard - You see username in top-right corner
Status: β PASS / β FAIL
β Test 4: Single Comment Prediction
Steps:
- On dashboard, select a product from dropdown (e.g., "Δiα»n thoαΊ‘i iPhone 15 Pro Max")
- Make sure "Single Comment" tab is active
- Enter Vietnamese comment:
SαΊ£n phαΊ©m rαΊ₯t tα»t, chαΊ₯t lượng cao, ΔΓ³ng gΓ³i cαΊ©n thαΊn. RαΊ₯t hΓ i lΓ²ng! - Click "Predict Rating"
Expected Result:
- Green result box appears below
- Shows predicted rating (1-5)
- Shows confidence percentage
- Shows star rating (βββββ)
Status: β PASS / β FAIL
β Test 5: Batch CSV Prediction
Steps:
- Select a product from dropdown
- Click "Upload CSV" tab
- Click "Choose File" and select
sample_comments.csv - File name should display: "Selected: sample_comments.csv"
- Click "Predict Batch"
Expected Result:
- Results section appears with 3 components:
A) Bar Chart:
- Shows distribution of ratings (1β to 5β)
- Colored bars (red for 1-star, green for 5-star)
B) Word Cloud:
- Image showing frequent Vietnamese words
- Larger words appear more frequently in comments
C) Results Table:
- Shows all comments with predicted ratings
- Each row has: Comment | Rating | Confidence
Status: β PASS / β FAIL
β Test 6: Download CSV Results
Steps:
- After batch prediction (Test 5), scroll to results table
- Click "Download CSV" button (green button, top-right of table)
Expected Result:
- CSV file downloads automatically
- Filename format:
predictions_[timestamp].csv - File contains columns:
Comment,Predicted_Rating,Confidence
Verify downloaded file:
- Open in Excel/Notepad
- Should have all 20 comments from
sample_comments.csv - Each has a predicted rating and confidence score
Status: β PASS / β FAIL
β Test 7: Test Swagger UI Endpoints
Steps:
- Go to: http://localhost:8000/docs
- Find "POST /api/auth/login" endpoint
- Click "Try it out"
- Enter:
username: testuser1 password: password123 - Click "Execute"
Expected Result:
- Response Code: 200
- Response body contains:
{ "access_token": "eyJ0eXAiOiJKV1Q...", "token_type": "bearer" }
Test authenticated endpoint:
- Copy the
access_tokenvalue - Click "Authorize" button (top-right, with lock icon)
- Paste token in "Value" field:
Bearer YOUR_TOKEN_HERE - Click "Authorize" then "Close"
- Try "GET /api/auth/me" endpoint
- Click "Try it out" β "Execute"
Expected Result:
- Response Code: 200
- Shows your user info (username, email, etc.)
Status: β PASS / β FAIL
β Test 8: Logout
Steps:
- On dashboard, click "Logout" button (top-right, red button)
Expected Result:
- Redirects to
/loginpage - Token is cleared from browser storage
Status: β PASS / β FAIL
β Test 9: Protected Route (Authentication Check)
Steps:
- After logout, try to access: http://localhost:8000/dashboard
- Open browser console (F12)
Expected Result:
- JavaScript checks for token
- Redirects back to
/loginbecause no token exists
Status: β PASS / β FAIL
β Test 10: Database Persistence
Steps:
- Stop the server (Ctrl+C)
- Start it again:
python main.py - Go to login page
- Login with previous credentials (
testuser1/password123)
Expected Result:
- Login works (user data persisted in database)
- Dashboard loads successfully
Status: β PASS / β FAIL
π Troubleshooting
Error: "Module not found"
pip install -r requirements.txt
Error: "Port 8000 already in use"
- Kill other process using port 8000
- Or change port in
main.py:uvicorn.run(..., port=8001)
Error: "Database is locked"
- Close all instances of the application
- Delete
app/database/rating_prediction.db - Restart application (will create new database)
Word cloud doesn't show
- Check folder exists:
app/static/uploads/wordclouds/ - Check server console for errors
CSV upload fails
- Ensure CSV has "Comment" column (case-sensitive)
- Check CSV is UTF-8 encoded
- Make sure comments are not empty
π Test Results Summary
| Test | Description | Status |
|---|---|---|
| 1 | Swagger UI Access | β¬ |
| 2 | User Registration | β¬ |
| 3 | User Login | β¬ |
| 4 | Single Prediction | β¬ |
| 5 | Batch CSV Prediction | β¬ |
| 6 | CSV Download | β¬ |
| 7 | Swagger API Testing | β¬ |
| 8 | Logout | β¬ |
| 9 | Auth Protection | β¬ |
| 10 | Database Persistence | β¬ |
Fill in: β PASS / β FAIL / β οΈ PARTIAL
π― Demo Checklist for Teacher
Before presenting, make sure:
- Server is running (
python main.py) - You can access Swagger UI (http://localhost:8000/docs)
- You have a test account ready
-
sample_comments.csvis available - You understand the architecture (routers, services, models)
- You can explain how to replace dummy ML model
Demo Flow:
- Show Swagger UI - explain automatic generation (bonus!)
- Register β Login - show JWT authentication
- Single prediction - demonstrate UI
- Batch CSV - show visualizations (chart + word cloud)
- Download CSV - export results
- Explain architecture - separation of concerns
Good luck! π