mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 16:48:31 -04:00
tests are, uh, mostly passing
This commit is contained in:
@@ -8,6 +8,7 @@ def find_by_service_name(services, service_name):
|
||||
return services[i]
|
||||
return None
|
||||
|
||||
|
||||
def extract_cloudfoundry_config():
|
||||
vcap_services = json.loads(os.environ['VCAP_SERVICES'])
|
||||
|
||||
@@ -18,7 +19,10 @@ def extract_cloudfoundry_config():
|
||||
os.environ['REDIS_URL'] = vcap_services['aws-elasticache-redis'][0]['credentials']['uri'].replace('redis', 'rediss')
|
||||
|
||||
# CSV Upload Bucket Name
|
||||
bucket_service = find_by_service_name(vcap_services['s3'], f"notifications-api-csv-upload-bucket-{os.environ['DEPLOY_ENV']}")
|
||||
bucket_service = find_by_service_name(
|
||||
vcap_services['s3'],
|
||||
f"notifications-api-csv-upload-bucket-{os.environ['DEPLOY_ENV']}"
|
||||
)
|
||||
if bucket_service:
|
||||
os.environ['CSV_UPLOAD_BUCKET_NAME'] = bucket_service['credentials']['bucket']
|
||||
os.environ['CSV_UPLOAD_ACCESS_KEY'] = bucket_service['credentials']['access_key_id']
|
||||
@@ -26,7 +30,10 @@ def extract_cloudfoundry_config():
|
||||
os.environ['CSV_UPLOAD_REGION'] = bucket_service['credentials']['region']
|
||||
|
||||
# Contact List Bucket Name
|
||||
bucket_service = find_by_service_name(vcap_services['s3'], f"notifications-api-contact-list-bucket-{os.environ['DEPLOY_ENV']}")
|
||||
bucket_service = find_by_service_name(
|
||||
vcap_services['s3'],
|
||||
f"notifications-api-contact-list-bucket-{os.environ['DEPLOY_ENV']}"
|
||||
)
|
||||
if bucket_service:
|
||||
os.environ['CONTACT_LIST_BUCKET_NAME'] = bucket_service['credentials']['bucket']
|
||||
os.environ['CONTACT_LIST_ACCESS_KEY'] = bucket_service['credentials']['access_key_id']
|
||||
|
||||
@@ -40,7 +40,6 @@ from app.dao.organisation_dao import (
|
||||
dao_get_organisation_by_email_address,
|
||||
dao_get_organisation_by_id,
|
||||
)
|
||||
from app.dao.permissions_dao import permission_dao
|
||||
from app.dao.services_dao import (
|
||||
dao_fetch_all_services_by_user,
|
||||
dao_fetch_all_services_created_by_user,
|
||||
@@ -64,7 +63,6 @@ from app.models import (
|
||||
LetterBranding,
|
||||
Notification,
|
||||
Organisation,
|
||||
Permission,
|
||||
Service,
|
||||
User,
|
||||
)
|
||||
@@ -151,8 +149,8 @@ def backfill_notification_statuses():
|
||||
`Notification._status_enum`
|
||||
"""
|
||||
LIMIT = 250000
|
||||
subq = "SELECT id FROM notification_history WHERE notification_status is NULL LIMIT {}".format(LIMIT) # nosec B608 no user-controlled input
|
||||
update = "UPDATE notification_history SET notification_status = status WHERE id in ({})".format(subq) # nosec B608 no user-controlled input
|
||||
subq = "SELECT id FROM notification_history WHERE notification_status is NULL LIMIT {}".format(LIMIT) # nosec B608 no user-controlled input
|
||||
update = "UPDATE notification_history SET notification_status = status WHERE id in ({})".format(subq) # nosec B608 no user-controlled input
|
||||
result = db.session.execute(subq).fetchall()
|
||||
|
||||
while len(result) > 0:
|
||||
@@ -169,7 +167,7 @@ def update_notification_international_flag():
|
||||
"""
|
||||
# 250,000 rows takes 30 seconds to update.
|
||||
subq = "select id from notifications where international is null limit 250000"
|
||||
update = "update notifications set international = False where id in ({})".format(subq) # nosec B608 no user-controlled input
|
||||
update = "update notifications set international = False where id in ({})".format(subq) # nosec B608 no user-controlled input
|
||||
result = db.session.execute(subq).fetchall()
|
||||
|
||||
while len(result) > 0:
|
||||
@@ -180,7 +178,7 @@ def update_notification_international_flag():
|
||||
|
||||
# Now update notification_history
|
||||
subq_history = "select id from notification_history where international is null limit 250000"
|
||||
update_history = "update notification_history set international = False where id in ({})".format(subq_history) # nosec B608 no user-controlled input
|
||||
update_history = "update notification_history set international = False where id in ({})".format(subq_history) # nosec B608 no user-controlled input
|
||||
result_history = db.session.execute(subq_history).fetchall()
|
||||
while len(result_history) > 0:
|
||||
db.session.execute(update_history)
|
||||
@@ -201,8 +199,8 @@ def fix_notification_statuses_not_in_sync():
|
||||
"""
|
||||
MAX = 10000
|
||||
|
||||
subq = "SELECT id FROM notifications WHERE cast (status as text) != notification_status LIMIT {}".format(MAX) # nosec B608 no user-controlled input
|
||||
update = "UPDATE notifications SET notification_status = status WHERE id in ({})".format(subq) # nosec B608 no user-controlled input
|
||||
subq = "SELECT id FROM notifications WHERE cast (status as text) != notification_status LIMIT {}".format(MAX) # nosec B608 no user-controlled input
|
||||
update = "UPDATE notifications SET notification_status = status WHERE id in ({})".format(subq) # nosec B608 no user-controlled input
|
||||
result = db.session.execute(subq).fetchall()
|
||||
|
||||
while len(result) > 0:
|
||||
@@ -212,7 +210,7 @@ def fix_notification_statuses_not_in_sync():
|
||||
result = db.session.execute(subq).fetchall()
|
||||
|
||||
subq_hist = "SELECT id FROM notification_history WHERE cast (status as text) != notification_status LIMIT {}".format(MAX) # nosec B608
|
||||
update = "UPDATE notification_history SET notification_status = status WHERE id in ({})".format(subq_hist) # nosec B608 no user-controlled input
|
||||
update = "UPDATE notification_history SET notification_status = status WHERE id in ({})".format(subq_hist) # nosec B608 no user-controlled input
|
||||
result = db.session.execute(subq_hist).fetchall()
|
||||
|
||||
while len(result) > 0:
|
||||
|
||||
@@ -144,7 +144,7 @@ class Config(object):
|
||||
MAX_VERIFY_CODE_COUNT = 5
|
||||
MAX_FAILED_LOGIN_COUNT = 10
|
||||
|
||||
SES_STUB_URL = None # TODO: set to a URL in env and remove this to use a stubbed SES service
|
||||
SES_STUB_URL = None # TODO: set to a URL in env and remove this to use a stubbed SES service
|
||||
|
||||
# be careful increasing this size without being sure that we won't see slowness in pysftp
|
||||
MAX_LETTER_PDF_ZIP_FILESIZE = 40 * 1024 * 1024 # 40mb
|
||||
@@ -164,7 +164,7 @@ class Config(object):
|
||||
SMS_CODE_TEMPLATE_ID = '36fb0730-6259-4da1-8a80-c8de22ad4246'
|
||||
EMAIL_2FA_TEMPLATE_ID = '299726d2-dba6-42b8-8209-30e1d66ea164'
|
||||
NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID = 'ece42649-22a8-4d06-b87f-d52d5d3f0a27'
|
||||
PASSWORD_RESET_TEMPLATE_ID = '474e9242-823b-4f99-813d-ed392e7f1201' # nosec B105 - this is not a password
|
||||
PASSWORD_RESET_TEMPLATE_ID = '474e9242-823b-4f99-813d-ed392e7f1201' # nosec B105 - this is not a password
|
||||
ALREADY_REGISTERED_EMAIL_TEMPLATE_ID = '0880fbb1-a0c6-46f0-9a8e-36c986381ceb'
|
||||
CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID = 'eb4d9930-87ab-4aef-9bce-786762687884'
|
||||
SERVICE_NOW_LIVE_TEMPLATE_ID = '618185c6-3636-49cd-b7d2-6f6f5eb3bdde'
|
||||
|
||||
@@ -28,12 +28,7 @@ from app.dao.templates_dao import (
|
||||
)
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.letters.utils import get_letter_pdf_and_metadata
|
||||
from app.models import (
|
||||
LETTER_TYPE,
|
||||
SECOND_CLASS,
|
||||
SMS_TYPE,
|
||||
Template,
|
||||
)
|
||||
from app.models import LETTER_TYPE, SECOND_CLASS, SMS_TYPE, Template
|
||||
from app.notifications.validators import check_reply_to, service_has_permission
|
||||
from app.schema_validation import validate
|
||||
from app.schemas import (
|
||||
@@ -171,6 +166,7 @@ def get_all_templates_for_service(service_id):
|
||||
data = template_schema.dump(templates, many=True)
|
||||
else:
|
||||
data = template_schema_no_detail.dump(templates, many=True)
|
||||
print(data)
|
||||
return jsonify(data=data)
|
||||
|
||||
|
||||
|
||||
@@ -380,7 +380,7 @@ def send_new_user_email_verification(user_id):
|
||||
|
||||
template = dao_get_template_by_id(current_app.config['NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID'])
|
||||
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
|
||||
|
||||
|
||||
current_app.logger.info('template.id is {}'.format(template.id))
|
||||
current_app.logger.info('service.id is {}'.format(service.id))
|
||||
|
||||
@@ -438,11 +438,11 @@ def send_already_registered_email(user_id):
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
reply_to_text=service.get_default_reply_to_email_address()
|
||||
)
|
||||
|
||||
|
||||
current_app.logger.info('Sending notification to queue')
|
||||
|
||||
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
|
||||
|
||||
|
||||
current_app.logger.info('Sent notification to queue')
|
||||
|
||||
return jsonify({}), 204
|
||||
|
||||
@@ -87,11 +87,7 @@ def get_london_month_from_utc_column(column):
|
||||
|
||||
|
||||
def get_public_notify_type_text(notify_type, plural=False):
|
||||
from app.models import (
|
||||
PRECOMPILED_LETTER,
|
||||
SMS_TYPE,
|
||||
UPLOAD_DOCUMENT,
|
||||
)
|
||||
from app.models import PRECOMPILED_LETTER, SMS_TYPE, UPLOAD_DOCUMENT
|
||||
notify_type_text = notify_type
|
||||
if notify_type == SMS_TYPE:
|
||||
notify_type_text = 'text message'
|
||||
|
||||
Reference in New Issue
Block a user