From 7373a99aec70b38d249d9aa23718dc5ca39db0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Tue, 15 Aug 2023 19:43:17 +0200 Subject: [PATCH] Speedup the tests by using a weaker hash algorythm --- la_chariotte/helpers/fixtures.py | 8 ++++++++ la_chariotte/mail/test_mail.py | 2 +- la_chariotte/mail/utils.py | 5 ++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/la_chariotte/helpers/fixtures.py b/la_chariotte/helpers/fixtures.py index 3498cd9..2d5e026 100644 --- a/la_chariotte/helpers/fixtures.py +++ b/la_chariotte/helpers/fixtures.py @@ -37,3 +37,11 @@ def simple_grouped_order(other_user): grouped_order.save() item = Item.objects.create(name="test item", grouped_order=grouped_order, price=2) return grouped_order + + +@pytest.fixture(autouse=True) +def password_hasher_setup(settings): + # Use a weaker password hasher during tests, for speed + settings.PASSWORD_HASHERS = [ + "django.contrib.auth.hashers.MD5PasswordHasher", + ] diff --git a/la_chariotte/mail/test_mail.py b/la_chariotte/mail/test_mail.py index 0166c37..aa7e039 100644 --- a/la_chariotte/mail/test_mail.py +++ b/la_chariotte/mail/test_mail.py @@ -35,7 +35,7 @@ def test_send_order_confirmation_mail(mailoutbox, simple_grouped_order, client): m = mailoutbox[0] assert ( m.subject - == f"[{settings.PROJECT_NAME}] Votre commande pour «Test grouped order»" + == f"[{settings.PROJECT_NAME}] Votre commande pour « Test grouped order »" ) assert f"{settings.BASE_URL}" in m.alternatives[0][0] assert m.alternatives[0][1] == "text/html" diff --git a/la_chariotte/mail/utils.py b/la_chariotte/mail/utils.py index 1ceb3d7..cb345df 100644 --- a/la_chariotte/mail/utils.py +++ b/la_chariotte/mail/utils.py @@ -1,16 +1,15 @@ import html2text +from django.conf import settings from django.core import mail from django.template.loader import render_to_string from django.utils.html import strip_tags -from la_chariotte import settings - def send_order_confirmation_mail(order): template_name = "mail/order_confirm_mail.html" subject = ( - f"[{settings.PROJECT_NAME}] Votre commande pour «{order.grouped_order.name}»" + f"[{settings.PROJECT_NAME}] Votre commande pour « {order.grouped_order.name} »" ) html_message = render_to_string( template_name, {"order": order, "base_url": settings.BASE_URL}