Browse Source

Replace non-breaking spaces with regular spaces for cheaper SMS messages.

pull/133/head
Pēteris Caune 7 years ago
parent
commit
1851cc7af3
2 changed files with 6 additions and 1 deletions
  1. +3
    -0
      hc/api/tests/test_notify.py
  2. +3
    -1
      hc/api/transports.py

+ 3
- 0
hc/api/tests/test_notify.py View File

@ -314,6 +314,8 @@ class NotifyTestCase(BaseTestCase):
@patch("hc.api.transports.requests.request")
def test_sms(self, mock_post):
self._setup_data("sms", "+1234567890")
self.check.last_ping = now() - td(hours=2)
mock_post.return_value.status_code = 200
self.channel.notify(self.check)
@ -322,6 +324,7 @@ class NotifyTestCase(BaseTestCase):
args, kwargs = mock_post.call_args
payload = kwargs["data"]
self.assertEqual(payload["To"], "+1234567890")
self.assertFalse(u"\xa0" in payload["Body"])
# sent SMS counter should go up
self.profile.refresh_from_db()


+ 3
- 1
hc/api/transports.py View File

@ -11,7 +11,9 @@ from hc.lib import emails
def tmpl(template_name, **ctx):
template_path = "integrations/%s" % template_name
return render_to_string(template_path, ctx).strip()
# \xa0 is non-breaking space. It causes SMS messages to use UCS2 encoding
# and cost twice the money.
return render_to_string(template_path, ctx).strip().replace(u"\xa0", " ")
class Transport(object):


Loading…
Cancel
Save