From 1851cc7af34dc776a1f79c5376817841d3219582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 10 Aug 2017 21:50:36 +0300 Subject: [PATCH] Replace non-breaking spaces with regular spaces for cheaper SMS messages. --- hc/api/tests/test_notify.py | 3 +++ hc/api/transports.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index 9eda75e5..3447abc6 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -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() diff --git a/hc/api/transports.py b/hc/api/transports.py index dd44cb5c..cf2eb362 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -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):