mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
code review feedback
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
import botocore
|
import botocore
|
||||||
from boto3 import Session
|
from boto3 import Session
|
||||||
from expiringdict import ExpiringDict
|
from expiringdict import ExpiringDict
|
||||||
@@ -8,7 +10,7 @@ from app.clients import AWS_CLIENT_CONFIG
|
|||||||
FILE_LOCATION_STRUCTURE = "service-{}-notify/{}.csv"
|
FILE_LOCATION_STRUCTURE = "service-{}-notify/{}.csv"
|
||||||
|
|
||||||
|
|
||||||
JOBS = ExpiringDict(max_len=100, max_age_seconds=3600)
|
JOBS = ExpiringDict(max_len=100, max_age_seconds=3600 * 4)
|
||||||
|
|
||||||
|
|
||||||
def get_s3_file(bucket_name, file_location, access_key, secret_key, region):
|
def get_s3_file(bucket_name, file_location, access_key, secret_key, region):
|
||||||
@@ -91,11 +93,7 @@ def get_phone_number_from_s3(service_id, job_id, job_row_number):
|
|||||||
correct_row = correct_row.split(",")
|
correct_row = correct_row.split(",")
|
||||||
|
|
||||||
my_phone = correct_row[phone_index]
|
my_phone = correct_row[phone_index]
|
||||||
my_phone = my_phone.replace("(", "")
|
my_phone = re.sub(r"[\+\s\(\)\-\.]*", "", my_phone)
|
||||||
my_phone = my_phone.replace(")", "")
|
|
||||||
my_phone = my_phone.replace("-", "")
|
|
||||||
my_phone = my_phone.replace(" ", "")
|
|
||||||
my_phone = my_phone.replace("+", "")
|
|
||||||
return my_phone
|
return my_phone
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ DELIVERY_RECEIPT_DELAY_IN_SECONDS = 120
|
|||||||
@notify_celery.task(
|
@notify_celery.task(
|
||||||
bind=True,
|
bind=True,
|
||||||
name="check_sms_delivery_receipt",
|
name="check_sms_delivery_receipt",
|
||||||
max_retries=12,
|
max_retries=48,
|
||||||
default_retry_delay=300,
|
default_retry_delay=300,
|
||||||
)
|
)
|
||||||
def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
||||||
@@ -92,7 +92,7 @@ def check_sms_delivery_receipt(self, message_id, notification_id, sent_at):
|
|||||||
|
|
||||||
|
|
||||||
@notify_celery.task(
|
@notify_celery.task(
|
||||||
bind=True, name="deliver_sms", max_retries=12, default_retry_delay=300
|
bind=True, name="deliver_sms", max_retries=48, default_retry_delay=300
|
||||||
)
|
)
|
||||||
def deliver_sms(self, notification_id):
|
def deliver_sms(self, notification_id):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -81,7 +81,12 @@ def send_sms_to_provider(notification):
|
|||||||
if my_phone:
|
if my_phone:
|
||||||
my_phone = my_phone.decode("utf-8")
|
my_phone = my_phone.decode("utf-8")
|
||||||
if my_phone is None:
|
if my_phone is None:
|
||||||
raise Exception("what happened to the phone number")
|
si = notification.service_id
|
||||||
|
ji = notification.job_id
|
||||||
|
jrn = notification.job_row_number
|
||||||
|
raise Exception(
|
||||||
|
f"The phone number for (Service ID: {si}; Job ID: {ji}; Job Row Number {jrn} was not found."
|
||||||
|
)
|
||||||
send_sms_kwargs = {
|
send_sms_kwargs = {
|
||||||
"to": my_phone,
|
"to": my_phone,
|
||||||
"content": str(template),
|
"content": str(template),
|
||||||
|
|||||||
@@ -50,11 +50,17 @@ def test_get_s3_file_makes_correct_call(notify_api, mocker):
|
|||||||
[
|
[
|
||||||
("phone number\r\n+15555555555", "aaa", 0, "15555555555"),
|
("phone number\r\n+15555555555", "aaa", 0, "15555555555"),
|
||||||
(
|
(
|
||||||
"day of week,favorite color,phone number\r\nmonday,green,15551111111\r\ntuesday,red,15552222222",
|
"day of week,favorite color,phone number\r\nmonday,green,1.555.111.1111\r\ntuesday,red,+1 (555) 222-2222",
|
||||||
"bbb",
|
"bbb",
|
||||||
1,
|
1,
|
||||||
"15552222222",
|
"15552222222",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"day of week,favorite color,phone number\r\nmonday,green,1.555.111.1111\r\ntuesday,red,+1 (555) 222-2222",
|
||||||
|
"ccc",
|
||||||
|
0,
|
||||||
|
"15551111111",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_phone_number_from_s3(
|
def test_get_phone_number_from_s3(
|
||||||
|
|||||||
Reference in New Issue
Block a user