Overview
The ExpireEye Backend API uses FastAPI’s built-in interactive documentation for testing during development. This guide covers how to effectively test endpoints using Swagger UI, manual testing strategies, and common test scenarios.Interactive API Testing with Swagger UI
FastAPI automatically generates interactive API documentation at/docs that you can use to test all endpoints without writing code.
Accessing Swagger UI
-
Start the development server:
-
Open your browser and navigate to:
Remember the
/api prefix - the API root path is configured in app/main.py:31. All endpoints are automatically prefixed with /api.Understanding the Interface
The Swagger UI organizes endpoints by tags:- auth - Authentication endpoints (login, signup)
- Product Inventory - Product management
- User Inventory - User’s product inventory
- User Profile - User account management
- Notifications - Notification system
- YOLO Detection - Image-based product detection
- Statistics - Usage and expiry statistics
- Status - Health check endpoint
- QR Code - QR code scanning
Testing Authentication Flow
Create a Test Account
- Find the POST /api/auth/signup endpoint under the “auth” section
- Click “Try it out”
- Fill in the request body:
- Click “Execute”
- Check the response - you should receive a
200status with a token
Password must be at least 6 characters (validated in
app/routers/auth.py:85-88).Copy the Authentication Token
From the signup response, copy the This JWT token is valid for 4000 minutes (configured in
token value:app/utils/jwt.py:9).Authorize Future Requests
- Click the “Authorize” button at the top right of the Swagger UI
- In the “Value” field, enter:
Bearer <your-token> - Click “Authorize”, then “Close”
Testing Protected Endpoints
Once authorized, you can test any protected endpoint. Here are common test scenarios:Product Detection (YOLO)
Test the image detection feature:Test Image Detection Endpoint
Test Image Detection Endpoint
Endpoint: What Happens:
POST /api/yolo/detectSteps:- Locate the endpoint under “YOLO Detection”
- Click “Try it out”
- Click “Choose File” and select an image containing food products
- Click “Execute”
- Image is saved to the
uploads/directory (app/routers/detection.py:22-23) - YOLO model processes the image
- Detected objects are returned with confidence scores
The endpoint requires authentication. The user ID is extracted from the JWT token (
app/routers/detection.py:18).QR Code Scanning
Test QR code detection:Test QR Code Scanner
Test QR Code Scanner
Endpoint: If no QR detected:The QR code detector uses OpenCV (
POST /api/qrSteps:- Generate a test QR code (use any online QR code generator)
- Download the QR code image
- In Swagger UI, find POST /api/qr under “QR Code”
- Click “Try it out”
- Upload the QR code image
- Click “Execute”
app/main.py:146-159).User Inventory Management
Test product inventory operations:Test Adding Products to Inventory
Test Adding Products to Inventory
Endpoint:
POST /api/product/user-inventorySteps:- Ensure you’re authorized (see authentication steps above)
- Find the endpoint under “User Inventory”
- Click “Try it out”
- Enter product data:
- Click “Execute”
Statistics and Analytics
Test Statistics Endpoints
Test Statistics Endpoints
Endpoint: This helps test that the scheduled expiry checking job is working (configured in
GET /api/stats/expiry-summaryRetrieve expiry statistics for the authenticated user:Steps:- Find GET /api/stats/expiry-summary
- Click “Try it out”
- Click “Execute”
app/main.py:173).Manual Testing Strategies
Using cURL
Test endpoints from the command line:Using Postman
- Import the OpenAPI spec from
http://localhost:8000/api/openapi.json - Create an environment with variables:
base_url:http://localhost:8000/apitoken: Your JWT token
- Set Authorization header:
Bearer {{token}} - Test endpoints using the imported collection
Using HTTPie
A more user-friendly alternative to cURL:Testing Error Scenarios
Authentication Errors
Test Missing Authorization Header
Test Missing Authorization Header
Test Invalid Token
Test Invalid Token
Test: Use an expired or malformed tokenToken validation happens in
- Click “Authorize” and enter:
Bearer invalid_token_123 - Try any protected endpoint
401 Unauthorizedapp/main.py:86-93.Test Invalid Credentials
Test Invalid Credentials
Test: Login with wrong passwordExpected Response: Password verification uses bcrypt (
- Call POST /api/auth/login with incorrect password
401 Unauthorizedapp/routers/auth.py:31-32).Validation Errors
Test Required Field Validation
Test Required Field Validation
Test: Submit incomplete dataExpected Response: Custom validation error handler is in
- Call POST /api/auth/signup with missing required fields:
422 Unprocessable Entityapp/main.py:99-115.File Upload Errors
Test Invalid File Upload
Test Invalid File Upload
Test: Upload an invalid file type
- Call POST /api/yolo/detect with a non-image file
- Upload a
.txtor.pdffile instead
500 Internal Server ErrorThe YOLO service will fail to process the file and return an error (app/routers/detection.py:26-28).Testing WebSocket Notifications
The API includes a WebSocket endpoint for real-time notifications:- Connect with valid token
- Connect with invalid/missing token
- Receive notifications when products expire
- Handle connection timeouts
WebSocket endpoint is at
/ws/notification and requires the access_token query parameter (app/main.py:196-200).Common Test Workflows
Complete User Journey Test
Scheduled Job Testing
Wait for the scheduler to run (every 10 seconds in development) and check:- Console logs for “Scheduler started” message
- Notifications for products expiring soon
- Statistics update reflecting current expiry status
check_product_expiry executes.
Next Steps
Local Development
Set up your development environment
Troubleshooting
Solve common testing issues