Skip to content

Commit

Permalink
Merge pull request #954 from mild-blue/sms_service
Browse files Browse the repository at this point in the history
Use post with new sms service
  • Loading branch information
kubantjan authored Aug 5, 2022
2 parents 09cdf7d + 40fefe5 commit 944f798
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
32 changes: 16 additions & 16 deletions tests/auth/user/test_sms_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,37 @@ class TestSmsService(TestCase):
@responses.activate
def test__send_sms(self):
app_config = mock.MagicMock()
app_config.sms_service_url = 'https://some.domain/isg/index.php'
app_config.sms_service_url = 'https://some.domain/SendSms'
app_config.sms_service_sender = 'sender1'
app_config.sms_service_login = 'test'
app_config.sms_service_password = 'test123'

phone = '+420602613357'
body = 'Test'

# encoded URL for the previous input
expected_url = 'https://some.domain/isg/index.php?' \
'cmd=send&' \
'sender=sender1&' \
'login=test&' \
'password=test123&' \
'phone=%2B420602613357&' \
'message=Test'
expected_json = {
'login': app_config.sms_service_login,
'password': app_config.sms_service_password,
'phone': phone,
'message': body,
'sender': app_config.sms_service_sender
}

responses.add(
'GET',
url=expected_url,
match_querystring=True,
status=200
'POST',
url=app_config.sms_service_url,
status=200,
match=[
responses.json_params_matcher(expected_json)
]
)

_send_otp_ikem(recipient_phone=phone, message_body=body, app_config=app_config)

@responses.activate
def test__send_sms_should_fail(self):
app_config = mock.MagicMock()
app_config.sms_service_url = 'https://some.domain/isg/index.php'
app_config.sms_service_url = 'https://some.domain/SendSms'
app_config.sms_service_sender = 'sender1'
app_config.sms_service_login = 'test'
app_config.sms_service_password = 'test123'
Expand All @@ -48,9 +49,8 @@ def test__send_sms_should_fail(self):
body = 'Test'

responses.add(
'GET',
'POST',
url=app_config.sms_service_url,
match_querystring=False,
status=500,
json='{\"error\":\"some error\"}'
)
Expand Down
7 changes: 3 additions & 4 deletions txmatching/auth/user/sms_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ def _send_otp_ikem(recipient_phone: str, message_body: str, app_config: Applicat
require_auth_condition(bool(app_config.sms_service_password), 'SMS service password is not set!')

params = {
'cmd': 'send',
'sender': app_config.sms_service_sender,
'login': app_config.sms_service_login,
'password': app_config.sms_service_password,
'phone': recipient_phone,
'message': message_body
'message': message_body,
'sender': app_config.sms_service_sender
}
try:
sms_request = requests.get(app_config.sms_service_url, params=params)
sms_request = requests.post(app_config.sms_service_url, json=params)
if sms_request.status_code != 200:
raise CouldNotSendOtpUsingSmsServiceException(
f'SMS gate responded with status code: {sms_request.status_code} '
Expand Down

0 comments on commit 944f798

Please sign in to comment.