SUMM.AI API
This package contains tests of the integreat_cms.summ_ai_api
app
SUMM.AI Test
- async tests.summ_ai_api.summ_ai_test.test_auto_translate_easy_german(login_role_user_async: tuple[AsyncClient, str], settings: SettingsWrapper, aiohttp_server: Callable, caplog: LogCaptureFixture) None [source]
This test checks whether the SUMM.AI API client works as expected
- Parameters:
login_role_user_async (tuple[AsyncClient, str]) – The fixture providing the http client and the current role (see
login_role_user()
)settings (SettingsWrapper) – The fixture providing the django settings
aiohttp_server (Callable) – The fixture providing the dummy aiohttp server used for faking the SUMM.AI API server
caplog (LogCaptureFixture) – The
caplog
fixture
- Return type:
None
- tests.summ_ai_api.summ_ai_test.test_check_rate_limit_exceeded(settings: SettingsWrapper, caplog: LogCaptureFixture) None [source]
Test for check_rate_limit_exceeded method. Tests if return is True when response-status = 429 (too many requests) or 529 (site overloaded), otherwise False
- Parameters:
settings (SettingsWrapper) – The Django settings
caplog (LogCaptureFixture) – Fixture for asserting log messages in tests (see
caplog
)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_missing_translation(settings: SettingsWrapper, aiohttp_raw_server: Callable) None [source]
Test correct handling for a json response without the translated_text key by SUMM.AI. Tests if SummAiRuntimeError is raised when invalid JSON is sent as response.
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_patient_task_queue_hit_rate_limit() None [source]
Test for PatientTaskQueue Class. It tests that when the maximum number of parallel requests to the summ_ai_api has been exceeded (rate limit exceeded), a defined time is waited until the next task object is returned via __anext__().
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_patient_task_queue_max_retries() None [source]
Test for PatientTaskQueue Class. Tests that it stops early when requests are not successful after a cooldown, resulting in another cooldown repeatedly.
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_patient_task_queue_normal_deque() None [source]
Test for PatientTaskQueue Class. Tests that a first-in/first out (fifo) deque-queue is built from a task-list Checks that __anext__() removes one element each from the queue
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_summ_ai_error_handling(login_role_user_async: tuple[AsyncClient, str], settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
This test checks whether the error handling of the SUMM.AI API client works as expected.
- Parameters:
login_role_user_async (tuple[AsyncClient, str]) – The fixture providing the http client and the current role (see
login_role_user()
)settings (SettingsWrapper) – The fixture providing the django settings
aiohttp_raw_server (Callable) – The fixture providing the dummy aiohttp server used for faking the SUMM.AI API server
caplog (LogCaptureFixture) – The
caplog
fixture
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_translate_text_field_ddos_defense(settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
see
test_translate_text_field_successful_translation()
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
caplog (LogCaptureFixture)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_translate_text_field_hit_rate_limit(settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
see
test_translate_text_field_successful_translation()
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
caplog (LogCaptureFixture)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_translate_text_field_internal_server_error(settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
see
test_translate_text_field_successful_translation()
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
caplog (LogCaptureFixture)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_translate_text_field_successful_translation(settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
- Parameters:
settings (SettingsWrapper) – The Django settings
aiohttp_raw_server (Callable) – The fixture providing the dummy aiohttp server used for faking the SUMM.AI API server
caplog (LogCaptureFixture) – Fixture for asserting log messages in tests (see
caplog
)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_translate_text_forbidden(settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
tests 403 response see
test_translate_text_field_successful_translation()
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
caplog (LogCaptureFixture)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_translate_text_with_empty_text_field(settings: SettingsWrapper, aiohttp_raw_server: Callable, caplog: LogCaptureFixture) None [source]
see
test_translate_text_field_successful_translation()
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
caplog (LogCaptureFixture)
- Return type:
None
- async tests.summ_ai_api.summ_ai_test.test_unexpected_html(settings: SettingsWrapper, aiohttp_raw_server: Callable) None [source]
Test correct handling for an unexpected HTML response by SUMM.AI. Tests if SummAiInvalidJSONError is raised when unexpected HTML is sent as response.
- Parameters:
settings (SettingsWrapper)
aiohttp_raw_server (Callable)
- Return type:
None
- tests.summ_ai_api.summ_ai_test.test_validate_response_invalid() None [source]
Test for validate_response method. Should throw exception when ‘translated_text’ is not found in request.
- Return type:
None
Utils
- class tests.summ_ai_api.utils.MockedRequest[source]
Bases:
object
Helper class mocking request, used for creating a SummAiApiclient instance. Region-property is needed therefore.
- tests.summ_ai_api.utils.enable_summ_api(region_slug: str) None [source]
Enable SUMM.AI in the test region
- Parameters:
region_slug (str) – The slug of the region in which we want to enable SUMM.AI
- Return type:
None
- tests.summ_ai_api.utils.get_changed_pages(settings: SettingsWrapper, ids: list[int]) list[dict] [source]
Load the changed pages with the specified ids from the database
- tests.summ_ai_api.utils.make_mock_summ_ai_server(response_data: dict, status: int = 200) Callable [source]
Creates a mock of SummAiServer-(Response)
- tests.summ_ai_api.utils.make_mock_summ_ai_server_rate_limited() Application [source]
Creates a mock of SUMM.AI server with rate limiting
- Returns:
Mocked SUMM.AI server with rate limiting
- Return type:
Application