"""Test messages.""" import gettext from unittest.mock import MagicMock import pytest from src.common import messages import config @pytest.mark.parametrize(('identity_lc', 'user_locale'), [ ('fr-CA', 'fr'), ('', 'en'), ('pt', 'pt'), ('zh', 'zh'), ('zh-CN', 'zh_CN') ]) def test_localization(identity_lc, user_locale, monkeypatch): """Test _get_translations.""" translations_mock = MagicMock() translations_mock.gettext = 'GETTEXT' monkeypatch.setattr( gettext, 'translation', MagicMock(return_value=translations_mock)) result = messages.get_translations(identity_lc) gettext.translation.assert_called_once_with( config.I18N_DOMAIN, localedir=config.I18N_FOLDER_NAME, languages=[user_locale], fallback=True) assert result == 'GETTEXT' @pytest.mark.parametrize(( 'platform_string', 'platform_name', 'follower_type'), [ ('youtube', 'YouTube', 'Subscribers'), ('facebook', 'Facebook', 'Fans'), ]) def test_get_platform_and_follower_type( platform_string, platform_name, follower_type): """Test _get_platform_and_follower_type.""" result = messages.get_platform_and_follower_type(platform_string) assert result[0] == platform_name assert result[1] == follower_type with pytest.raises(Exception) as e: messages.get_platform_and_follower_type('tiktok') assert str(e.value) == 'Unknown platform tiktok' def test_format_message(): """Test output message to SNS is formatted as expected.""" message = messages.create_message_string( 'Message Body', {'meta': 'data'} ) assert message == '{\"GCM\": \"{\\"data\\": {\\"meta\\": \\"data\\", \\"body\\": \\"Message Body\\"}}\", \"APNS\": \"{\\"aps\\": {\\"alert\\": {\\"body\\": \\"Message Body\\"}, \\"sound\\": \\"default\\"}, \\"body\\": {\\"meta\\": \\"data\\"}}\", \"default\": \"Message Body\"}' # noqa:E501