2018-01-25 15:51:51 +01:00
from datetime import date , datetime
2017-12-06 12:23:12 +01:00
from unittest import mock
2017-11-24 08:39:10 +01:00
from django . contrib . auth . models import User
from django . core import mail
from django . test import TestCase
from django . urls import reverse
2018-06-16 18:40:34 +02:00
from stages . views . export import openxml_contenttype
2018-01-25 15:51:51 +01:00
from stages . models import Section , Teacher
from . models import Candidate , Interview
2017-11-24 08:39:10 +01:00
class CandidateTests ( TestCase ) :
@classmethod
def setUpTestData ( cls ) :
User . objects . create_superuser (
' me ' , ' me@example.org ' , ' mepassword ' , first_name = ' Hans ' , last_name = ' Schmid ' ,
)
2018-02-14 18:41:57 +01:00
def test_total_result ( self ) :
ede = Section . objects . create ( name = ' EDE ' )
cand = Candidate (
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ede ,
email = ' henri@example.org ' , deposite_date = date . today ( )
)
self . assertEqual ( cand . total_result , 0 )
cand . examination_result = 7
cand . interview_result = 4
cand . file_result = 5
self . assertEqual ( cand . total_result , 16 )
2018-01-25 15:51:51 +01:00
def test_interview ( self ) :
inter = Interview . objects . create ( date = datetime ( 2018 , 3 , 10 , 10 , 30 ) , room = ' B103 ' )
2018-02-14 18:41:57 +01:00
self . assertEqual ( str ( inter ) , ' samedi 10 mars 2018 à 10h30 : ? (Ent.) / ? (Dos.) - (N) -salle:B103-??? ' )
2018-01-25 15:51:51 +01:00
ede = Section . objects . create ( name = ' EDE ' )
cand = Candidate . objects . create (
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ede ,
email = ' henri@example.org ' , deposite_date = date . today ( )
)
t1 = Teacher . objects . create ( first_name = " Julie " , last_name = " Caux " , abrev = " JCA " )
2018-02-01 10:09:18 +01:00
t2 = Teacher . objects . create ( first_name = ' Jeanne ' , last_name = ' Dubois ' , abrev = " JDU " )
2018-01-25 15:51:51 +01:00
inter . teacher_int = t1
inter . teacher_file = t2
inter . candidat = cand
inter . save ( )
self . assertEqual (
str ( inter ) ,
2018-02-14 18:41:57 +01:00
' samedi 10 mars 2018 à 10h30 : JCA (Ent.) / JDU (Dos.) - (N) -salle:B103-Dupond Henri '
2018-01-25 15:51:51 +01:00
)
self . assertEqual ( cand . interview , inter )
2018-02-01 14:06:31 +01:00
def test_add_candidate ( self ) :
url = reverse ( ' admin:candidats_candidate_add ' )
post_data = dict ( { } ,
city = ' Peseux ' ,
section = ' EDE ' ,
certificate_of_payement = ' on ' ,
interview = ' ' ,
gender = ' F ' ,
aes_accords = ' 0 ' ,
mobile = ' 077 999 99 99 ' ,
registration_form = ' on ' ,
birth_date = ' 15.03.1997 ' ,
residence_permits = ' ' ,
corporation = ' ' ,
_save = ' Enregistrer ' ,
marks_certificate = ' on ' ,
avs = ' 75609994444567 ' ,
activity_rate = ' ' ,
last_name = ' G. ' ,
deposite_date = ' 31.01.2018 ' ,
police_record = ' on ' ,
examination_result = ' ' ,
diploma_detail = ' Maturité linguistique ' ,
handicap = ' on ' ,
work_certificate = ' on ' ,
comment = ' Le casier judiciaire a été envoyé par e-mail le 30.01.2018 ' ,
certif_of_800_general = ' on ' ,
instructor = ' ' ,
validation_sfpo = ' ' ,
email = ' caterina.g@example.org ' ,
file_result = ' ' ,
cv = ' on ' ,
diploma_status = ' 2 ' ,
pcode = ' 2034 ' ,
first_name = ' Caterina ' ,
reflexive_text = ' on ' ,
diploma = ' 4 ' ,
has_photo = ' on ' ,
certif_of_800_childhood = ' on ' ,
district = ' Ne ' ,
option = ' PS ' ,
interview_result = ' ' ,
street = ' de Neuchâtel 99 ' ,
)
self . client . login ( username = ' me ' , password = ' mepassword ' )
2018-06-06 18:51:16 +02:00
response = self . client . get ( url )
self . assertEqual ( response . status_code , 200 )
2018-02-01 14:06:31 +01:00
response = self . client . post ( url , post_data )
self . assertEqual ( response . status_code , 302 )
2017-11-24 08:39:10 +01:00
def test_send_confirmation_mail ( self ) :
2018-02-02 09:55:09 +01:00
self . maxDiff = None
2017-12-05 15:51:28 +01:00
ede = Section . objects . create ( name = ' EDE ' )
ase = Section . objects . create ( name = ' ASE ' )
2018-06-08 13:50:09 +02:00
eds = Section . objects . create ( name = ' EDS ' )
2017-11-24 08:39:10 +01:00
Candidate . objects . bulk_create ( [
2018-01-12 15:15:15 +01:00
# A mail should NOT be sent for those first 2
2017-11-24 08:39:10 +01:00
Candidate (
2017-12-05 15:51:28 +01:00
first_name = ' Jill ' , last_name = ' Simth ' , gender = ' F ' , section = ede ,
2018-02-02 09:36:05 +01:00
deposite_date = date . today ( ) , confirmation_date = date . today ( ) ) ,
2017-12-05 15:51:28 +01:00
Candidate ( first_name = ' Hervé ' , last_name = ' Bern ' , gender = ' M ' , section = ede ,
2018-01-12 15:15:15 +01:00
deposite_date = date . today ( ) , canceled_file = True ) ,
2017-11-24 08:39:10 +01:00
# Good
2018-02-02 09:55:09 +01:00
Candidate ( first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ede , option = ' ENF ' ,
email = ' henri@example.org ' , deposite_date = date . today ( ) ) ,
2017-12-05 15:51:28 +01:00
Candidate ( first_name = ' Joé ' , last_name = ' Glatz ' , gender = ' F ' , section = ase ,
2017-11-24 08:39:10 +01:00
email = ' joe@example.org ' , deposite_date = date . today ( ) ) ,
2018-06-08 13:50:09 +02:00
Candidate ( first_name = ' John ' , last_name = ' Durand ' , gender = ' M ' , section = eds ,
email = ' john@example.org ' , deposite_date = date . today ( ) ) ,
2017-11-24 08:39:10 +01:00
] )
self . client . login ( username = ' me ' , password = ' mepassword ' )
2018-02-02 09:55:09 +01:00
cand1 = Candidate . objects . get ( last_name = ' Simth ' )
response = self . client . get ( reverse ( ' candidate-confirmation ' , args = [ cand1 . pk ] ) , follow = True )
msg = " \n " . join ( str ( m ) for m in response . context [ ' messages ' ] )
self . assertEqual ( msg , " Une confirmation a déjà été envoyée! " )
cand2 = Candidate . objects . get ( last_name = ' Bern ' )
response = self . client . get ( reverse ( ' candidate-confirmation ' , args = [ cand2 . pk ] ) , follow = True )
msg = " \n " . join ( str ( m ) for m in response . context [ ' messages ' ] )
self . assertEqual ( msg , " Ce dossier a été annulé! " )
cand3 = Candidate . objects . get ( last_name = ' Dupond ' )
response = self . client . get ( reverse ( ' candidate-confirmation ' , args = [ cand3 . pk ] ) )
data = response . context [ ' form ' ] . initial
response = self . client . post (
reverse ( ' candidate-confirmation ' , args = [ cand3 . pk ] ) , data = data , follow = True
)
self . assertEqual ( len ( mail . outbox ) , 1 )
2018-01-24 11:06:22 +01:00
# Logged-in user also receives as Bcc
self . assertEqual ( mail . outbox [ 0 ] . recipients ( ) , [ ' henri@example.org ' , ' me@example.org ' ] )
2017-12-05 15:51:28 +01:00
# Mail content differ depending on the section
2018-02-02 09:55:09 +01:00
self . assertEqual ( mail . outbox [ 0 ] . body , """ Monsieur Henri Dupond,
2017-11-24 08:39:10 +01:00
2018-02-02 09:55:09 +01:00
Par ce courriel , nous vous confirmons la bonne réception de vos documents de candidature à la formation Education de l & #39;enfance, dipl. ES, option «Enfance» et vous remercions de l’ intérêt que vous portez à notre institution.
2017-12-05 15:51:28 +01:00
2018-02-02 09:55:09 +01:00
Votre dossier sera traité dans les jours à venir et des nouvelles vous seront communiquées par courriel durant la 2 ème quinzaine du mois de février .
2017-12-05 15:51:28 +01:00
Dans l ’ intervalle , nous vous adressons , Monsieur , nos salutations les plus cordiales .
2018-02-02 09:55:09 +01:00
Secrétariat de la filière Education de l ’ enfance , dipl . ES
2017-12-05 15:51:28 +01:00
Hans Schmid
me @example.org
2018-02-02 09:55:09 +01:00
tél . 032 886 33 00 """
2017-12-05 15:51:28 +01:00
)
2018-02-02 09:55:09 +01:00
mail . outbox = [ ]
cand4 = Candidate . objects . get ( last_name = ' Glatz ' )
response = self . client . get ( reverse ( ' candidate-confirmation ' , args = [ cand4 . pk ] ) )
data = response . context [ ' form ' ] . initial
response = self . client . post (
reverse ( ' candidate-confirmation ' , args = [ cand4 . pk ] ) , data = data , follow = True
)
self . assertEqual ( len ( mail . outbox ) , 1 )
# Logged-in user also receives as Bcc
self . assertEqual ( mail . outbox [ 0 ] . recipients ( ) , [ ' joe@example.org ' , ' me@example.org ' ] )
self . assertEqual ( mail . outbox [ 0 ] . body , """ Madame, Monsieur,
2017-11-24 08:39:10 +01:00
2018-02-15 12:13:04 +01:00
Nous vous confirmons la bonne réception de l ’ inscription de Madame Joé Glatz dans la filière Assist . socio - éducatif - ve CFC pour la prochaine rentrée scolaire .
Le nom de la classe ainsi que les jours de cours vous seront communiqués dès que toutes les inscriptions seront rentrées , mais au plus tard durant la 1 ère semaine de juillet .
2017-11-24 08:39:10 +01:00
2018-11-15 15:31:58 +01:00
Nous attirons votre attention sur le fait que l ' accès aux cours est autorisé sous réserve de l ' approbation du contrat par l ' autorité cantonale qui en est détentrice.
2018-02-02 09:55:09 +01:00
Nous nous tenons à votre disposition pour tout renseignement complémentaire et vous prions de recevoir , Madame , Monsieur , nos salutations les plus cordiales .
2017-11-24 08:39:10 +01:00
2018-02-02 09:55:09 +01:00
Secrétariat de l ’ EPC
2017-11-24 08:39:10 +01:00
Hans Schmid
me @example.org
2018-02-02 09:55:09 +01:00
tél . 032 886 33 00 """
2017-11-24 08:39:10 +01:00
)
2017-11-24 08:57:38 +01:00
# One was already set, 2 new.
2018-02-02 09:36:05 +01:00
self . assertEqual ( Candidate . objects . filter ( confirmation_date__isnull = False ) . count ( ) , 3 )
2017-12-06 12:23:12 +01:00
2018-06-08 13:50:09 +02:00
mail . outbox = [ ]
cand5 = Candidate . objects . get ( last_name = ' Durand ' )
response = self . client . get ( reverse ( ' candidate-confirmation ' , args = [ cand5 . pk ] ) )
data = response . context [ ' form ' ] . initial
response = self . client . post (
reverse ( ' candidate-confirmation ' , args = [ cand5 . pk ] ) , data = data , follow = True
)
self . assertEqual ( len ( mail . outbox ) , 1 )
# Logged-in user also receives as Bcc
self . assertEqual ( mail . outbox [ 0 ] . recipients ( ) , [ ' john@example.org ' , ' me@example.org ' ] )
self . assertEqual ( mail . outbox [ 0 ] . body , """ Monsieur John Durand,
Par ce courriel , nous vous confirmons la bonne réception de vos documents de candidature à la formation Education sociale , dipl . ES et vous remercions de l ’ intérêt que vous portez à notre institution .
Votre dossier sera traité début octobre 2018 et des nouvelles vous seront communiquées par courriel .
Dans l ’ intervalle , nous vous adressons , Monsieur , nos salutations les plus cordiales .
Secrétariat de la filière Education sociale , dipl . ES
Hans Schmid
me @example.org
tél . 032 886 33 00 """
)
# One was already set, 2 new.
self . assertEqual ( Candidate . objects . filter ( confirmation_date__isnull = False ) . count ( ) , 4 )
2017-12-06 12:23:12 +01:00
def test_send_confirmation_error ( self ) :
ede = Section . objects . create ( name = ' EDE ' )
2018-01-24 11:06:22 +01:00
henri = Candidate . objects . create (
2017-12-06 12:23:12 +01:00
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ede ,
email = ' henri@example.org ' , deposite_date = date . today ( )
)
self . client . login ( username = ' me ' , password = ' mepassword ' )
2018-02-02 09:55:09 +01:00
response = self . client . get ( reverse ( ' candidate-confirmation ' , args = [ henri . pk ] ) )
data = response . context [ ' form ' ] . initial
2018-01-24 11:06:22 +01:00
with mock . patch ( ' django.core.mail.EmailMessage.send ' ) as mocked :
2017-12-06 12:23:12 +01:00
mocked . side_effect = Exception ( " Error sending mail " )
2018-02-02 09:55:09 +01:00
response = self . client . post (
reverse ( ' candidate-confirmation ' , args = [ henri . pk ] ) , data = data , follow = True
)
2017-12-06 12:23:12 +01:00
self . assertContains ( response , " Échec d’ envoi pour le candidat Dupond Henri (Error sending mail) " )
2018-01-24 11:06:22 +01:00
henri . refresh_from_db ( )
2018-02-02 09:36:05 +01:00
self . assertIsNone ( henri . confirmation_date )
2018-01-26 18:19:16 +01:00
def test_convocation_ede ( self ) :
henri = Candidate . objects . create (
2018-02-15 08:56:45 +01:00
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ' EDE ' , option = ' ENF ' ,
2018-01-26 18:19:16 +01:00
email = ' henri@example.org ' , deposite_date = date . today ( )
)
inter = Interview . objects . create ( date = datetime ( 2018 , 3 , 10 , 10 , 30 ) , room = ' B103 ' , candidat = henri )
self . client . login ( username = ' me ' , password = ' mepassword ' )
response = self . client . get ( reverse ( ' candidate-convocation ' , args = [ henri . pk ] ) )
self . assertContains ( response , ' <h2>Dupond Henri</h2> ' )
self . assertContains ( response , ' <input type= " text " name= " to " value= " henri@example.org " size= " 60 " id= " id_to " required> ' , html = True )
2018-02-01 10:47:25 +01:00
expected_message = """ Monsieur Henri Dupond,
2018-01-26 18:19:16 +01:00
2018-02-19 11:22:32 +01:00
Nous vous adressons par la présente votre convocation personnelle à la procédure d ’ admission de la filière Education de l ’ enfance , dipl . ES .
2018-01-26 18:19:16 +01:00
2018-02-14 17:44:30 +01:00
Vous êtes attendu à l ’ Ecole Santé - social Pierre - Coullery , rue de la Prévoyance 82 , 2300 La Chaux - de - Fonds aux dates suivantes :
2018-01-26 18:19:16 +01:00
2018-02-19 11:22:32 +01:00
- mercredi 7 mars 2018 , à 13 h30 , salle A405 , pour l ’ examen écrit ( analyse de texte d ’ une durée de 2 h30 env . ) ;
2018-01-26 18:19:16 +01:00
2018-02-14 17:44:30 +01:00
- samedi 10 mars 2018 à 10 h30 , en salle B103 , pour l ’ entretien d ’ admission ( durée 20 min . ) .
2018-01-26 18:19:16 +01:00
En cas d ’ empêchement de dernière minute , nous vous remercions d ’ annoncer votre absence au secrétariat ( Tél . 032 886 33 00 ) .
2018-02-14 17:44:30 +01:00
Si vous rencontrez des difficultés d ’ apprentissage ( dyslexie , dysorthographie , etc . ) , nous vous rappelons que vous pouvez bénéficier d ’ un temps supplémentaire d ’ une heure au maximum pour l ’ examen d ’ admission . Si vous n ’ avez pas déjà joint à votre dossier de candidature un document officiel ( rapport d ’ orthophonie par exemple ) , vous devez impérativement nous le faire parvenir au moins 5 jours ouvrables avant la date du premier examen .
2018-01-26 18:19:16 +01:00
2018-02-01 10:47:25 +01:00
De plus , afin que nous puissions enregistrer définitivement votre inscription , nous vous remercions par avance de nous faire parvenir , dans les meilleurs délais , le ou les documents suivants :
- Formulaire d & #39;inscription, Attest. de paiement, Casier judic., CV, Texte réflexif, Photo passeport, Bull. de notes
Tous les documents nécessaires à compléter votre dossier se trouvent sur notre site internet à l ’ adresse https : / / www . cifom . ch / index . php / ecoles / epc / formations - epc / educateur - de - l - enfance - epc .
2018-02-14 17:44:30 +01:00
Sans nouvelles de votre part 5 jours ouvrables avant la date du premier examen , votre dossier ne sera pas pris en considération et vous ne pourrez pas vous présenter à l ’ examen d ’ admission .
2018-02-01 10:47:25 +01:00
2018-02-14 17:44:30 +01:00
Nous vous remercions de nous confirmer par retour de courriel que vous avez bien reçu ce message et dans l ’ attente du plaisir de vous rencontrer prochainement , nous vous prions d ’ agréer , Monsieur , nos salutations les meilleures .
2018-01-26 18:19:16 +01:00
Secrétariat de la filière Education de l ’ enfance , dipl . ES
Hans Schmid
me @example.org
2018-02-01 10:47:25 +01:00
tél . 032 886 33 00
"""
self . assertEqual ( response . context [ ' form ' ] . initial [ ' message ' ] , expected_message )
2018-02-15 08:56:45 +01:00
# Add missing documents and resend message
for field_name in [
' registration_form ' , ' certificate_of_payement ' , ' police_record ' , ' cv ' , ' reflexive_text ' ,
' has_photo ' , ' marks_certificate ' ] :
setattr ( henri , field_name , True )
henri . save ( )
response = self . client . get ( reverse ( ' candidate-convocation ' , args = [ henri . pk ] ) )
self . assertEqual ( response . context [ ' form ' ] . initial [ ' message ' ] , expected_message . replace (
"""
De plus , afin que nous puissions enregistrer définitivement votre inscription , nous vous remercions par avance de nous faire parvenir , dans les meilleurs délais , le ou les documents suivants :
- Formulaire d & #39;inscription, Attest. de paiement, Casier judic., CV, Texte réflexif, Photo passeport, Bull. de notes
Tous les documents nécessaires à compléter votre dossier se trouvent sur notre site internet à l ’ adresse https : / / www . cifom . ch / index . php / ecoles / epc / formations - epc / educateur - de - l - enfance - epc .
Sans nouvelles de votre part 5 jours ouvrables avant la date du premier examen , votre dossier ne sera pas pris en considération et vous ne pourrez pas vous présenter à l ’ examen d ’ admission . """ , " " )
)
# Now send the message
2018-01-26 18:19:16 +01:00
response = self . client . post ( reverse ( ' candidate-convocation ' , args = [ henri . pk ] ) , data = {
' cci ' : ' me@example.org ' ,
' to ' : henri . email ,
' subject ' : " Procédure de qualification " ,
' message ' : " Monsieur Henri Dupond, ... " ,
' sender ' : ' me@example.org ' ,
} )
self . assertRedirects ( response , reverse ( ' admin:candidats_candidate_changelist ' ) )
self . assertEqual ( len ( mail . outbox ) , 1 )
self . assertEqual ( mail . outbox [ 0 ] . recipients ( ) , [ ' henri@example.org ' , ' me@example.org ' ] )
self . assertEqual ( mail . outbox [ 0 ] . subject , " Procédure de qualification " )
henri . refresh_from_db ( )
self . assertIsNotNone ( henri . convocation_date )
2018-01-26 19:15:10 +01:00
2018-02-02 09:55:09 +01:00
def test_validation_enseignant_ede ( self ) :
self . maxDiff = None
henri = Candidate . objects . create (
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , birth_date = date ( 2000 , 5 , 15 ) ,
street = " Rue Neuve 3 " , pcode = ' 2222 ' , city = ' Petaouchnok ' ,
2018-02-15 15:53:12 +01:00
section = ' EDE ' , option = ' ENF ' ,
2018-02-02 09:55:09 +01:00
email = ' henri@example.org ' , deposite_date = date . today ( )
)
t1 = Teacher . objects . create (
first_name = " Julie " , last_name = " Caux " , abrev = " JCA " , email = " julie@example.org "
)
t2 = Teacher . objects . create (
first_name = ' Jeanne ' , last_name = ' Dubois ' , abrev = " JDU " , email = " jeanne@example.org "
)
2018-02-15 15:53:12 +01:00
self . client . login ( username = ' me ' , password = ' mepassword ' )
response = self . client . get ( reverse ( ' candidate-validation ' , args = [ henri . pk ] ) , follow = True )
self . assertContains ( response , " Aucun interview attribué à ce candidat pour l’ instant " )
2018-02-02 09:55:09 +01:00
inter = Interview . objects . create (
date = datetime ( 2018 , 3 , 10 , 10 , 30 ) , room = ' B103 ' , candidat = henri ,
teacher_int = t1 , teacher_file = t2 ,
)
response = self . client . get ( reverse ( ' candidate-validation ' , args = [ henri . pk ] ) )
expected_message = """ Bonjour,
Par ce courriel , je vous informe qu ' un entretien d ' admission a été planifié selon les modalités suivantes :
- samedi 10 mars 2018 à 10 h30 , en salle B103
Candidat :
Monsieur Henri Dupond
Rue Neuve 3
2222 Petaouchnok
Date de naiss . : 15 mai 2000
Sans nouvelle de votre part dans les 48 heures , une convocation définitive sera envoyée au candidat .
Avec mes meilleurs messages .
Secrétariat de la filière Education de l ’ enfance , dipl . ES
Hans Schmid
me @example.org
tél . 032 886 33 00
"""
self . assertEqual ( response . context [ ' form ' ] . initial [ ' message ' ] , expected_message )
data = response . context [ ' form ' ] . initial
response = self . client . post ( reverse ( ' candidate-validation ' , args = [ henri . pk ] ) , data = data )
self . assertEqual ( len ( mail . outbox ) , 1 )
self . assertEqual ( mail . outbox [ 0 ] . recipients ( ) , [ " julie@example.org " , " jeanne@example.org " , ' me@example.org ' ] )
self . assertEqual ( mail . outbox [ 0 ] . subject , " Validation de l ' entretien d ' admission " )
henri . refresh_from_db ( )
self . assertIsNotNone ( henri . validation_date )
2018-01-26 19:15:10 +01:00
def test_summary_pdf ( self ) :
ede = Section . objects . create ( name = ' EDE ' )
cand = Candidate . objects . create (
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ede ,
email = ' henri@example.org ' , deposite_date = date . today ( )
)
2018-02-02 09:55:09 +01:00
summary_url = reverse ( ' candidate-summary ' , args = [ cand . pk ] )
2018-01-26 19:15:10 +01:00
self . client . login ( username = ' me ' , password = ' mepassword ' )
2018-02-02 09:55:09 +01:00
response = self . client . post ( summary_url , follow = True )
2018-01-26 19:15:10 +01:00
self . assertEqual (
response [ ' Content-Disposition ' ] ,
2018-02-02 09:55:09 +01:00
' attachment; filename= " dupond_henri.pdf " '
2018-01-26 19:15:10 +01:00
)
2018-02-02 09:55:09 +01:00
self . assertEqual ( response [ ' Content-Type ' ] , ' application/pdf ' )
2020-01-08 11:23:52 +01:00
self . assertGreater ( int ( response [ ' Content-Length ' ] ) , 1000 )
2018-02-14 19:08:03 +01:00
def test_export_candidates ( self ) :
ede = Section . objects . create ( name = ' EDE ' )
Candidate . objects . create (
first_name = ' Henri ' , last_name = ' Dupond ' , gender = ' M ' , section = ede ,
email = ' henri@example.org ' , deposite_date = date . today ( )
)
Candidate . objects . create (
first_name = ' Joé ' , last_name = ' Glatz ' , gender = ' F ' , section = ede ,
email = ' joe@example.org ' , deposite_date = date . today ( )
)
change_url = reverse ( ' admin:candidats_candidate_changelist ' )
self . client . login ( username = ' me ' , password = ' mepassword ' )
response = self . client . post ( change_url , {
' action ' : ' export_candidates ' ,
' _selected_action ' : Candidate . objects . values_list ( ' pk ' , flat = True )
} , follow = True )
self . assertEqual ( response [ ' Content-Type ' ] , openxml_contenttype )