Skip to content

Commit

Permalink
use updated method name
Browse files Browse the repository at this point in the history
  • Loading branch information
calellowitz committed Nov 14, 2024
1 parent 79154f0 commit 460c794
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 40 deletions.
6 changes: 3 additions & 3 deletions corehq/apps/commtrack/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from corehq.apps.domain.models import Domain
from corehq.apps.products.models import SQLProduct
from corehq.apps.receiverwrapper.util import submit_form_locally
from corehq.apps.sms.api import MessageMetadata, send_sms_to_verified_number
from corehq.apps.sms.api import MessageMetadata, send_message_to_verified_number
from corehq.apps.users.models import CouchUser
from corehq.form_processor.interfaces.supply import SupplyInterface
from corehq.form_processor.parsers.ledgers.helpers import (
Expand Down Expand Up @@ -50,7 +50,7 @@ def handle(verified_contact, text, msg):
except Exception as e:
if settings.UNIT_TESTING or settings.DEBUG:
raise
send_sms_to_verified_number(verified_contact, 'problem with stock report: %s' % str(e))
send_message_to_verified_number(verified_contact, 'problem with stock report: %s' % str(e))
return True

process(domain_obj.name, data)
Expand Down Expand Up @@ -372,4 +372,4 @@ def summarize_action(action, txs):
' '.join(sorted(summarize_action(a, txs) for a, txs in tx_by_action.items()))
)

send_sms_to_verified_number(v, msg, metadata=metadata)
send_message_to_verified_number(v, msg, metadata=metadata)
1 change: 1 addition & 0 deletions corehq/apps/sms/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def options(self):
(MessagingEvent.CONTENT_SMS_CALLBACK, gettext_noop('SMS Callback')),
(MessagingEvent.CONTENT_SMS, gettext_noop('Other SMS')),
(MessagingEvent.CONTENT_EMAIL, gettext_noop('Email')),
(MessagingEvent.CONTENT_CONNECT, gettext_noop('Connect Message')),
]


Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/sms/handlers/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from corehq.apps.sms.api import (
MessageMetadata,
add_msg_tags,
send_sms_to_verified_number,
send_message_to_verified_number,
)
from corehq.apps.sms.models import WORKFLOW_DEFAULT, MessagingEvent

Expand All @@ -26,7 +26,7 @@ def fallback_handler(verified_number, text, msg):
outbound_meta = MessageMetadata(workflow=WORKFLOW_DEFAULT,
location_id=msg.location_id,
messaging_subevent_id=outbound_subevent.pk)
send_sms_to_verified_number(verified_number, domain_obj.default_sms_response,
send_message_to_verified_number(verified_number, domain_obj.default_sms_response,
metadata=outbound_meta)
outbound_subevent.completed()

Expand Down
12 changes: 6 additions & 6 deletions corehq/apps/sms/handlers/form_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MessageMetadata,
add_msg_tags,
log_sms_exception,
send_sms_to_verified_number,
send_message_to_verified_number,
)
from corehq.apps.sms.messages import (
MSG_CHOICE_OUT_OF_RANGE,
Expand Down Expand Up @@ -59,7 +59,7 @@ def form_session_handler(verified_number, text, msg):
"message_id": msg.couch_id
})
session.mark_completed(False) # this will also release the channel
send_sms_to_verified_number(
send_message_to_verified_number(
verified_number, get_message(MSG_GENERIC_ERROR, verified_number)
)
return True
Expand All @@ -77,7 +77,7 @@ def form_session_handler(verified_number, text, msg):
verified_number.domain, verified_number.owner_id
)
if multiple:
send_sms_to_verified_number(verified_number, get_message(MSG_GENERIC_ERROR, verified_number))
send_message_to_verified_number(verified_number, get_message(MSG_GENERIC_ERROR, verified_number))
return True

if session:
Expand All @@ -102,7 +102,7 @@ def form_session_handler(verified_number, text, msg):
except Exception:
# Catch any touchforms errors
log_sms_exception(msg)
send_sms_to_verified_number(verified_number, get_message(MSG_TOUCHFORMS_DOWN, verified_number))
send_message_to_verified_number(verified_number, get_message(MSG_TOUCHFORMS_DOWN, verified_number))
return True
else:
return False
Expand Down Expand Up @@ -152,12 +152,12 @@ def answer_next_question(verified_number, text, msg, session, subevent_id):
events = get_events_from_responses(responses)
if len(text_responses) > 0:
response_text = format_message_list(text_responses)
send_sms_to_verified_number(verified_number, response_text,
send_message_to_verified_number(verified_number, response_text,
metadata=outbound_metadata, events=events)
else:
mark_as_invalid_response(msg)
response_text = "%s %s" % (error_msg, event.text_prompt)
send_sms_to_verified_number(verified_number, response_text,
send_message_to_verified_number(verified_number, response_text,
metadata=outbound_metadata, events=[event])


Expand Down
14 changes: 7 additions & 7 deletions corehq/apps/sms/handlers/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from corehq.apps.sms.api import (
MessageMetadata,
add_msg_tags,
send_sms_to_verified_number,
send_message_to_verified_number,
)
from corehq.apps.sms.handlers.form_session import validate_answer
from corehq.apps.sms.messages import (
Expand Down Expand Up @@ -107,10 +107,10 @@ def global_keyword_start(verified_number, text, msg, text_words, open_sessions):
process_survey_keyword_actions(verified_number, k, text[6:].strip(), msg)
else:
message = get_message(MSG_KEYWORD_NOT_FOUND, verified_number, (keyword,))
send_sms_to_verified_number(verified_number, message, metadata=outbound_metadata)
send_message_to_verified_number(verified_number, message, metadata=outbound_metadata)
else:
message = get_message(MSG_START_KEYWORD_USAGE, verified_number, (text_words[0],))
send_sms_to_verified_number(verified_number, message, metadata=outbound_metadata)
send_message_to_verified_number(verified_number, message, metadata=outbound_metadata)
return True


Expand All @@ -130,14 +130,14 @@ def global_keyword_current(verified_number, text, msg, text_words, open_sessions

resp = FormplayerInterface(session.session_id, verified_number.domain).current_question()

send_sms_to_verified_number(verified_number, resp.event.text_prompt,
send_message_to_verified_number(verified_number, resp.event.text_prompt,
metadata=outbound_metadata, events=[resp.event])
return True


def global_keyword_unknown(verified_number, text, msg, text_words, open_sessions):
message = get_message(MSG_UNKNOWN_GLOBAL_KEYWORD, verified_number, (text_words[0],))
send_sms_to_verified_number(verified_number, message)
send_message_to_verified_number(verified_number, message)
return True


Expand Down Expand Up @@ -469,7 +469,7 @@ def clean_up_and_send_response(msg, contact, session, error_occurred, error_msg,
contact.doc_type, contact.get_id)
metadata.messaging_subevent_id = response_subevent.pk

send_sms_to_verified_number(verified_number, error_msg, metadata=metadata)
send_message_to_verified_number(verified_number, error_msg, metadata=metadata)
if response_subevent:
response_subevent.completed()

Expand Down Expand Up @@ -560,7 +560,7 @@ def send_keyword_response(vn, message_id, logged_event):
messaging_subevent_id=subevent.pk,
)
message = get_message(message_id, vn)
send_sms_to_verified_number(vn, message, metadata=metadata)
send_message_to_verified_number(vn, message, metadata=metadata)
subevent.completed()


Expand Down
14 changes: 7 additions & 7 deletions corehq/apps/sms/tests/opt_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from corehq.apps.domain.models import Domain
from corehq.messaging.pillow import get_case_messaging_sync_pillow
from corehq.messaging.smsbackends.test.models import SQLTestSMSBackend
from corehq.apps.sms.api import incoming, send_sms_to_verified_number
from corehq.apps.sms.api import incoming, send_message_to_verified_number
from corehq.apps.sms.messages import MSG_OPTED_IN, MSG_OPTED_OUT, get_message
from corehq.apps.sms.models import SMS, PhoneBlacklist, PhoneNumber, SQLMobileBackendMapping, SQLMobileBackend
from corehq.apps.sms.tests.util import (
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_sending_to_opted_out_number(self):
v = PhoneNumber.get_two_way_number('99912345678')
self.assertIsNotNone(v)

send_sms_to_verified_number(v, 'hello')
send_message_to_verified_number(v, 'hello')
sms = self.get_last_sms('+99912345678')
self.assertEqual(sms.direction, 'O')
self.assertEqual(sms.text, 'hello')
Expand All @@ -118,7 +118,7 @@ def test_sending_to_opted_out_number(self):
phone_number = PhoneBlacklist.objects.get(phone_number='99912345678')
self.assertFalse(phone_number.send_sms)

send_sms_to_verified_number(v, 'hello')
send_message_to_verified_number(v, 'hello')
sms = self.get_last_sms('+99912345678')
self.assertEqual(sms.direction, 'O')
self.assertEqual(sms.text, 'hello')
Expand All @@ -130,7 +130,7 @@ def test_sending_to_opted_out_number(self):
phone_number = PhoneBlacklist.objects.get(phone_number='99912345678')
self.assertTrue(phone_number.send_sms)

send_sms_to_verified_number(v, 'hello')
send_message_to_verified_number(v, 'hello')
sms = self.get_last_sms('+99912345678')
self.assertEqual(sms.direction, 'O')
self.assertEqual(sms.text, 'hello')
Expand All @@ -144,7 +144,7 @@ def test_custom_opt_keywords(self):
v = PhoneNumber.get_two_way_number('19912345678')
self.assertIsNotNone(v)

send_sms_to_verified_number(v, 'hello')
send_message_to_verified_number(v, 'hello')
sms = self.get_last_sms('+19912345678')
self.assertEqual(sms.direction, 'O')
self.assertEqual(sms.text, 'hello')
Expand All @@ -154,7 +154,7 @@ def test_custom_opt_keywords(self):
phone_number = PhoneBlacklist.objects.get(phone_number='19912345678')
self.assertFalse(phone_number.send_sms)

send_sms_to_verified_number(v, 'hello')
send_message_to_verified_number(v, 'hello')
sms = self.get_last_sms('+19912345678')
self.assertEqual(sms.direction, 'O')
self.assertEqual(sms.text, 'hello')
Expand All @@ -166,7 +166,7 @@ def test_custom_opt_keywords(self):
phone_number = PhoneBlacklist.objects.get(phone_number='19912345678')
self.assertTrue(phone_number.send_sms)

send_sms_to_verified_number(v, 'hello')
send_message_to_verified_number(v, 'hello')
sms = self.get_last_sms('+19912345678')
self.assertEqual(sms.direction, 'O')
self.assertEqual(sms.text, 'hello')
Expand Down
14 changes: 7 additions & 7 deletions corehq/apps/sms/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from corehq.apps.hqcase.utils import update_case
from corehq.apps.sms.api import (
send_sms,
send_sms_to_verified_number,
send_message_to_verified_number,
send_sms_with_backend,
send_sms_with_backend_name,
)
Expand Down Expand Up @@ -812,7 +812,7 @@ def __test_verified_number_with_map(self, contact):
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for BACKEND2'))
self.assertTrue(send_message_to_verified_number(verified_number, 'Test for BACKEND2'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend2.pk)

Expand All @@ -823,7 +823,7 @@ def __test_verified_number_with_map(self, contact):
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for BACKEND5'))
self.assertTrue(send_message_to_verified_number(verified_number, 'Test for BACKEND5'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend5.pk)

Expand All @@ -841,7 +841,7 @@ def __test_contact_level_backend(self, contact):
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for domain BACKEND'))
self.assertTrue(send_message_to_verified_number(verified_number, 'Test for domain BACKEND'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend8.pk)

Expand All @@ -853,7 +853,7 @@ def __test_contact_level_backend(self, contact):
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for shared domain BACKEND'))
self.assertTrue(send_message_to_verified_number(verified_number, 'Test for shared domain BACKEND'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend9.pk)

Expand All @@ -865,7 +865,7 @@ def __test_contact_level_backend(self, contact):
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for global BACKEND'))
self.assertTrue(send_message_to_verified_number(verified_number, 'Test for global BACKEND'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend10.pk)

Expand All @@ -874,7 +874,7 @@ def __test_contact_level_backend(self, contact):
self.backend10.save()

with self.assertRaises(BadSMSConfigException):
send_sms_to_verified_number(verified_number, 'Test for unknown BACKEND')
send_message_to_verified_number(verified_number, 'Test for unknown BACKEND')

def __test_send_sms_with_backend(self):
with patch(
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/sms/tests/test_form_session_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_incoming_sms_linked_form_session__session_contact_matches_incoming(self
self.assertEqual(session_info.session_id, session.session_id)

@patch('corehq.apps.sms.handlers.form_session.answer_next_question', MagicMock(return_value=None))
@patch('corehq.apps.sms.handlers.form_session.send_sms_to_verified_number', MagicMock(return_value=None))
@patch('corehq.apps.sms.handlers.form_session.send_message_to_verified_number', MagicMock(return_value=None))
def test_incoming_sms_linked_form_session__session_contact_different_from_incoming(self):
session = self._make_session(self.number2)
self._claim_channel(session)
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/sms/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from corehq.apps.sms.api import (
MessageMetadata,
send_sms,
send_sms_to_verified_number,
send_message_to_verified_number,
)
from corehq.apps.sms.mixin import PhoneNumberInUseException, apply_leniency
from corehq.apps.sms.models import (
Expand Down Expand Up @@ -135,7 +135,7 @@ def process_verification(verified_number, msg, verification_keywords=None, creat
messages.MSG_VERIFICATION_SUCCESSFUL,
verified_number=verified_number
)
send_sms_to_verified_number(verified_number, message,
send_message_to_verified_number(verified_number, message,
metadata=MessageMetadata(messaging_subevent_id=subevent.pk))
subevent.completed()
return True
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/sms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
get_inbound_phone_entry,
incoming,
send_sms,
send_sms_to_verified_number,
send_message_to_verified_number,
send_sms_with_backend_name,
)
from corehq.apps.sms.forms import (
Expand Down Expand Up @@ -543,7 +543,7 @@ def api_send_sms(request, domain):
if backend_id is not None:
success = send_sms_with_backend_name(domain, phone_number, text, backend_id, metadata)
elif vn is not None:
success = send_sms_to_verified_number(vn, text, metadata)
success = send_message_to_verified_number(vn, text, metadata)
else:
success = send_sms(domain, None, phone_number, text, metadata)

Expand Down
6 changes: 3 additions & 3 deletions corehq/apps/smsforms/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from corehq.apps.sms.api import (
MessageMetadata,
send_sms,
send_sms_to_verified_number,
send_message_to_verified_number,
)
from corehq.apps.sms.models import PhoneNumber
from corehq.apps.sms.util import format_message_list
Expand Down Expand Up @@ -77,7 +77,7 @@ def send_first_message(domain, recipient, phone_entry_or_number, session, respon
)

if isinstance(phone_entry_or_number, PhoneNumber):
send_sms_to_verified_number(
send_message_to_verified_number(
phone_entry_or_number,
message,
metadata,
Expand Down Expand Up @@ -134,7 +134,7 @@ def handle_due_survey_action(domain, contact_id, session_id):
messaging_subevent_id=subevent.pk if subevent else None
)
resp = FormplayerInterface(session.session_id, domain).current_question()
send_sms_to_verified_number(
send_message_to_verified_number(
p,
resp.event.text_prompt,
metadata,
Expand Down

0 comments on commit 460c794

Please sign in to comment.