Skip to content

Commit

Permalink
tests: test mail attachments mimetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Apr 27, 2024
1 parent 6ac4aad commit 288ad16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion canaille/app/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def logo():

def type_from_filename(filename):
filetype = mimetypes.guess_type(filename)
if not filetype or not filetype[0]: # pragma: no cover
if not filetype or not filetype[0]:
# For some reasons GHA fails to guess webp mimetypes
# According to MDN, the default mimetype should be application/octet-stream
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
return "application", "octet-stream"

maintype, subtype = filetype[0].split("/")
Expand Down
6 changes: 6 additions & 0 deletions tests/app/test_mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask_webtest import TestApp

from canaille import create_app
from canaille.app.mails import type_from_filename


@pytest.fixture
Expand Down Expand Up @@ -224,3 +225,8 @@ def test_default_from_flask_server_name(configuration, user, smtpd, backend):
res = res.form.submit(status=200)
assert smtpd.messages[0]["X-MailFrom"] == "[email protected]"
assert smtpd.messages[0]["From"] == '"Canaille" <[email protected]>'


def test_type_from_filename():
assert type_from_filename("index.html") == ("text", "html")
assert type_from_filename("unknown") == ("application", "octet-stream")

0 comments on commit 288ad16

Please sign in to comment.