Fix candidate tests
This commit is contained in:
parent
7574f74386
commit
6980298266
2 changed files with 6 additions and 7 deletions
|
|
@ -42,6 +42,7 @@ export_candidates.short_description = "Exporter les candidats sélectionnés"
|
|||
def send_confirmation_mail(modeladmin, request, queryset):
|
||||
from_email = request.user.email
|
||||
subject = "Confirmation de votre inscription à l'Ecole Santé-social Pierre-Coullery"
|
||||
email_sent = 0
|
||||
|
||||
for candidate in queryset.filter(
|
||||
deposite_date__isnull=False, date_confirmation_mail__isnull=True, canceled_file=False):
|
||||
|
|
@ -66,11 +67,13 @@ def send_confirmation_mail(modeladmin, request, queryset):
|
|||
body = loader.render_to_string('email/candidate_confirm_FE.txt', context)
|
||||
try:
|
||||
send_mail(subject, body, from_email, to, fail_silently=False)
|
||||
email_sent += 1
|
||||
except Exception as err:
|
||||
modeladmin.message_user(request, "Échec d’envoi pour le candidat {0} ({1})".format(candidate, err))
|
||||
else:
|
||||
candidate.date_confirmation_mail = date.today()
|
||||
candidate.save()
|
||||
modeladmin.message_user(request, "%d messages de confirmation ont été envoyés." % email_sent)
|
||||
|
||||
send_confirmation_mail.short_description = "Envoyer email de confirmation"
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,12 @@ class CandidateTests(TestCase):
|
|||
ede = Section.objects.create(name='EDE')
|
||||
ase = Section.objects.create(name='ASE')
|
||||
Candidate.objects.bulk_create([
|
||||
# A mail should NOT be sent for those first 4
|
||||
Candidate(
|
||||
first_name='Sara', last_name='Hitz', gender='F', section=ede,
|
||||
deposite_date=None),
|
||||
# A mail should NOT be sent for those first 2
|
||||
Candidate(
|
||||
first_name='Jill', last_name='Simth', gender='F', section=ede,
|
||||
date_confirmation_mail=date.today()),
|
||||
deposite_date=date.today(), date_confirmation_mail=date.today()),
|
||||
Candidate(first_name='Hervé', last_name='Bern', gender='M', section=ede,
|
||||
canceled_file=True),
|
||||
Candidate(first_name='Frank', last_name='Pit', gender='M', section=ede, email=''),
|
||||
deposite_date=date.today(), canceled_file=True),
|
||||
# Good
|
||||
Candidate(first_name='Joé', last_name='Glatz', gender='F', section=ase,
|
||||
email='joe@example.org', deposite_date=date.today()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue