Tests
We use pytest to validate that the functionality of the cms works as expected.
In addition, we use the following plugins:
pytest-cov: This plugin produces coverage reports.
pytest-django: Provide a few helpers for Django
pytest-xdist: Enable distributing tests across multiple CPUs to speed up test execution
Welcome to requests-mock’s documentation!: Mocking requests to external APIs
For more information, see Testing in Django and Writing and running tests.
- API
- API Config
- Test API Chat
mark_chat_active()mark_chat_expired()test_api_chat_first_chat()test_api_chat_get_messages_failure()test_api_chat_get_messages_success()test_api_chat_incorrect_server_error()test_api_chat_missing_auth_error()test_api_chat_ratelimiting()test_api_chat_ratelimiting_trusted_ip_header()test_api_chat_send_message()test_api_chat_set_evaluation_consent()test_api_chat_stale_chat_get_returns_not_found()test_api_chat_stale_chat_starts_new_chat()test_api_is_chat_enabled_for_user()
- Test API Feedback
- Test API Push Page
- Test API Result
- Test API Social
- Test News Endpoint
- Test Pushnotification API
- CMS
- Utils
- Test Cancel Translation
- Test Content Utils
- Test Disable Hix Post Save Signal
- Test External Calendar Utils
- Test Internal Link Checker
prepage_url()test_check_internal_invalid()test_check_internal_skipped()test_check_internal_valid()test_ignore_inherited_by_new_content_object_same_region()test_ignore_not_inherited_across_regions()test_ignore_not_inherited_from_archived_page()test_ignore_not_inherited_from_past_event()test_preserve_ignored_links_across_form_save_cycle()test_preserve_ignored_links_across_internal_url_rewrite()test_preserve_ignored_links_across_update_links_to()
- Test Repair Tree
- Test Rounded Hix Value
- Test Slug Utils
- Test Translation Utils
- Test Tree Mutex
- Views
- Status Code
- Test View Status Code_1
- Test View Status Code_10
- Test View Status Code_11
- Test View Status Code_12
- Test View Status Code_13
- Test View Status Code_14
- Test View Status Code_15
- Test View Status Code_16
- Test View Status Code_2
- Test View Status Code_3
- Test View Status Code_4
- Test View Status Code_5
- Test View Status Code_6
- Test View Status Code_7
- Test View Status Code_8
- Test View Status Code_9
- Bulk Actions
- Test Public View Status Code
- Test View Redirect
- Utils
- View Config
- Status Code
- Test Duplicate Regions
- Test Language
- Test Login
- Test Media Library
- Test Page Filters
- Utils
- Core
- Firebase API
- Test Firebase API Client
TestFirebaseApiClientTestFirebaseApiClient.__init__()TestFirebaseApiClient.response_mock_dataTestFirebaseApiClient.send_all_with_mocked_response()TestFirebaseApiClient.setup_method()TestFirebaseApiClient.teardown_method()TestFirebaseApiClient.test_client_throws_exception_when_fcm_disabled()TestFirebaseApiClient.test_firebase_api_200_success()TestFirebaseApiClient.test_firebase_api_200_unexpected_api_response()TestFirebaseApiClient.test_firebase_api_403_wrong_token()TestFirebaseApiClient.test_firebase_api_404()TestFirebaseApiClient.test_is_invalid_when_no_title()TestFirebaseApiClient.test_is_invalid_when_no_translation()TestFirebaseApiClient.test_is_valid()TestFirebaseApiClient.test_multiple_regions_notification_send()TestFirebaseApiClient.test_region_notification_send()
- Test Firebase Data Client
TestFirebaseDataClientTestFirebaseDataClient.__init__()TestFirebaseDataClient.endpoint_mock_urlTestFirebaseDataClient.response_mock_dataTestFirebaseDataClient.test_avg_per_region()TestFirebaseDataClient.test_client_throws_exception_when_fcm_disabled()TestFirebaseDataClient.test_without_analytics_labels()TestFirebaseDataClient.unlabeled_response_mock_data
- Test Firebase API Client
- Mt API
- News Managers
- Sitemap
- XLIFF
Conftest
This module contains shared fixtures for pytest
- tests.conftest.ALL_ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'MARKETING_TEAM', 'ANONYMOUS'][source]
All region and staff roles and anonymous users
[ 'MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'MARKETING_TEAM', 'ANONYMOUS', ]
- 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', '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.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', 'MARKETING_TEAM'][source]
All region and staff roles
[ 'MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'MARKETING_TEAM', ]
- tests.conftest.STAFF_ROLES: Final = ['ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'MARKETING_TEAM'][source]
All roles of staff users
['ROOT', 'SERVICE_TEAM', 'CMS_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.clean_news_cache(load_test_data: None) Generator[None][source]
Clear external news-source cache entries before and after a test.
Language slugs are read from the DB so adding or removing a language is automatically reflected.
- Parameters:
load_test_data (None)
- Return type:
Generator[None]
- tests.conftest.configure_celery_for_tests(settings: SettingsWrapper) None[source]
- Parameters:
settings (SettingsWrapper)
- Return type:
None
- tests.conftest.create_language() Callable[..., Language][source]
- Return type:
Callable[…, Language]
- 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.paramload_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:
- tests.conftest.mock_server(httpserver: HTTPServer) MockServer[source]
- Parameters:
httpserver (HTTPServer)
- Return type:
Mock
- class tests.mock.MockServer(http_server: HTTPServer)[source]
Bases:
objectHttp 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:
- 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
caplogfixture- Raises:
AssertionError – When the the logs contains error messages
- Return type:
None