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 Raw Content
- Test API Result
- Test API Social
- Test API Token Auth
- Test News Endpoint
- Test Pushnotification API
- Test Region Settings
test_api_managed_region_form_shows_the_real_budget()test_get_region_settings()test_post_accepts_budget_outside_the_predefined_sizes()test_post_rejects_invalid_values()test_post_rejects_non_writable_fields()test_post_updates_settings_and_records_sync()test_requires_authentication()test_requires_permission()test_unknown_region_returns_404()
- 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
- Conftest
- 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.QUICK_ROLE_SET: Final = ['ROOT', 'MANAGEMENT', 'AUTHOR', 'ANONYMOUS'][source]
Representative subset covering all permission boundaries (for faster local runs)
['ROOT', 'MANAGEMENT', 'AUTHOR', 'ANONYMOUS']
- tests.conftest.TEST_ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'MARKETING_TEAM', 'ANONYMOUS'][source]
The roles used for parametrized tests — set QUICK_ROLES=1 to use the subset
[ 'MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER', 'ROOT', 'SERVICE_TEAM', 'CMS_TEAM', 'MARKETING_TEAM', 'ANONYMOUS', ]
- 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.clear_cache() None[source]
Reset the cache before every test so cache state cannot leak between tests.
The cache backend used in tests (
LocMemCache) lives for the lifetime of the worker process, and Django only rolls back the database between tests — not the cache. Without this, process-level cache state (most notably the API rate-limit counters inrate_limited()) accumulates across tests and makes assertions depend on test execution order.- Return type:
None
- tests.conftest.clear_leaked_messages(request: SubRequest) Generator[None][source]
Discard unread messages from the shared client after every test.
login_role_user()is session-scoped, so one client — and one cookie jar — is reused for the whole run, whileMESSAGE_STORAGEkeeps messages in a cookie. A test that triggers a view emitting a message without ever rendering the redirect target leaves that message queued in the cookie, where an arbitrary later test renders it into its own response and trips content assertions.- Parameters:
request (SubRequest)
- Return type:
Generator[None]
- tests.conftest.configure_celery_for_tests(settings: SettingsWrapper) None[source]
- Parameters:
settings (SettingsWrapper)
- Return type:
None
- tests.conftest.create_event() Callable[..., Event][source]
Factory fixture to create an
Eventwith sensible defaults for all required fields.- Returns:
A callable that creates an event
- Return type:
Callable[…, Event]
- tests.conftest.create_event_translation() Callable[..., EventTranslation][source]
Factory fixture to create an
EventTranslationwith sensible defaults for all required fields.- Returns:
A callable that creates an event translation
- Return type:
Callable[…, EventTranslation]
- tests.conftest.create_language() Callable[..., Language][source]
Factory fixture to create a
Languagewith sensible defaults for all required fields, so tests only need to pass the values they care about.- Returns:
A callable that creates a language
- Return type:
Callable[…, Language]
- tests.conftest.create_page() Callable[..., Page][source]
Factory fixture to create a
Pagevia treebeard’sadd_root/add_childAPI.- Returns:
A callable that creates a page
- Return type:
Callable[…, Page]
- tests.conftest.create_page_translation() Callable[..., PageTranslation][source]
Factory fixture to create a
PageTranslationwith sensible defaults for all required fields.- Returns:
A callable that creates a page translation
- Return type:
Callable[…, PageTranslation]
- tests.conftest.create_recurrence_rule() Callable[..., RecurrenceRule][source]
Factory fixture to create a
RecurrenceRule.- Returns:
A callable that creates a recurrence rule
- Return type:
Callable[…, RecurrenceRule]
- tests.conftest.create_region(create_language: Callable[..., Language]) Callable[..., Region][source]
Factory fixture to create a
Regionwith sensible defaults for all required fields. If no language tree exists for the region after creation, a default language is created and attached automatically.
- tests.conftest.create_user() Callable[..., User][source]
Factory fixture to create a
User.- Returns:
A callable that creates a user
- Return type:
Callable[…, User]
- tests.conftest.disable_auto_news_reimport(settings: SettingsWrapper) None[source]
Disable re-import of external news on demand to avoid hitting the real APIs and getting real news posts
- Parameters:
settings (SettingsWrapper)
- Return type:
None
- 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 test data for transactional test cases. Transactional tests flush the database after each test, so fixtures must be reloaded per function. pytest-django ensures these run after all non-transactional tests within the same worker.
- 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:
- tests.conftest.pytest_addoption(parser: Parser) None[source]
Register custom CLI options.
- Parameters:
parser (Parser)
- Return type:
None
- tests.conftest.reset_linkcheck_listeners() Generator[None][source]
Restore the configured linkcheck listener state around every test.
linkcheck.listeners.disable_listeners()re-registers the listeners when its context manager exits instead of restoring whatever state was active before, so production code paths that use it — the region form,region_actionsandlanguage_tree_actions— leave the listeners connected for the remainder of the worker process, even thoughLINKCHECK_DISABLE_LISTENERSis enabled intest_settings. Any later test that saves content then silently getsUrl/Linkrows it never asked for, which makes linkcheck assertions depend on which tests happened to share the worker.- Return type:
Generator[None]
- tests.conftest.update_snapshots(request: FixtureRequest) bool[source]
Whether
--update-snapshotswas passed on the CLI.- Parameters:
request (FixtureRequest)
- Return type:
Constants
Shared test constants.
Role identifiers and role groups used across test parametrization.
Extracted from conftest.py so they can be imported without triggering
fixture registration.
- tests.constants.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.constants.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.constants.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.constants.REGION_ROLES: Final = ['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER'][source]
All roles of region users
['MANAGEMENT', 'EDITOR', 'AUTHOR', 'EVENT_MANAGER', 'OBSERVER']
- tests.constants.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', ]
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