import pytest from django.urls import reverse from la_chariotte import settings from la_chariotte.order.models import GroupedOrder pytestmark = pytest.mark.django_db def test_send_order_confirmation_mail(mailoutbox, simple_grouped_order, client): """ When a user orders, they receive a confirmation email """ item = simple_grouped_order.item_set.first() # the user places an order order_url = reverse( "order:order", kwargs={ "grouped_order_id": simple_grouped_order.pk, }, ) response = client.post( order_url, { f"quantity_{item.pk}": [4, 0], "first_name": "Prénom", "last_name": "Nom", "phone": "0645632569", "email": "test@mail.fr", "note": "", }, ) assert len(mailoutbox) == 1 m = mailoutbox[0] assert m.subject == "[La Chariotte] Votre commande pour Test grouped order" assert "Votre participation à la commande groupée" in m.body assert "Votre participation à la commande groupée" in m.alternatives[0][0] assert f"{settings.BASE_URL}" in m.alternatives[0][0] assert m.alternatives[0][1] == "text/html" assert "test@mail.fr" in mailoutbox[0].to