tests: fix GHA

For some reasons, webp mimetypes failed to be guessed on GHA.
This commit is contained in:
Éloi Rivard 2024-04-27 14:06:15 +02:00
parent 444e6b135c
commit ebcaaeaded
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
4 changed files with 23 additions and 17 deletions

View file

@ -42,7 +42,7 @@ jobs:
export TZ=UTC
poetry --version
poetry install --extras all
poetry run pytest -x
poetry run pytest --showlocals
minversions:
name: minimum dependency versions
runs-on: ubuntu-latest
@ -70,7 +70,7 @@ jobs:
poetry --version
poetry lock
poetry install --extras all
poetry run pytest
poetry run pytest --showlocals
style:
runs-on: ubuntu-latest
steps:

View file

@ -38,6 +38,16 @@ def logo():
return logo_cid, logo_filename, logo_raw
def type_from_filename(filename):
filetype = mimetypes.guess_type(filename)
if not filetype or not filetype[0]: # pragma: no cover
# For some reasons GHA fails to guess webp mimetypes
return "application", "octet-stream"
maintype, subtype = filetype[0].split("/")
return maintype, subtype
def send_email(subject, recipient, text, html, attachements=None):
current_app.logger.debug(f"Sending a mail to {recipient}: {subject}")
msg = email.message.EmailMessage()
@ -58,11 +68,7 @@ def send_email(subject, recipient, text, html, attachements=None):
attachements = attachements or []
for cid, filename, value in attachements:
filetype = mimetypes.guess_type(filename)
if not filetype or not filetype[0]: # pragma: no cover
continue
maintype, subtype = filetype[0].split("/")
maintype, subtype = type_from_filename(filename)
msg.get_payload()[1].add_related(
value, maintype=maintype, subtype=subtype, cid=cid
)

View file

@ -39,9 +39,9 @@ def mail_index(user):
form = MailTestForm(request.form or None)
if request.form and form.validate():
if send_test_mail(form.email.data):
flash(_("The test invitation mail has been sent correctly"), "success")
flash(_("The test mail has been sent correctly"), "success")
else:
flash(_("The test invitation mail has not been sent correctly"), "error")
flash(_("The test mail has not been sent correctly"), "error")
return render_template("mails/admin.html", form=form, menuitem="admin")

View file

@ -23,7 +23,7 @@ def test_send_test_email(testclient, logged_admin, smtpd):
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 1
@ -45,7 +45,7 @@ def test_send_test_email_ssl(testclient, logged_admin, smtpd):
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 1
@ -62,7 +62,7 @@ def test_send_test_email_without_credentials(testclient, logged_admin, smtpd):
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 1
@ -80,7 +80,7 @@ def test_send_test_email_recipient_refused(SMTP, testclient, logged_admin, smtpd
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 0
@ -94,7 +94,7 @@ def test_send_test_email_failed(testclient, logged_admin):
res = res.form.submit(expect_errors=True)
assert (
"error",
"The test invitation mail has not been sent correctly",
"The test mail has not been sent correctly",
) in res.flashes
@ -107,7 +107,7 @@ def test_mail_with_default_no_logo(testclient, logged_admin, smtpd):
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 1
@ -129,7 +129,7 @@ def test_mail_with_default_logo(testclient, logged_admin, smtpd, httpserver):
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 1
@ -157,7 +157,7 @@ def test_mail_with_logo_in_http(testclient, logged_admin, smtpd, httpserver):
res = res.form.submit()
assert (
"success",
"The test invitation mail has been sent correctly",
"The test mail has been sent correctly",
) in res.flashes
assert len(smtpd.messages) == 1