Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SMS

.. attribute:: PYMESS_SMS_USE_ACCENT

Setting that sets if SMS will be sent with accent or not. Default value is ``False``.
Setting that sets if SMS will be sent with accent or not. Default value is ``False``. This setting does not work for SMS voice messages.

.. attribute:: PYMESS_SMS_LOG_IDLE_MESSAGES

Expand Down
2 changes: 1 addition & 1 deletion pymess/models/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def clean_recipient(self):
self.recipient = normalize_phone_number(force_str(self.recipient))

def clean_content(self):
if not settings.SMS_USE_ACCENT:
if not self.is_voice_message and not settings.SMS_USE_ACCENT:
self.content = str(remove_accent(str(self.content)))

@property
Expand Down
40 changes: 40 additions & 0 deletions tests/test_sms_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest
from unittest.mock import patch

from pymess.models.sms import OutputSMSMessage
from pymess.enums import OutputSMSMessageState


@pytest.mark.django_db
class TestOutputSMSMessageCleanContent:

@pytest.mark.parametrize('use_accent,expected_content', [
(False, 'Prilis zlutoucky kun upel dabelske ody'),
(True, 'Příliš žluťoučký kůň úpěl ďábelské ódy'),
])
def test_clean_content_should_handle_accents_for_regular_sms_based_on_setting(self, use_accent, expected_content):
message = OutputSMSMessage(
recipient='+420123456789',
content='Příliš žluťoučký kůň úpěl ďábelské ódy',
state=OutputSMSMessageState.WAITING,
is_voice_message=False,
)

with patch('pymess.models.sms.settings.SMS_USE_ACCENT', use_accent):
message.clean_content()

assert message.content == expected_content

@pytest.mark.parametrize('use_accent', [False, True])
def test_clean_content_should_keep_accents_for_voice_message_regardless_of_setting(self, use_accent):
message = OutputSMSMessage(
recipient='+420123456789',
content='Příliš žluťoučký kůň úpěl ďábelské ódy',
state=OutputSMSMessageState.WAITING,
is_voice_message=True,
)

with patch('pymess.models.sms.settings.SMS_USE_ACCENT', use_accent):
message.clean_content()

assert message.content == 'Příliš žluťoučký kůň úpěl ďábelské ódy'