diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7e551303..d98b99db 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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: diff --git a/canaille/app/mails.py b/canaille/app/mails.py index e2e015e1..81eced5f 100644 --- a/canaille/app/mails.py +++ b/canaille/app/mails.py @@ -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 ) diff --git a/canaille/core/endpoints/admin.py b/canaille/core/endpoints/admin.py index 3bb6e0c7..8a3c6682 100644 --- a/canaille/core/endpoints/admin.py +++ b/canaille/core/endpoints/admin.py @@ -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") diff --git a/tests/app/test_mails.py b/tests/app/test_mails.py index ab5c6e7f..7061f592 100644 --- a/tests/app/test_mails.py +++ b/tests/app/test_mails.py @@ -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