mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Fix merge error.
Moved the billable unit calculation before the santise call.
This commit is contained in:
@@ -41,7 +41,6 @@ from app.models import (
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_VALIDATION_FAILED,
|
||||
NOTIFICATION_VIRUS_SCAN_FAILED,
|
||||
@@ -189,6 +188,8 @@ def process_virus_scan_passed(self, filename):
|
||||
scan_pdf_object = s3.get_s3_object(current_app.config['LETTERS_SCAN_BUCKET_NAME'], filename)
|
||||
old_pdf = scan_pdf_object.get()['Body'].read()
|
||||
|
||||
billable_units = _get_page_count(notification, old_pdf)
|
||||
|
||||
new_pdf = _sanitise_precomiled_pdf(self, notification, old_pdf)
|
||||
|
||||
# TODO: Remove this once CYSP update their template to not cross over the margins
|
||||
@@ -213,12 +214,10 @@ def process_virus_scan_passed(self, filename):
|
||||
|
||||
# temporarily upload original pdf while testing sanitise flow.
|
||||
_upload_pdf_to_test_or_live_pdf_bucket(
|
||||
old_pdf, # TODO: change to new_pdf
|
||||
new_pdf,
|
||||
filename,
|
||||
is_test_letter=is_test_key)
|
||||
|
||||
billable_units = _get_page_count(notification, old_pdf)
|
||||
|
||||
update_letter_pdf_status(
|
||||
reference=reference,
|
||||
status=NOTIFICATION_DELIVERED if is_test_key else NOTIFICATION_CREATED,
|
||||
@@ -238,7 +237,7 @@ def _get_page_count(notification, old_pdf):
|
||||
current_app.logger.exception(msg='Invalid PDF received for notification_id: {}'.format(notification.id))
|
||||
update_letter_pdf_status(
|
||||
reference=notification.reference,
|
||||
status=NOTIFICATION_PERMANENT_FAILURE
|
||||
status=NOTIFICATION_VALIDATION_FAILED
|
||||
)
|
||||
raise e
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ from app.models import (
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_VALIDATION_FAILED,
|
||||
@@ -362,9 +361,9 @@ def test_process_letter_task_check_virus_scan_passed(
|
||||
s3 = boto3.client('s3', region_name='eu-west-1')
|
||||
s3.put_object(Bucket=source_bucket_name, Key=filename, Body=b'pdf_content')
|
||||
|
||||
mocker.patch('app.celery.letters_pdf_tasks.pdf_page_count', return_value=1)
|
||||
mock_get_page_count = mocker.patch('app.celery.letters_pdf_tasks._get_page_count', return_value=1)
|
||||
mock_s3upload = mocker.patch('app.celery.letters_pdf_tasks.s3upload')
|
||||
mock_sanitise = mocker.patch('app.celery.letters_pdf_tasks._sanitise_precomiled_pdf', return_value="pdf_content")
|
||||
mock_sanitise = mocker.patch('app.celery.letters_pdf_tasks._sanitise_precomiled_pdf', return_value=b'pdf_content')
|
||||
|
||||
process_virus_scan_passed(filename)
|
||||
|
||||
@@ -381,6 +380,10 @@ def test_process_letter_task_check_virus_scan_passed(
|
||||
file_location=destination_folder + filename,
|
||||
region='eu-west-1',
|
||||
)
|
||||
mock_get_page_count.assert_called_once_with(
|
||||
letter_notification,
|
||||
b'pdf_content'
|
||||
)
|
||||
|
||||
|
||||
@freeze_time('2018-01-01 18:00')
|
||||
@@ -406,6 +409,7 @@ def test_process_letter_task_check_virus_scan_passed_when_sanitise_fails(
|
||||
sample_letter_notification.key_type = key_type
|
||||
mock_move_s3 = mocker.patch('app.letters.utils._move_s3_object')
|
||||
mock_sanitise = mocker.patch('app.celery.letters_pdf_tasks._sanitise_precomiled_pdf', return_value=None)
|
||||
mock_get_page_count = mocker.patch('app.celery.letters_pdf_tasks._get_page_count', return_value=2)
|
||||
|
||||
process_virus_scan_passed(filename)
|
||||
|
||||
@@ -420,6 +424,10 @@ def test_process_letter_task_check_virus_scan_passed_when_sanitise_fails(
|
||||
target_bucket_name, filename
|
||||
)
|
||||
|
||||
mock_get_page_count.assert_called_once_with(
|
||||
sample_letter_notification, b'pdf_content'
|
||||
)
|
||||
|
||||
|
||||
def test_get_page_count_set_notification_to_permanent_failure_when_not_pdf(
|
||||
sample_letter_notification
|
||||
@@ -427,7 +435,7 @@ def test_get_page_count_set_notification_to_permanent_failure_when_not_pdf(
|
||||
with pytest.raises(expected_exception=PdfReadError):
|
||||
_get_page_count(sample_letter_notification, b'pdf_content')
|
||||
updated_notification = Notification.query.filter_by(id=sample_letter_notification.id).first()
|
||||
assert updated_notification.status == NOTIFICATION_PERMANENT_FAILURE
|
||||
assert updated_notification.status == NOTIFICATION_VALIDATION_FAILED
|
||||
|
||||
|
||||
def test_process_letter_task_check_virus_scan_failed(sample_letter_notification, mocker):
|
||||
|
||||
Reference in New Issue
Block a user