From dc070278f711bc9b82e7b465fecb522d4284b90b Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 15 Sep 2020 11:48:36 +0200 Subject: [PATCH] Gestioncof : tests --- gestioncof/tests/test_views.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/gestioncof/tests/test_views.py b/gestioncof/tests/test_views.py index ea51c509..dc9b8df0 100644 --- a/gestioncof/tests/test_views.py +++ b/gestioncof/tests/test_views.py @@ -1,15 +1,13 @@ -import os import uuid from datetime import timedelta -from custommail.models import CustomMail -from django.conf import settings from django.contrib import messages from django.contrib.auth import get_user_model from django.contrib.messages.api import get_messages from django.contrib.messages.storage.base import Message from django.core import mail -from django.core.management import call_command +from django.core.mail import EmailMessage +from django.template import loader from django.test import Client, TestCase, override_settings from django.urls import reverse @@ -33,12 +31,6 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase): auth_user = "staff" auth_forbidden = [None, "user", "member"] - def requires_mails(self): - data_file = os.path.join( - settings.BASE_DIR, "gestioncof", "management", "data", "custommail.json" - ) - call_command("syncmails", data_file, verbosity=0) - def test_get(self): r = self.client.get(self.url) self.assertEqual(r.status_code, 200) @@ -64,8 +56,6 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase): } def test_post_new(self): - self.requires_mails() - r = self.client.post( self.url, dict( @@ -97,7 +87,6 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(u.email, "username@mail.net") def test_post_edit(self): - self.requires_mails() u = self.users["user"] r = self.client.post( @@ -132,7 +121,6 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(u.email, "user@mail.net") def _test_mail_welcome(self, was_cof, is_cof, expect_mail): - self.requires_mails() u = self.users["member"] if was_cof else self.users["user"] data = dict( @@ -146,8 +134,12 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase): u.refresh_from_db() def _is_sent(): - cm = CustomMail.objects.get(shortname="welcome") - welcome_msg = cm.get_message({"member": u}) + welcome_msg = EmailMessage( + subject="Bienvenue au COF", + body=loader.render_to_string( + "gestioncof/mails/welcome.txt", context={"member": "u"} + ), + ) for m in mail.outbox: if m.subject == welcome_msg.subject: return True