Tests

We use pytest to validate that the functionality of the cms works as expected.

In addition, we use the following plugins:

For more information, see Testing in Django and Writing and running tests.

Conftest

This module contains shared fixtures for pytest

tests.conftest.ALL_ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'APP_TEAM', 'MARKETING_TEAM', 'ANONYMOUS'][source]

All region and staff roles and anonymous users

[
    'MANAGEMENT',
    'EDITOR',
    'AUTHOR',
    'EVENT_MANAGER',
    'OBSERVER',
    'ROOT',
    'SERVICE_TEAM',
    'CMS_TEAM',
    'APP_TEAM',
    'MARKETING_TEAM',
    'ANONYMOUS',
]
tests.conftest.ANONYMOUS: Final = 'ANONYMOUS'[source]

A role identifier for anonymous users

tests.conftest.HIGH_PRIV_STAFF_ROLES: Final = ['ROOT', 'SERVICE_TEAM', 'CMS_TEAM'][source]

All roles of staff users that don’t just have read-only permissions

['ROOT', 'SERVICE_TEAM', 'CMS_TEAM']
tests.conftest.PRIV_STAFF_ROLES: Final = ['ROOT', 'APP_TEAM', 'SERVICE_TEAM', 'CMS_TEAM'][source]

All roles of staff users that don’t just have read-only permissions

['ROOT', 'APP_TEAM', 'SERVICE_TEAM', 'CMS_TEAM']
tests.conftest.REGION_ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER'][source]

All roles of region users

['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER']
tests.conftest.ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'APP_TEAM', 'MARKETING_TEAM'][source]

All region and staff roles

[
    'MANAGEMENT',
    'EDITOR',
    'AUTHOR',
    'EVENT_MANAGER',
    'OBSERVER',
    'ROOT',
    'SERVICE_TEAM',
    'CMS_TEAM',
    'APP_TEAM',
    'MARKETING_TEAM',
]
tests.conftest.ROOT: Final = 'ROOT'[source]

A role identifier for superusers

tests.conftest.STAFF_ROLES: Final = ['ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'APP_TEAM', 'MARKETING_TEAM'][source]

All roles of staff users

['ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'APP_TEAM', 'MARKETING_TEAM']
tests.conftest.WRITE_ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER'][source]

All roles with editing permissions

['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER']
tests.conftest.load_test_data(django_db_setup: None, django_db_blocker: _DatabaseBlocker) None[source]

Load the test data initially for all test cases

Parameters:
  • django_db_setup (None) – The fixture providing the database availability

  • django_db_blocker (_DatabaseBlocker) – The fixture providing the database blocker

Return type:

None

tests.conftest.load_test_data_transactional(transactional_db: None, django_db_blocker: _DatabaseBlocker) None[source]

Load the test data initially for all transactional test cases

Parameters:
  • transactional_db (None) – The fixture providing transaction support for the database

  • django_db_blocker (_DatabaseBlocker) – The fixture providing the database blocker

Return type:

None

tests.conftest.login_role_user(request: SubRequest, load_test_data: None, django_db_blocker: _DatabaseBlocker) tuple[Client, str][source]

Get the test user of the current role and force a login. Gets executed only once per user.

Parameters:
  • request (SubRequest) – The request object providing the parametrized role variable through request.param

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

  • django_db_blocker (_DatabaseBlocker) – The fixture providing the database blocker

Returns:

The http client and the current role

Return type:

tuple[Client, str]

tests.conftest.login_role_user_async(request: SubRequest, load_test_data: None, django_db_blocker: _DatabaseBlocker) tuple[AsyncClient, str][source]

Get the test user of the current role and force a login. Gets executed only once per user. Identical to login_role_user() with the difference that it returns an django.test.client.AsyncClient instead of django.test.client.Client.

Parameters:
  • request (SubRequest) – The request object providing the parametrized role variable through request.param

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

  • django_db_blocker (_DatabaseBlocker) – The fixture providing the database blocker

Returns:

The http client and the current role

Return type:

tuple[AsyncClient, str]

tests.conftest.pytest_plugins: Final = 'aiohttp.pytest_plugin'[source]

Enable the aiohttp pytest plugin to make use of the test server

Mock

class tests.mock.MockServer(http_server: HTTPServer)[source]

Bases: object

Http server instance that allowes to configure mock responses

Parameters:

http_server (HTTPServer) –

__init__(http_server: HTTPServer) None[source]
Parameters:

http_server (HTTPServer) –

Return type:

None

Utils

This file contains helper functions for tests.

tests.utils.assert_message_in_log(message: str, caplog: LogCaptureFixture) None[source]

Check whether a given message is in the messages div

Parameters:
  • message (str) – The expected message

  • caplog (LogCaptureFixture) – The caplog fixture

Raises:

AssertionError – When the expected message was not found in the logs

Return type:

None

tests.utils.assert_no_error_messages(caplog: LogCaptureFixture) None[source]

Assert that no error messages were shown to the user

Parameters:

caplog (LogCaptureFixture) – The caplog fixture

Raises:

AssertionError – When the the logs contains error messages

Return type:

None

tests.utils.get_error_messages(caplog: LogCaptureFixture) list[str][source]

Get all errors from the messages framework

Parameters:

caplog (LogCaptureFixture) – The caplog fixture

Returns:

The list of error messages that were shown to the user

Return type:

list[str]

tests.utils.get_messages(caplog: LogCaptureFixture) list[str][source]

Get all logs from the messages framework

Parameters:

caplog (LogCaptureFixture) – The caplog fixture

Returns:

The list of messages that were shown to the user

Return type:

list[str]