102 lines
2.6 KiB
Markdown
102 lines
2.6 KiB
Markdown
# Sim-Search API Tests
|
|
|
|
This directory contains tests for the Sim-Search API.
|
|
|
|
## Test Files
|
|
|
|
- `test_api.py`: Tests the core functionality of the API, including authentication, query processing, search execution, and report generation.
|
|
|
|
## Running Tests
|
|
|
|
### Using pytest directly
|
|
|
|
```bash
|
|
# Run all tests
|
|
pytest
|
|
|
|
# Run a specific test file
|
|
pytest tests/test_api.py
|
|
|
|
# Run tests with verbose output
|
|
pytest -v tests/test_api.py
|
|
|
|
# Run tests with verbose output and exit on first failure
|
|
pytest -xvs tests/test_api.py
|
|
|
|
# Run tests with coverage report
|
|
pytest --cov=app --cov-report=term --cov-report=html tests/test_api.py
|
|
```
|
|
|
|
### Using the run_tests.py script
|
|
|
|
We provide a convenient script to run the tests with various options:
|
|
|
|
```bash
|
|
# Run all tests
|
|
python run_tests.py
|
|
|
|
# Run with verbose output
|
|
python run_tests.py --verbose
|
|
|
|
# Run with -xvs flag (exit on first failure, verbose, show output)
|
|
python run_tests.py --xvs
|
|
|
|
# Run with coverage report
|
|
python run_tests.py --coverage
|
|
|
|
# Run a specific test file
|
|
python run_tests.py --test-file tests/test_api.py
|
|
```
|
|
|
|
### Using the test_api_curl.sh script
|
|
|
|
For manual testing of the API endpoints using curl commands:
|
|
|
|
```bash
|
|
# Make the script executable
|
|
chmod +x test_api_curl.sh
|
|
|
|
# Run the script
|
|
./test_api_curl.sh
|
|
```
|
|
|
|
This script will test all the API endpoints in sequence, including:
|
|
- Authentication (register, login)
|
|
- Query processing and classification
|
|
- Search execution and retrieval
|
|
- Report generation and management
|
|
|
|
## Test Database
|
|
|
|
The tests use a separate SQLite database (`test.db`) to avoid affecting the production database. This database is created and destroyed during the test run.
|
|
|
|
## Test User
|
|
|
|
The tests create a test user with the following credentials:
|
|
- Email: test@example.com
|
|
- Password: password123
|
|
- Full Name: Test User
|
|
|
|
## Test Coverage
|
|
|
|
To generate a test coverage report:
|
|
|
|
```bash
|
|
pytest --cov=app --cov-report=term --cov-report=html tests/
|
|
```
|
|
|
|
This will generate a coverage report in the terminal and an HTML report in the `htmlcov` directory.
|
|
|
|
## Continuous Integration
|
|
|
|
These tests can be integrated into a CI/CD pipeline to ensure that the API is working correctly before deployment.
|
|
|
|
## Troubleshooting
|
|
|
|
If you encounter issues with the tests:
|
|
|
|
1. Make sure the API server is not running when running the tests, as they will start their own instance.
|
|
2. Check that the test database is not locked by another process.
|
|
3. Ensure that all dependencies are installed (`pip install -r requirements.txt`).
|
|
4. If you're getting authentication errors, make sure the JWT secret key is set correctly in the test environment.
|