Many countries are introducing different requirements for SMS senders to register and/or use alpha numeric ids, short codes or regional numbers or face being blocked. The changes in this PR will give us more flexibility by allowing us to map to different resources in Twilio based on the phone number we are trying to reach. For this first implementation the selection is made based on country code of the recipient. Verification and phone calls were given the same treatment although the immediate need is for SMS. Senders with no country code set can be used as catch-all defaults. This also falls back to the configured live settings/environment variables if not configured. Possible future additions: - Move through list of trying multiple senders before failing notification - Easily expanded to allow per-organization or per-user resources to let users and tenants configure their own Twilio - Add UI + replace live settings so users can configure their own settings - More selection criteria if needed TODO: - [x] Add+Fix Tests - [x] Verify changes are compatible with #1713
40 lines
939 B
Python
40 lines
939 B
Python
import pytest
|
|
|
|
from apps.twilioapp.tests.factories import (
|
|
TwilioAccountFactory,
|
|
TwilioPhoneCallSenderFactory,
|
|
TwilioSmsSenderFactory,
|
|
TwilioVerificationSenderFactory,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def make_twilio_account():
|
|
def _make_twilio_account(**kwargs):
|
|
return TwilioAccountFactory(**kwargs)
|
|
|
|
return _make_twilio_account
|
|
|
|
|
|
@pytest.fixture
|
|
def make_twilio_phone_call_sender():
|
|
def _make_twilio_phone_call_sender(**kwargs):
|
|
return TwilioPhoneCallSenderFactory(**kwargs)
|
|
|
|
return _make_twilio_phone_call_sender
|
|
|
|
|
|
@pytest.fixture
|
|
def make_twilio_sms_sender():
|
|
def _make_twilio_sms_sender(**kwargs):
|
|
return TwilioSmsSenderFactory(**kwargs)
|
|
|
|
return _make_twilio_sms_sender
|
|
|
|
|
|
@pytest.fixture
|
|
def make_twilio_verification_sender():
|
|
def _make_twilio_verification_sender(**kwargs):
|
|
return TwilioVerificationSenderFactory(**kwargs)
|
|
|
|
return _make_twilio_verification_sender
|