1 # -*- coding: utf-8 -*-
4 from django
.contrib
.auth
.models
import User
, Group
5 from project
import groups
6 from auf
.django
.references
import models
as ref
7 from django
.test
import TestCase
8 from project
.rh
import models
as rh
10 class RhTest(TestCase
):
16 self.grp_correspondants_rh
17 self.grp_administrateurs
18 self.grp_directeurs_bureau
23 self.grp_haute_direction
24 self.grp_service_utilisateurs
28 self.poste_cnf_ngaoundere
35 0@test.auf: self.employe_cnf_ngaoundere
36 1@test.auf: self.employe_cnf_bangui
37 2@test.auf: self.employe_bap_bureau
38 3@test.auf: self.employe_bap_ifi
46 self.dossier_cnf_ngaoundere
47 self.dossier_cnf_bangui
48 self.dossier_bap_bureau
53 self
.grp_correspondants_rh
= Group(name
=groups
.CORRESPONDANT_RH
)
54 self
.grp_correspondants_rh
.save()
56 self
.grp_administrateurs
= Group(name
=groups
.ADMINISTRATEURS
)
57 self
.grp_administrateurs
.save()
59 self
.grp_directeurs_bureau
= Group(name
=groups
.DIRECTEUR_DE_BUREAU
)
60 self
.grp_directeurs_bureau
.save()
62 self
.grp_drh
= Group(name
=groups
.DRH_NIVEAU_1
)
65 self
.grp_drh2
= Group(name
=groups
.DRH_NIVEAU_2
)
68 self
.grp_accior
= Group(name
=groups
.ACCIOR
)
69 self
.grp_accior
.save()
71 self
.grp_abf
= Group(name
=groups
.ABF
)
74 self
.grp_haute_direction
= Group(name
=groups
.HAUTE_DIRECTION
)
75 self
.grp_haute_direction
.save()
77 self
.grp_service_utilisateurs
= Group(name
=groups
.SERVICE_UTILISATEURS
)
78 self
.grp_service_utilisateurs
.save()
80 self
.password
= "0000"
81 self
.today
= datetime
.datetime
.now()
82 #########################
83 # Régions / Implantations
84 #########################
85 self
.REGION_ACGL
= ref
.Region
.objects
.get(id=1)
86 self
.IMPLANTATION_ACGL_CNF_NGAOUNDERE
= ref
.Implantation
.objects
.get(id=90)
87 self
.IMPLANTATION_ACGL_CNF_BANGUI
= ref
.Implantation
.objects
.get(id=85)
89 self
.REGION_BAP
= ref
.Region
.objects
.get(id=4)
90 self
.IMPLANTATION_BAP_BUREAU
= ref
.Implantation
.objects
.get(id=51)
91 self
.IMPLANTATION_BAP_IFI
= ref
.Implantation
.objects
.get(id=55)
97 self
.employe_cnf_ngaoundere
= rh
.Employe(
102 self
.employe_cnf_ngaoundere
.save()
103 self
.employe_cnf_bangui
= rh
.Employe(
108 self
.employe_cnf_bangui
.save()
109 self
.employe_bap_bureau
= rh
.Employe(
114 self
.employe_bap_bureau
.save()
115 self
.employe_bap_ifi
= rh
.Employe(
120 self
.employe_bap_ifi
.save()
125 self
.poste_cnf_ngaoundere
= rh
.Poste(nom
="poste à NGAOUNDERE",
126 implantation
=self
.IMPLANTATION_ACGL_CNF_NGAOUNDERE
)
128 self
.poste_cnf_bangui
= rh
.Poste(nom
="poste à BANGUI",
129 implantation
=self
.IMPLANTATION_ACGL_CNF_BANGUI
)
131 self
.poste_cnf_ngaoundere
.save()
132 self
.poste_cnf_bangui
.save()
134 self
.dossier_cnf_ngaoundere
= rh
.Dossier(poste
=self
.poste_cnf_ngaoundere
,
135 employe
=self
.employe_cnf_ngaoundere
, date_debut
=self
.today
)
136 self
.dossier_cnf_bangui
= rh
.Dossier(poste
=self
.poste_cnf_bangui
,
137 employe
=self
.employe_cnf_bangui
, date_debut
=self
.today
)
139 self
.dossier_cnf_ngaoundere
.save()
140 self
.dossier_cnf_bangui
.save()
145 self
.poste_bap_bureau
= rh
.Poste(nom
="poste au Bureau BAP",
146 implantation
=self
.IMPLANTATION_BAP_BUREAU
)
147 self
.poste_bap_ifi
= rh
.Poste(nom
="poste à l'IFI",
148 implantation
=self
.IMPLANTATION_BAP_IFI
)
150 self
.poste_bap_bureau
.save()
151 self
.poste_bap_ifi
.save()
153 self
.dossier_bap_bureau
= rh
.Dossier(poste
=self
.poste_bap_bureau
,
154 employe
=self
.employe_bap_bureau
, date_debut
=self
.today
)
155 self
.dossier_bap_ifi
= rh
.Dossier(poste
=self
.poste_bap_ifi
,
156 employe
=self
.employe_bap_ifi
, date_debut
=self
.today
)
158 self
.dossier_bap_bureau
.save()
159 self
.dossier_bap_ifi
.save()
165 for idx
, e
in enumerate(rh
.Employe
.objects
.all().order_by('id')):
166 email
= u
"%s@test.auf" % idx
167 u
= User(first_name
=e
.prenom
,
172 u
.set_password(self
.password
)
175 # on le porte dans le référentiel employé
176 ref_e
= ref
.Employe(id=u
.id,
177 nom
=e
.nom
, prenom
=e
.prenom
,
178 implantation
=e
.poste_principal().implantation
,
179 implantation_physique
=e
.poste_principal().implantation
,
180 service
=ref
.Service
.objects
.get(id=1))
183 # on le porte dans le référentiel auth
184 ref
.Authentification(id=ref_e
, courriel
=u
.email
).save()
186 def _clean_refs(self
):
187 courriels
= [u
"%s@test.auf" % idx
for idx
, e
in
188 enumerate(rh
.Employe
.objects
.all())]
189 ref
.Employe
.objects
.filter(courriel__in
=courriels
).delete()
190 ref
.Authentification
.objects
.filter(courriel__in
=courriels
).delete()
195 def _test_acces_ok(self
, url
):
196 response
= self
.client
.get(url
, follow
=True)
197 self
.assertEqual(response
.status_code
, 200)
198 self
.assertEqual('next' in response
.context
, False)
200 def _test_acces_ko(self
, url
):
201 response
= self
.client
.get(url
, follow
=True)
202 is_ko
= response
.status_code
== 403 or 'next' in response
.context
203 self
.assertEqual(is_ko
, True)
205 def _test_anonyme(self
):
208 def _test_correspondant_rh(self
, email
="0@test.auf"):
209 u
= User
.objects
.get(email
=email
)
210 self
.grp_correspondants_rh
.user_set
.add(u
)
211 self
.grp_correspondants_rh
.save()
213 credentials
= {'username': email
, 'password': self
.password
}
214 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
216 def _test_administrateur_regional(self
, email
="0@test.auf"):
217 u
= User
.objects
.get(email
=email
)
218 self
.grp_administrateurs
.user_set
.add(u
)
219 self
.grp_administrateurs
.save()
221 credentials
= {'username': email
, 'password': self
.password
}
222 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
224 def _test_directeur_bureau(self
, email
="0@test.auf"):
225 u
= User
.objects
.get(email
=email
)
226 self
.grp_directeurs_bureau
.user_set
.add(u
)
227 self
.grp_directeurs_bureau
.save()
229 credentials
= {'username': email
, 'password': self
.password
}
230 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
235 u
= User
.objects
.get(email
=email
)
236 self
.grp_drh
.user_set
.add(u
)
239 credentials
= {'username': email
, 'password': self
.password
}
240 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
242 def _test_drh2(self
):
245 u
= User
.objects
.get(email
=email
)
246 self
.grp_drh2
.user_set
.add(u
)
249 credentials
= {'username': email
, 'password': self
.password
}
250 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
252 def _test_grp_accior(self
):
255 u
= User
.objects
.get(email
=email
)
256 self
.grp_accior
.user_set
.add(u
)
257 self
.grp_accior
.save()
259 credentials
= {'username': email
, 'password': self
.password
}
260 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
262 def _test_grp_abf(self
):
265 u
= User
.objects
.get(email
=email
)
266 self
.grp_abf
.user_set
.add(u
)
269 credentials
= {'username': email
, 'password': self
.password
}
270 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
272 def _test_grp_haute_direction(self
):
275 u
= User
.objects
.get(email
=email
)
276 self
.grp_haute_direction
.user_set
.add(u
)
277 self
.grp_haute_direction
.save()
279 credentials
= {'username': email
, 'password': self
.password
}
280 self
.assertTrue(self
.client
.login(**credentials
), "login failed")
282 def _test_grp_service_utilisateurs(self
):
285 u
= User
.objects
.get(email
=email
)
286 self
.grp_service_utilisateurs
.user_set
.add(u
)
287 self
.grp_service_utilisateurs
.save()
289 credentials
= {'username': email
, 'password': self
.password
}
290 self
.assertTrue(self
.client
.login(**credentials
), "login failed")