Mt API

This package contains tests of the integreat_cms.deepl_api and integreat_cms.google_translate_api app

Deepl API Test

tests.mt_api.deepl_api_test.setup_deepl_supported_languages(source_languages: list[str], target_languages: list[str]) None[source]

Setup supported languages for DeepL

Parameters:
  • source_languages (list[str]) – The supported source languages

  • target_languages (list[str]) – The supported target languages

Return type:

None

tests.mt_api.deepl_api_test.setup_fake_deepl_api_server(mock_server: MockServer) None[source]

Setup a mocked DeepL API server with dummy response

Parameters:

mock_server (MockServer) – The fixture providing the mock http server for faking the DeepL API server

Return type:

None

tests.mt_api.deepl_api_test.test_deepl_bulk_mt_api_error(load_test_data: None, login_role_user: tuple[Client, str], error: int, settings: SettingsWrapper, mock_server: MockServer, caplog: LogCaptureFixture) None[source]

Check for error handling when DeepL API returns server error :param load_test_data: The fixture providing the test data (see load_test_data()) :param login_role_user: The fixture providing the http client and the current role (see login_role_user()) :param error: The error status to test :param settings: The fixture providing the django settings :param mock_server: The fixture providing the mock http server used for faking the DeepL API server :param caplog: The caplog fixture

Parameters:
  • load_test_data (None)

  • login_role_user (tuple[Client, str])

  • error (int)

  • settings (SettingsWrapper)

  • mock_server (MockServer)

  • caplog (LogCaptureFixture)

Return type:

None

Google Translate API Test

class tests.mt_api.google_translate_api_test.FakeClient[source]

Bases: object

Fake client to replace translate_v2.Client

tests.mt_api.google_translate_api_test.setup_fake_google_translate_api(self, request: HttpRequest, form_class: ModelFormMetaclass) None[source]

Setup a fake for Google Translate API

Parameters:
  • request (HttpRequest) – The current request

  • form_class (ModelFormMetaclass) – The CustomContentModelForm subclass of the current content type

Return type:

None

tests.mt_api.google_translate_api_test.setup_google_translate_supported_languages(source_languages: list[str], target_languages: list[str]) None[source]

Setup supported languages for Google Translate

Parameters:
  • source_languages (list[str]) – The supported source languages

  • target_languages (list[str]) – The supported target languages

Return type:

None

tests.mt_api.google_translate_api_test.test_google_translate_error(login_role_user: tuple[Client, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check for error handling

Parameters:
  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

Mt API Test

tests.mt_api.mt_api_test.mt_setup(deepl_source: list[str], deepl_target: list[str], gt_source: list[str], gt_target: list[str], settings: SettingsWrapper, mock_server: MockServer | None) None[source]

Function to set up the user language and MT providers

Parameters:
  • deepl_source (list[str]) – available source languages of DeepL

  • deepl_target (list[str]) – available target languages of DeepL

  • gt_source (list[str]) – available source languages of Google Translate

  • gt_target (list[str]) – available target languages of Google Translate

  • settings (SettingsWrapper) – The fixture providing the django settings

  • mock_server (MockServer | None) – The fixture providing the mock http server used for faking the DeepL API server

Return type:

None

tests.mt_api.mt_api_test.test_automatic_translation(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], content_role_id_data_combination: tuple[Any, list, int, dict], settings: SettingsWrapper, mock_server: MockServer, caplog: LogCaptureFixture) None[source]

Check machine translation of the page/event/poi when automatic_translation checkbox in set on the form

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • content_role_id_data_combination (tuple[Any, list, int, dict]) – The combination of content type, user roles with permission and selected_ids used in the test

  • settings (SettingsWrapper) – The fixture providing the django settings

  • mock_server (MockServer) – The fixture providing the mock http server used for faking the DeepL API server

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_api_test.test_bulk_mt(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], content_role_id_combination: tuple[Any, list, list[int]], settings: SettingsWrapper, mock_server: MockServer, caplog: LogCaptureFixture) None[source]

Check for bulk machine translation of pages/events/pois via the MT API

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • content_role_id_combination (tuple[Any, list, list[int]]) – The combination of content type, user roles with permission and selected_ids used in the test

  • settings (SettingsWrapper) – The fixture providing the django settings

  • mock_server (MockServer) – The fixture providing the mock http server used for faking the DeepL API server

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_api_test.test_bulk_mt_exceeds_limit(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check for bulk machine translation error when the attempted translation would exceed the region’s word limit

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_api_test.test_bulk_mt_no_source_language(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check for bulk machine translation error when the source language is not available

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_api_test.test_bulk_mt_up_to_date(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check for bulk machine translation error when one of the target translations is up-to-date and the other is machine translated

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_api_test.test_bulk_mt_up_to_date_and_ready_for_mt(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], settings: SettingsWrapper, mock_server: MockServer, caplog: LogCaptureFixture) None[source]

Check for bulk machine translation when one of the target translations is up-to-date and the other is ready for MT

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • settings (SettingsWrapper) – The fixture providing the django settings

  • mock_server (MockServer) – The fixture providing the mock http server used for faking the DeepL API server

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_api_test.test_deepl_bulk_mt_no_target_language(load_test_data: None, login_role_user: tuple[Client, str], provider_language_combination: tuple[str, str, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check for bulk machine translation error when the target language is not available

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • provider_language_combination (tuple[str, str, str]) – The combination of MT provider and source/target language

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

Mt Provider Assignment Test

tests.mt_api.mt_provider_assignment_test.check_mt_provider(region_slug: str, language_slug: str, mt_provider: str | None) None[source]

Check whether the correct MT provider is assigned for the language

Parameters:
  • region_slug (str) – slug of the region used in the test

  • language_slug (str) – Language whose MT provider must be checked

  • mt_provider (str | None) – MT provider which should be assigned for the language in the region

Return type:

None

tests.mt_api.mt_provider_assignment_test.test_both_providers_available(load_test_data: None, caplog: LogCaptureFixture) None[source]

Check the provider assignment for the case when multiple of MT provider and languages are available for MT

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_provider_assignment_test.test_change_to_not_supporting_provider(load_test_data: None, login_role_user: tuple[Client, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check the MT provider assignment fails when a provider is selected which does not support the language

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_provider_assignment_test.test_change_to_supporting_provider(load_test_data: None, login_role_user: tuple[Client, str], settings: SettingsWrapper, caplog: LogCaptureFixture) None[source]

Check the preferred MT provider can be changed correctly

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • login_role_user (tuple[Client, str]) – The fixture providing the http client and the current role (see login_role_user())

  • settings (SettingsWrapper) – The fixture providing the django settings

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_provider_assignment_test.test_no_available_provider(load_test_data: None, caplog: LogCaptureFixture) None[source]

Check the provider assignment for the case no MT provider supports any language

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_provider_assignment_test.test_only_deepl_available(load_test_data: None, caplog: LogCaptureFixture) None[source]

Check the provider assignment for the case when only DeepL is supporting some languages but not all

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

tests.mt_api.mt_provider_assignment_test.test_only_google_translate_available(load_test_data: None, caplog: LogCaptureFixture) None[source]

Check the provider assignment for the case when only Google Translate is supporting some languages but not all

Parameters:
  • load_test_data (None) – The fixture providing the test data (see load_test_data())

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None

Utils

tests.mt_api.utils.get_content_translations(content_model: ModelBase, ids: list[int], *language_slugs: str) list[dict[str, Any]][source]

Load the translations for the given content model from the database

Parameters:
  • content_model (ModelBase) – Name of the requested data model (Page, Event or POI)

  • ids (list[int]) – List of ids of the requested model entries

  • language_slugs (str) – List of the requested language slugs

Returns:

Content translations

Return type:

list[dict[str, Any]]

tests.mt_api.utils.get_english_name(slug: str) str[source]

return the english name of language

Parameters:

slug (str) – language slug

Returns:

english name of the language

Return type:

str

tests.mt_api.utils.get_word_count(translations: list[EventTranslation] | list[PageTranslation] | list[POITranslation]) int[source]

Count the total number of words in the title, content and meta-description of translations

Parameters:

translations (list[EventTranslation] | list[PageTranslation] | list[POITranslation]) – List of translations (Pages, Events or POIs)

Returns:

Word count

Return type:

int