mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Set precompiled letters to pending virus check initially
This commit is contained in:
@@ -25,7 +25,8 @@ from app.models import (
|
|||||||
KEY_TYPE_TEAM,
|
KEY_TYPE_TEAM,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
NOTIFICATION_SENDING,
|
NOTIFICATION_SENDING,
|
||||||
NOTIFICATION_DELIVERED
|
NOTIFICATION_DELIVERED,
|
||||||
|
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||||
)
|
)
|
||||||
from app.celery.letters_pdf_tasks import create_letters_pdf
|
from app.celery.letters_pdf_tasks import create_letters_pdf
|
||||||
from app.celery.research_mode_tasks import create_fake_letter_response_file
|
from app.celery.research_mode_tasks import create_fake_letter_response_file
|
||||||
@@ -220,8 +221,15 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text
|
|||||||
if not api_key.service.research_mode and api_key.service.restricted and api_key.key_type != KEY_TYPE_TEST:
|
if not api_key.service.research_mode and api_key.service.restricted and api_key.key_type != KEY_TYPE_TEST:
|
||||||
raise BadRequestError(message='Cannot send letters when service is in trial mode', status_code=403)
|
raise BadRequestError(message='Cannot send letters when service is in trial mode', status_code=403)
|
||||||
|
|
||||||
|
should_send = not (api_key.service.research_mode or api_key.key_type == KEY_TYPE_TEST)
|
||||||
|
|
||||||
|
# if we don't want to actually send the letter, then start it off in SENDING so we don't pick it up
|
||||||
|
status = NOTIFICATION_CREATED if should_send else NOTIFICATION_SENDING
|
||||||
|
|
||||||
if precompiled:
|
if precompiled:
|
||||||
try:
|
try:
|
||||||
|
if should_send:
|
||||||
|
status = NOTIFICATION_PENDING_VIRUS_CHECK
|
||||||
letter_content = base64.b64decode(letter_data['content'])
|
letter_content = base64.b64decode(letter_data['content'])
|
||||||
pages = pdf_page_count(io.BytesIO(letter_content))
|
pages = pdf_page_count(io.BytesIO(letter_content))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -230,10 +238,6 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text
|
|||||||
current_app.logger.exception(msg='Invalid PDF received')
|
current_app.logger.exception(msg='Invalid PDF received')
|
||||||
raise BadRequestError(message='Letter content is not a valid PDF', status_code=400)
|
raise BadRequestError(message='Letter content is not a valid PDF', status_code=400)
|
||||||
|
|
||||||
should_send = not (api_key.service.research_mode or api_key.key_type == KEY_TYPE_TEST)
|
|
||||||
|
|
||||||
# if we don't want to actually send the letter, then start it off in SENDING so we don't pick it up
|
|
||||||
status = NOTIFICATION_CREATED if should_send else NOTIFICATION_SENDING
|
|
||||||
notification = create_letter_notification(letter_data=letter_data,
|
notification = create_letter_notification(letter_data=letter_data,
|
||||||
template=template,
|
template=template,
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ from freezegun import freeze_time
|
|||||||
from app.dao.service_sms_sender_dao import dao_update_service_sms_sender
|
from app.dao.service_sms_sender_dao import dao_update_service_sms_sender
|
||||||
from app.models import (
|
from app.models import (
|
||||||
ScheduledNotification,
|
ScheduledNotification,
|
||||||
SCHEDULE_NOTIFICATIONS,
|
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
|
NOTIFICATION_CREATED,
|
||||||
|
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||||
|
SCHEDULE_NOTIFICATIONS,
|
||||||
SMS_TYPE
|
SMS_TYPE
|
||||||
)
|
)
|
||||||
from flask import json, current_app
|
from flask import json, current_app
|
||||||
@@ -55,6 +57,7 @@ def test_post_sms_notification_returns_201(client, sample_template_with_placehol
|
|||||||
assert validate(resp_json, post_sms_response) == resp_json
|
assert validate(resp_json, post_sms_response) == resp_json
|
||||||
notifications = Notification.query.all()
|
notifications = Notification.query.all()
|
||||||
assert len(notifications) == 1
|
assert len(notifications) == 1
|
||||||
|
assert notifications[0].status == NOTIFICATION_CREATED
|
||||||
notification_id = notifications[0].id
|
notification_id = notifications[0].id
|
||||||
assert resp_json['id'] == str(notification_id)
|
assert resp_json['id'] == str(notification_id)
|
||||||
assert resp_json['reference'] == reference
|
assert resp_json['reference'] == reference
|
||||||
@@ -306,6 +309,7 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
|
|||||||
resp_json = json.loads(response.get_data(as_text=True))
|
resp_json = json.loads(response.get_data(as_text=True))
|
||||||
assert validate(resp_json, post_email_response) == resp_json
|
assert validate(resp_json, post_email_response) == resp_json
|
||||||
notification = Notification.query.one()
|
notification = Notification.query.one()
|
||||||
|
assert notification.status == NOTIFICATION_CREATED
|
||||||
assert resp_json['id'] == str(notification.id)
|
assert resp_json['id'] == str(notification.id)
|
||||||
assert resp_json['reference'] == reference
|
assert resp_json['reference'] == reference
|
||||||
assert notification.reference is None
|
assert notification.reference is None
|
||||||
@@ -756,6 +760,7 @@ def test_post_precompiled_letter_notification_returns_201(client, notify_user, m
|
|||||||
notification = Notification.query.first()
|
notification = Notification.query.first()
|
||||||
|
|
||||||
assert notification.billable_units == 3
|
assert notification.billable_units == 3
|
||||||
|
assert notification.status == NOTIFICATION_PENDING_VIRUS_CHECK
|
||||||
|
|
||||||
resp_json = json.loads(response.get_data(as_text=True))
|
resp_json = json.loads(response.get_data(as_text=True))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user