Gestioncof : tests

This commit is contained in:
Ludovic Stephan 2020-09-15 11:48:36 +02:00
parent 561a121e04
commit dc070278f7

View file

@ -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