def test_collate_letter_pdfs_for_day(notify_api, mocker): mock_s3 = mocker.patch('app.celery.tasks.s3.get_s3_bucket_objects', return_value=[ {'Key': 'B.pDf', 'Size': 2}, {'Key': 'A.PDF', 'Size': 1}, {'Key': 'C.pdf', 'Size': 3} ]) mock_group_letters = mocker.patch('app.celery.letters_pdf_tasks.group_letters', return_value=[ [{'Key': 'A.PDF', 'Size': 1}, {'Key': 'B.pDf', 'Size': 2}], [{'Key': 'C.pdf', 'Size': 3}] ]) mock_celery = mocker.patch('app.celery.letters_pdf_tasks.notify_celery.send_task') collate_letter_pdfs_for_day('2017-01-02') mock_s3.assert_called_once_with('test-letters-pdf', subfolder='2017-01-02') mock_group_letters.assert_called_once_with(sorted(mock_s3.return_value, key=lambda x: x['Key'])) assert mock_celery.call_args_list[0] == call( name='zip-and-send-letter-pdfs', kwargs={ 'filenames_to_zip': ['A.PDF', 'B.pDf'], 'upload_filename': 'NOTIFY.2017-01-02.001.oqdjIM2-NAUU9Sm5Slmi.ZIP' }, queue='process-ftp-tasks', compression='zlib' ) assert mock_celery.call_args_list[1] == call( name='zip-and-send-letter-pdfs', kwargs={ 'filenames_to_zip': ['C.pdf'], 'upload_filename': 'NOTIFY.2017-01-02.002.tdr7hcdPieiqjkVoS4kU.ZIP' }, queue='process-ftp-tasks', compression='zlib' )
def test_collate_letter_pdfs_for_day_works_without_date_param( notify_api, mocker): mock_s3 = mocker.patch("app.celery.tasks.s3.get_s3_bucket_objects") collate_letter_pdfs_for_day() expected_date = "2018-09-12" mock_s3.assert_called_once_with("test-letters-pdf", subfolder=expected_date)
def test_upload_letter_pdf_to_correct_bucket(sample_letter_notification, mocker, is_precompiled_letter, bucket_config_name): if is_precompiled_letter: sample_letter_notification.template.hidden = True sample_letter_notification.template.name = PRECOMPILED_TEMPLATE_NAME mock_s3 = mocker.patch("app.letters.utils.s3upload") filename = get_letter_pdf_filename( reference=sample_letter_notification.reference, crown=sample_letter_notification.service.crown, is_scan_letter=is_precompiled_letter, ) upload_letter_pdf(sample_letter_notification, b"\x00\x01", precompiled=is_precompiled_letter) mock_s3.assert_called_once_with( bucket_name=current_app.config[bucket_config_name], file_location=filename, filedata=b"\x00\x01", region=current_app.config["AWS_REGION"], )
def test_upload_letter_pdf_uses_postage_from_notification( sample_letter_template, mocker, postage, expected_postage): letter_notification = create_notification(template=sample_letter_template, postage=postage) mock_s3 = mocker.patch('app.letters.utils.s3upload') filename = upload_letter_pdf(letter_notification, b'\x00\x01', precompiled=False) mock_s3.assert_called_once_with( bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'], file_location=filename, filedata=b'\x00\x01', region=current_app.config['AWS_REGION'])
def test_upload_letter_pdf_to_correct_bucket(sample_letter_notification, mocker, is_precompiled_letter, bucket_config_name): if is_precompiled_letter: sample_letter_notification.template.hidden = True sample_letter_notification.template.name = PRECOMPILED_TEMPLATE_NAME mock_s3 = mocker.patch('app.letters.utils.s3upload') filename = upload_letter_pdf(sample_letter_notification, b'\x00\x01', precompiled=is_precompiled_letter) mock_s3.assert_called_once_with( bucket_name=current_app.config[bucket_config_name], file_location=filename, filedata=b'\x00\x01', region=current_app.config['AWS_REGION'])
def test_upload_letter_pdf_uses_postage_from_notification( sample_letter_template, mocker, postage, expected_postage): letter_notification = create_notification(template=sample_letter_template, postage=postage) mock_s3 = mocker.patch("app.letters.utils.s3upload") filename = get_letter_pdf_filename( reference=letter_notification.reference, crown=letter_notification.service.crown, is_scan_letter=False, postage=letter_notification.postage, ) upload_letter_pdf(letter_notification, b"\x00\x01", precompiled=False) mock_s3.assert_called_once_with( bucket_name=current_app.config["LETTERS_PDF_BUCKET_NAME"], file_location=filename, filedata=b"\x00\x01", region=current_app.config["AWS_REGION"], )
def test_collate_letter_pdfs_for_day(notify_api, mocker): mock_s3 = mocker.patch( "app.celery.tasks.s3.get_s3_bucket_objects", return_value=[ { "Key": "B.pDf", "Size": 2 }, { "Key": "A.PDF", "Size": 1 }, { "Key": "C.pdf", "Size": 3 }, ], ) mock_group_letters = mocker.patch( "app.celery.letters_pdf_tasks.group_letters", return_value=[ [{ "Key": "A.PDF", "Size": 1 }, { "Key": "B.pDf", "Size": 2 }], [{ "Key": "C.pdf", "Size": 3 }], ], ) mock_celery = mocker.patch( "app.celery.letters_pdf_tasks.notify_celery.send_task") collate_letter_pdfs_for_day("2017-01-02") mock_s3.assert_called_once_with("test-letters-pdf", subfolder="2017-01-02") mock_group_letters.assert_called_once_with( sorted(mock_s3.return_value, key=lambda x: x["Key"])) assert mock_celery.call_args_list[0] == call( name="zip-and-send-letter-pdfs", kwargs={ "filenames_to_zip": ["A.PDF", "B.pDf"], "upload_filename": "NOTIFY.2017-01-02.001.oqdjIM2-NAUU9Sm5Slmi.ZIP", }, queue="process-ftp-tasks", compression="zlib", ) assert mock_celery.call_args_list[1] == call( name="zip-and-send-letter-pdfs", kwargs={ "filenames_to_zip": ["C.pdf"], "upload_filename": "NOTIFY.2017-01-02.002.tdr7hcdPieiqjkVoS4kU.ZIP", }, queue="process-ftp-tasks", compression="zlib", )