Spaces:
Sleeping
Sleeping
File size: 7,055 Bytes
c09e844 |
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# 🧪 Testing Guide - Step by Step
## Pre-requisites
```bash
# 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:
1. Open browser: **http://localhost:8000/docs**
2. 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:
1. Go to: **http://localhost:8000/register**
2. Fill in:
- Username: `testuser1`
- Email: `test@example.com`
- Password: `password123`
3. Click "Register"
4. Should redirect to login page
### Expected Result:
- Green success message appears
- Redirects to `/login` after 1.5 seconds
**Status:** ✅ PASS / ❌ FAIL
---
## ✅ Test 3: User Login
### Steps:
1. Go to: **http://localhost:8000/login**
2. Enter:
- Username: `testuser1`
- Password: `password123`
3. 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:
1. On dashboard, select a product from dropdown (e.g., "Điện thoại iPhone 15 Pro Max")
2. Make sure "Single Comment" tab is active
3. 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!
```
4. 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:
1. Select a product from dropdown
2. Click "Upload CSV" tab
3. Click "Choose File" and select `sample_comments.csv`
4. File name should display: "Selected: sample_comments.csv"
5. 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:
1. After batch prediction (Test 5), scroll to results table
2. 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:
1. Go to: **http://localhost:8000/docs**
2. Find "POST /api/auth/login" endpoint
3. Click "Try it out"
4. Enter:
```json
username: testuser1
password: password123
```
5. Click "Execute"
### Expected Result:
- Response Code: 200
- Response body contains:
```json
{
"access_token": "eyJ0eXAiOiJKV1Q...",
"token_type": "bearer"
}
```
### Test authenticated endpoint:
1. Copy the `access_token` value
2. Click "Authorize" button (top-right, with lock icon)
3. Paste token in "Value" field: `Bearer YOUR_TOKEN_HERE`
4. Click "Authorize" then "Close"
5. Try "GET /api/auth/me" endpoint
6. Click "Try it out" → "Execute"
### Expected Result:
- Response Code: 200
- Shows your user info (username, email, etc.)
**Status:** ✅ PASS / ❌ FAIL
---
## ✅ Test 8: Logout
### Steps:
1. On dashboard, click "Logout" button (top-right, red button)
### Expected Result:
- Redirects to `/login` page
- Token is cleared from browser storage
**Status:** ✅ PASS / ❌ FAIL
---
## ✅ Test 9: Protected Route (Authentication Check)
### Steps:
1. After logout, try to access: **http://localhost:8000/dashboard**
2. Open browser console (F12)
### Expected Result:
- JavaScript checks for token
- Redirects back to `/login` because no token exists
**Status:** ✅ PASS / ❌ FAIL
---
## ✅ Test 10: Database Persistence
### Steps:
1. Stop the server (Ctrl+C)
2. Start it again: `python main.py`
3. Go to login page
4. 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"
```bash
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.csv` is available
- [ ] You understand the architecture (routers, services, models)
- [ ] You can explain how to replace dummy ML model
### Demo Flow:
1. **Show Swagger UI** - explain automatic generation (bonus!)
2. **Register → Login** - show JWT authentication
3. **Single prediction** - demonstrate UI
4. **Batch CSV** - show visualizations (chart + word cloud)
5. **Download CSV** - export results
6. **Explain architecture** - separation of concerns
Good luck! 🎓
|