diff --git a/src/settings.py b/src/settings.py index 0364dfd..7572529 100644 --- a/src/settings.py +++ b/src/settings.py @@ -42,7 +42,8 @@ class Settings(BaseSettings): # Have to use a US number as the originator to send to the US # https://support.messagebird.com/hc/en-us/articles/208747865-United-States us_send_number = '15744445663' - gb_send_number = '12048170659' + canada_send_number = '12048170659' + inbox_send_number = 'inbox' @validator('pg_dsn') def heroku_ready_pg_dsn(cls, v): diff --git a/src/worker/sms.py b/src/worker/sms.py index d186d68..2b7b774 100644 --- a/src/worker/sms.py +++ b/src/worker/sms.py @@ -64,7 +64,12 @@ def __init__(self, ctx: dict, group_id: int, company_id: int, recipient: SmsReci self.m: SmsSendModel = m self.tags = list(set(self.recipient.tags + self.m.tags + [str(self.m.uid)])) self.messagebird: MessageBird = ctx['messagebird'] - self.from_name = self.settings.gb_send_number if self.m.country_code != 'US' else self.settings.us_send_number + if self.m.country_code == 'US': + self.from_name = self.settings.us_send_number + elif self.m.country_code == 'CA': + self.from_name = self.settings.canada_send_number + else: + self.from_name = self.settings.inbox_send_number async def run(self): sms_data = await self._sms_prep() diff --git a/tests/test_sms.py b/tests/test_sms.py index b8c0899..a4f18c0 100644 --- a/tests/test_sms.py +++ b/tests/test_sms.py @@ -28,7 +28,7 @@ def test_send_message(cli, tmpdir, worker, loop): "to: Number(number='+447891123856', country_code='44', " "number_formatted='+44 7891 123856', descr=None, is_mobile=True)" ) in msg_file - assert f'\nfrom_name: {settings.gb_send_number}\n' in msg_file + assert f'\nfrom_name: {settings.inbox_send_number}\n' in msg_file assert '\nmessage:\nthis is a message bar\n' in msg_file assert '\nlength: SmsLength(length=21, parts=1)\n' in msg_file @@ -59,6 +59,32 @@ def test_send_message_usa(cli, settings, tmpdir, worker, loop): assert '\nlength: SmsLength(length=21, parts=1)\n' in msg_file +def test_send_message_canada(cli, settings, tmpdir, worker, loop): + data = { + 'uid': '69eb85e8-1504-40aa-94ff-75bb65fd8d72', + 'company_code': 'foobar', + 'country_code': 'CA', + 'from_name': 'foobar send', + 'method': 'sms-test', + 'main_template': 'this is a message {{ foo }}', + 'recipients': [{'number': '+1 818 337 3095', 'context': {'foo': 'bar'}}], + } + r = cli.post('/send/sms/', json=data, headers={'Authorization': 'testing-key'}) + assert r.status_code == 201, r.text + assert worker.test_run() == 1 + assert len(tmpdir.listdir()) == 1 + f = '69eb85e8-1504-40aa-94ff-75bb65fd8d72-18183373095.txt' + assert str(tmpdir.listdir()[0]).endswith(f) + msg_file = tmpdir.join(f).read() + assert ( + "to: Number(number='+18183373095', country_code='1', " + "number_formatted='+1 818-337-3095', descr=None, is_mobile=True)" + ) in msg_file + assert f'\nfrom_name: {settings.canada_send_number}\n' in msg_file + assert '\nmessage:\nthis is a message bar\n' in msg_file + assert '\nlength: SmsLength(length=21, parts=1)\n' in msg_file + + def test_validate_number(cli, tmpdir): data = { 'country_code': 'US', @@ -325,7 +351,7 @@ def test_link_shortening(cli, tmpdir, sync_db: SyncDb, worker, loop): f = '69eb85e8-1504-40aa-94ff-75bb65fd8d75-447891123856.txt' assert str(tmpdir.listdir()[0]).endswith(f) msg_file = tmpdir.join(f).read() - assert f'\nfrom_name: {settings.gb_send_number}\n' in msg_file + assert f'\nfrom_name: {settings.inbox_send_number}\n' in msg_file assert '\nmessage:\nthis is a message click.example.com/l' in msg_file token = re.search('message click.example.com/l(.+?)\n', msg_file).groups()[0] assert len(token) == 12