"""Tests for the translations module.""" from unittest.mock import MagicMock import pytest from notifications_delivery.utils.translations import get_translations @pytest.mark.parametrize( 'translations_mock, locale, expected_value', ( # check translations been loaded successfully (MagicMock(return_value='TRANSLATION'), 'de', 'TRANSLATION'), # check null translations for default locale (MagicMock(return_value='TRANSLATION'), 'en', 'NULL_TRANSLATION'), # check fallback for unknown locale (MagicMock(side_effect=FileNotFoundError), 'unknown_locale', 'NULL_TRANSLATION'), ) ) def test_translations(translations_mock, locale, expected_value, mocker): """Test translations.""" mocker.patch( 'notifications_delivery.utils.translations.gettext.translation', translations_mock ) mocker.patch( 'notifications_delivery.utils.translations.gettext.NullTranslations', MagicMock(return_value='NULL_TRANSLATION') ) translations = get_translations(locale=locale) assert translations == expected_value