XLIFF

This package contains tests of the integreat_cms.xliff app

Utils

This file contains helper functions for XLIFF tests.

tests.xliff.utils.get_and_assert_200(client: Client, url: str) HttpResponse | TemplateResponse[source]

Perform a get request and make sure the result is successful

Parameters:
  • client (Client) – The authenticated client

  • url (str) – The URL to open

Returns:

The successful response

Return type:

HttpResponse | TemplateResponse

tests.xliff.utils.get_open_kwargs(file_name: str) OpenKwargs[source]

Determine the open() keyword arguments of a file (binary mode for ZIP files)

Parameters:

file_name (str) – The filename

Returns:

The kwargs

Return type:

OpenKwargs

tests.xliff.utils.upload_files(client: Client, url: str, file_1: str, file_2: str) HttpResponseNotFound | HttpResponseRedirect[source]

Helper function to upload two XLIFF files

Parameters:
  • client (Client) – The authenticated client

  • url (str) – The URL to which the files should be uploaded

  • file_1 (str) – The first file

  • file_2 (str) – The second file

Returns:

The upload response

Return type:

HttpResponseNotFound | HttpResponseRedirect

tests.xliff.utils.validate_xliff_import_response(client: Client, caplog: LogCaptureFixture, response: HttpResponseRedirect, import_1: dict[str, Any], import_2: dict[str, Any]) None[source]

Helper function to validate an XLIFF import response

Parameters:
  • client (Client) – The authenticated client

  • caplog (LogCaptureFixture) – The caplog fixture

  • response (HttpResponseRedirect) – The response of the confirm view to be validated

  • import_1 (dict[str, Any]) – A dict of import information

  • import_2 (dict[str, Any]) – A list of import information

Return type:

None

XLIFF Config

This file contains the import config for XLIFF tests.

tests.xliff.xliff_config.XLIFF_IMPORTS: Final[list[tuple[dict[str, int | str], dict[str, int | str]]]] = [({'content': '<p>Updated content</p>', 'file': 'augsburg_de_en_1_2_willkommen.xliff', 'id': 1, 'message': 'SUCCESS  Pages "Updated title" and "Updated title" (Title in German: "Willkommen in Augsburg") were imported successfully.', 'title': 'Updated title'}, {'content': '<p>Updated content</p>', 'expected_file': 'augsburg_de_en_2_1_willkommen-in-augsburg.xliff', 'file': 'augsburg_de_en_2_1_willkommen-in-augsburg.zip', 'id': 2, 'message': 'SUCCESS  Pages "Updated title" and "Updated title" (Title in German: "Willkommen in Augsburg") were imported successfully.', 'title': 'Updated title'}), ({'content': '<p>Welcome to Augsburg</p>', 'file': 'augsburg_de_en_1_2_willkommen_unchanged.xliff', 'id': 1, 'message': 'INFO     Pages "Welcome" and "City Map" were imported without changes.', 'title': 'Welcome'}, {'content': '<p>These changes were saved automatically</p>', 'file': 'augsburg_de_en_5_1_stadtplan_unchanged.xliff', 'id': 5, 'message': 'INFO     Pages "Welcome" and "City Map" were imported without changes.', 'title': 'City Map'}), ({'content': '<p>Updated content</p>', 'file': 'augsburg_de_en_1_2_willkommen.xliff', 'id': 1, 'message': 'SUCCESS  Page "Updated title" was imported successfully.', 'title': 'Updated title'}, {'confirmation_message': 'ERROR    Page <b>&quot;Welcome&quot;</b> from file <b>augsburg_de_en_1_2_willkommen.xliff</b> was also translated in file <b>augsburg_de_en_1_2_willkommen_conflict.xliff</b>. Please check which of the files contains the most recent version and upload only this file. If you confirm this import, only the first file will be imported and the latter will be ignored.', 'content': '<p>Updated content</p>', 'file': 'augsburg_de_en_1_2_willkommen_conflict.xliff', 'id': 1, 'message': 'ERROR    Page &quot;Conflicting title&quot; from the file <b>augsburg_de_en_1_2_willkommen_conflict.xliff</b> could not be imported. Check if you have uploaded any other conflicting files for this page. If the problem persists, contact an administrator.', 'title': 'Updated title'})][source]

The files to be uploaded and their expected response

[
    (
        {
            'content': '<p>Updated content</p>',
            'file': 'augsburg_de_en_1_2_willkommen.xliff',
            'id': 1,
            'message': 'SUCCESS  Pages "Updated title" and "Updated title" (Title in German: "Willkommen in Augsburg") were imported successfully.',
            'title': 'Updated title',
        },
        {
            'content': '<p>Updated content</p>',
            'expected_file': 'augsburg_de_en_2_1_willkommen-in-augsburg.xliff',
            'file': 'augsburg_de_en_2_1_willkommen-in-augsburg.zip',
            'id': 2,
            'message': 'SUCCESS  Pages "Updated title" and "Updated title" (Title in German: "Willkommen in Augsburg") were imported successfully.',
            'title': 'Updated title',
        },
    ),
    (
        {
            'content': '<p>Welcome to Augsburg</p>',
            'file': 'augsburg_de_en_1_2_willkommen_unchanged.xliff',
            'id': 1,
            'message': 'INFO     Pages "Welcome" and "City Map" were imported without changes.',
            'title': 'Welcome',
        },
        {
            'content': '<p>These changes were saved automatically</p>',
            'file': 'augsburg_de_en_5_1_stadtplan_unchanged.xliff',
            'id': 5,
            'message': 'INFO     Pages "Welcome" and "City Map" were imported without changes.',
            'title': 'City Map',
        },
    ),
    (
        {
            'content': '<p>Updated content</p>',
            'file': 'augsburg_de_en_1_2_willkommen.xliff',
            'id': 1,
            'message': 'SUCCESS  Page "Updated title" was imported successfully.',
            'title': 'Updated title',
        },
        {
            'confirmation_message': 'ERROR    Page <b>&quot;Welcome&quot;</b> from file <b>augsburg_de_en_1_2_willkommen.xliff</b> was also translated in file <b>augsburg_de_en_1_2_willkommen_conflict.xliff</b>. Please check which of the files contains the most recent version and upload only this file. If you confirm this import, only the first file will be imported and the latter will be ignored.',
            'content': '<p>Updated content</p>',
            'file': 'augsburg_de_en_1_2_willkommen_conflict.xliff',
            'id': 1,
            'message': 'ERROR    Page &quot;Conflicting title&quot; from the file <b>augsburg_de_en_1_2_willkommen_conflict.xliff</b> could not be imported. Check if you have uploaded any other conflicting files for this page. If the problem persists, contact an administrator.',
            'title': 'Updated title',
        },
    ),
]

XLIFF Test

tests.xliff.xliff_test.test_xliff_export(login_role_user: tuple[Client, str], settings: SettingsWrapper, tmp_path: Path, xliff_version: str, view: str, directory: str) None[source]

This test checks whether the xliff export works as expected

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

  • tmp_path (Path) – The fixture providing the directory for temporary files for this test case

  • xliff_version (str) – The XLIFF version to be tested

  • view (str) – The name of the view for the export

  • directory (str) – The directory that contains the expected XLIFF files

Return type:

None

tests.xliff.xliff_test.test_xliff_import(login_role_user: tuple[Client, str], settings: SettingsWrapper, caplog: LogCaptureFixture, import_1: dict[str, Any], import_2: dict[str, Any]) None[source]

This test checks whether the xliff import works as expected

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

  • import_1 (dict[str, Any]) – A dict of import information

  • import_2 (dict[str, Any]) – A list of import information

  • caplog (LogCaptureFixture) – The caplog fixture

Return type:

None