def test_send_pdf_letter_notification_raises_error_when_pdf_is_not_in_transient_letter_bucket( mocker, sample_service_full_permissions, fake_uuid, notify_user, ): user = sample_service_full_permissions.users[0] post_data = {'filename': 'valid.pdf', 'created_by': user.id, 'file_id': fake_uuid, 'postage': 'first', 'recipient_address': 'Bugs%20Bunny%0A123%20Main%20Street%0ALooney%20Town'} mocker.patch('app.service.send_notification.utils_s3download', side_effect=S3ObjectNotFound({}, '')) with pytest.raises(S3ObjectNotFound): send_pdf_letter_notification(sample_service_full_permissions.id, post_data)
def test_send_pdf_letter_notification_raises_error_when_pdf_is_not_in_transient_letter_bucket( mocker, sample_service_full_permissions, fake_uuid, notify_user, ): user = sample_service_full_permissions.users[0] post_data = { 'filename': 'valid.pdf', 'created_by': user.id, 'file_id': fake_uuid } mocker.patch('app.service.send_notification.utils_s3download', side_effect=S3ObjectNotFound({}, '')) with pytest.raises(S3ObjectNotFound): send_pdf_letter_notification(sample_service_full_permissions.id, post_data)
assert mocked_cache_get.call_args_list[0][0][ 0] == 'test-template-preview-cache' assert mocked_cache_get.call_args_list[0][0][1] == expected_cache_key assert mocked_cache_set.call_count == 2 mocked_cache_set.call_args_list[1][0][0].seek(0) assert mocked_cache_set.call_args_list[1][0][0].read() == resp.get_data() assert mocked_cache_set.call_args_list[1][0][1] == 'eu-west-1' assert mocked_cache_set.call_args_list[1][0][ 2] == 'test-template-preview-cache' assert mocked_cache_set.call_args_list[1][0][3] == expected_cache_key @pytest.mark.parametrize( 'side_effects, number_of_cache_get_calls, number_of_cache_set_calls', [ ( [S3ObjectNotFound({}, ''), S3ObjectNotFound({}, '')], 2, 2, ), ( [NonIterableIO(b'\x00'), S3ObjectNotFound({}, '')], 1, 0, ), ( [S3ObjectNotFound({}, ''), NonIterableIO(valid_letter)], 2, 1,
def mocked_cache_get(mocker): return mocker.patch('app.s3download', side_effect=S3ObjectNotFound({}, ''))