TestAPI
This module contains tests for the Flask API endpoints in the src.api module.
The tests verify the functionality of the /anisearchmodel/manga endpoint, ensuring it handles valid inputs, missing fields, and internal server errors correctly. The tests use a mock for the get_similarities function to simulate different scenarios.
The test suite includes
- Testing successful manga similarity search with valid inputs
- Testing error handling for invalid inputs (missing fields, invalid model names)
- Testing internal server error handling
- Parameterized tests for different invalid input scenarios
The tests use pytest fixtures for the Flask test client and model name configuration.
client
¶
Fixture to create a test client for the Flask application.
RETURNS | DESCRIPTION |
---|---|
None
|
Generator[FlaskClient, None, None]: A Flask test client instance that can be used to make requests to the application endpoints. |
Source code in tests/test_api.py
test_get_manga_similarities_internal_error
¶
Test the /anisearchmodel/manga endpoint for internal server errors.
Verifies that the endpoint returns a 500 status code and an error message when an exception occurs during processing.
PARAMETER | DESCRIPTION |
---|---|
client
|
Flask test client fixture
TYPE:
|
model_name
|
Model name fixture from command line options
TYPE:
|
The test
- Creates a valid payload
- Mocks get_similarities to raise an exception
- Verifies the 500 status code and error message
Source code in tests/test_api.py
test_get_manga_similarities_invalid_input
¶
test_get_manga_similarities_invalid_input(client: FlaskClient, payload: dict, expected_error: str) -> None
Test the /anisearchmodel/manga endpoint with invalid inputs.
Verifies that the endpoint returns a 400 status code and an error message when the input is invalid.
PARAMETER | DESCRIPTION |
---|---|
client
|
Flask test client fixture
TYPE:
|
payload
|
Test payload with invalid input combinations
TYPE:
|
expected_error
|
Expected error message for the given invalid input
TYPE:
|
The test cases verify
- Missing model name
- Invalid model name
- Missing description
Source code in tests/test_api.py
test_get_manga_similarities_success
¶
Test the /anisearchmodel/manga endpoint with valid input.
Verifies that the endpoint returns a 200 status code and the expected list of similarities when provided with a valid model and description.
PARAMETER | DESCRIPTION |
---|---|
client
|
Flask test client fixture
TYPE:
|
model_name
|
Model name fixture from command line options
TYPE:
|
The test
- Creates a payload with valid model name and description
- Mocks the get_similarities function to return predefined results
- Verifies the response status code and structure of returned data