-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility to send base64 encoded attachments to invenio-mail.
- Loading branch information
1 parent
94bf0ee
commit 97fd5b4
Showing
2 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2015-2018 CERN. | ||
# Copyright (C) 2023 University of Münster. | ||
# | ||
# Invenio is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
@@ -11,11 +12,6 @@ | |
|
||
from __future__ import absolute_import, print_function | ||
|
||
import os | ||
|
||
import pkg_resources | ||
from flask_mail import Attachment | ||
|
||
from invenio_mail.tasks import send_email | ||
|
||
|
||
|
@@ -70,3 +66,33 @@ def test_send_message_with_date(email_task_app): | |
|
||
result_stream = email_task_app.extensions["invenio-mail"].stream | ||
assert result_stream.getvalue().find("Date: Tue, 23 Feb 2016") != -1 | ||
|
||
|
||
def test_send_message_stream_with_attachment(email_task_app): | ||
"""Test sending a message with attachment using Task module.""" | ||
with email_task_app.app_context(): | ||
with email_task_app.extensions["mail"].record_messages() as outbox: | ||
msg = { | ||
"subject": "Test2", | ||
"sender": "[email protected]", | ||
"recipients": ["[email protected]"], | ||
"attachments": [ | ||
{ | ||
"base64": "RWluIGVpbmZhY2hlciBTdHJpbmcK", | ||
"disposition": "filename.bin", | ||
} | ||
], | ||
} | ||
|
||
send_email.delay(msg) | ||
|
||
result_stream = email_task_app.extensions["invenio-mail"].stream | ||
assert ( | ||
result_stream.getvalue().find("Content-Type: application/octet-stream") | ||
!= -1 | ||
) | ||
assert ( | ||
result_stream.getvalue().find("Content-Disposition: filename.bin;") | ||
!= -1 | ||
) | ||
assert result_stream.getvalue().find("RWluIGVpbmZhY2hlciBTdHJpbmcK") != -1 |