tests
[auf_rh_dae.git] / project / rh / test / common.py
CommitLineData
493f7aab
OL
1# -*- coding: utf-8 -*-
2
3import datetime
3383b2d1 4from django.contrib.auth.models import User, Group
c3550a05 5from project import groups
493f7aab
OL
6from auf.django.references import models as ref
7from django.test import TestCase
8from project.rh import models as rh
9
493f7aab
OL
10class RhTest(TestCase):
11
12 def setUp(self):
13 """
5ac79652
OL
14 DEVISES
15 =======
16 self.devise_cad
17
18 CLASSEMENTS
19 ===========
20 self.classement_p_5_0
21 self.classement_p_5_10
22
23 VALEUR POINTS
24 =============
25 self.vp_cad_scm_2012
26
27 SERVICES
28 ========
29 self.srv_info
30
31 CATEGORIE EMPLOI
32 ================
33 self.cat_emploi_pro
34
35 FAMILLE PROFESSIONNELLE
36 =======================
37 self.famille_cadre
38
39 TYPE POSTES
40 ===========
41 self.type_poste_tech
42
3383b2d1
OL
43 GROUPES
44 =======
45 self.grp_correspondants_rh
46 self.grp_administrateurs
47 self.grp_directeurs_bureau
48 self.grp_drh
49 self.grp_drh2
50 self.grp_accior
51 self.grp_abf
52 self.grp_haute_direction
53 self.grp_service_utilisateurs
54
493f7aab
OL
55 POSTES
56 ======
57 self.poste_cnf_ngaoundere
58 self.poste_cnf_bangui
59 self.poste_bap_bureau
60 self.poste_bap_ifi
61
62 EMPLOYES
63 ========
bcc0c52d
OL
64 0@test.auf: self.employe_cnf_ngaoundere
65 1@test.auf: self.employe_cnf_bangui
66 2@test.auf: self.employe_bap_bureau
67 3@test.auf: self.employe_bap_ifi
493f7aab
OL
68
69 USERS DJANGO
70 ============
71 cf. EMPLOYES
72
73 DOSSIERS
74 ========
75 self.dossier_cnf_ngaoundere
76 self.dossier_cnf_bangui
77 self.dossier_bap_bureau
78 self.dossier_bap_ifi
79
80
81 """
5ac79652
OL
82 #########
83 # DEVISES
84 #########
85 self.devise_cad = rh.Devise(code="CAD", nom="CAD")
86 self.devise_cad.save()
87
88 #############
89 # CLASSEMENTS
90 #############
91 self.classement_p_5_0 = rh.Classement(type="P", echelon=5, degre=1, coefficient=5.01)
92 self.classement_p_5_0.save()
93
94 self.classement_p_5_10 = rh.Classement(type="P", echelon=5, degre=10, coefficient=5.10)
95 self.classement_p_5_10.save()
96
97 ##########
98 # SERVICES
99 ##########
100 self.srv_info = rh.Service(nom="info")
101 self.srv_info.save()
102
103 ###################
104 # CATEGORIES EMPLOI
105 ###################
106 self.cat_emploi_pro = rh.CategorieEmploi(nom="pro")
107 self.cat_emploi_pro.save()
108
109 #################
110 # FAMILLES EMPLOI
111 #################
112 self.famille_cadre = rh.FamilleProfessionnelle(nom="cadre")
113 self.famille_cadre.save()
114
115 #############
116 # TYPES POSTE
117 #############
118 self.type_poste_tech = rh.TypePoste(nom="tech",
119 categorie_emploi=self.cat_emploi_pro,
120 famille_professionnelle=self.famille_cadre)
121 self.type_poste_tech.save()
122
123 #########
124 # GROUPES
125 #########
3383b2d1
OL
126 self.grp_correspondants_rh = Group(name=groups.CORRESPONDANT_RH)
127 self.grp_correspondants_rh.save()
128
129 self.grp_administrateurs = Group(name=groups.ADMINISTRATEURS)
130 self.grp_administrateurs.save()
131
132 self.grp_directeurs_bureau = Group(name=groups.DIRECTEUR_DE_BUREAU)
133 self.grp_directeurs_bureau.save()
134
135 self.grp_drh = Group(name=groups.DRH_NIVEAU_1)
136 self.grp_drh.save()
137
138 self.grp_drh2 = Group(name=groups.DRH_NIVEAU_2)
139 self.grp_drh2.save()
140
141 self.grp_accior = Group(name=groups.ACCIOR)
142 self.grp_accior.save()
143
144 self.grp_abf = Group(name=groups.ABF)
145 self.grp_abf.save()
146
147 self.grp_haute_direction = Group(name=groups.HAUTE_DIRECTION)
148 self.grp_haute_direction.save()
149
150 self.grp_service_utilisateurs = Group(name=groups.SERVICE_UTILISATEURS)
151 self.grp_service_utilisateurs.save()
152
493f7aab 153 self.password = "0000"
f96ec25c 154 self.today = datetime.datetime.now()
07039f95
OL
155 self.tomorrow = self.today + datetime.timedelta(days=1)
156
493f7aab
OL
157 #########################
158 # Régions / Implantations
159 #########################
160 self.REGION_ACGL = ref.Region.objects.get(id=1)
161 self.IMPLANTATION_ACGL_CNF_NGAOUNDERE = ref.Implantation.objects.get(id=90)
162 self.IMPLANTATION_ACGL_CNF_BANGUI = ref.Implantation.objects.get(id=85)
163
164 self.REGION_BAP = ref.Region.objects.get(id=4)
165 self.IMPLANTATION_BAP_BUREAU = ref.Implantation.objects.get(id=51)
166 self.IMPLANTATION_BAP_IFI = ref.Implantation.objects.get(id=55)
167
5ac79652
OL
168 #############
169 #VALEUR POINT
170 #############
171 self.vp_cad_ngaoundere_2012 = rh.ValeurPoint(valeur=1000.1,
172 devise=self.devise_cad,
173 implantation=self.IMPLANTATION_ACGL_CNF_NGAOUNDERE,
174 annee=2012)
175 self.vp_cad_ngaoundere_2012.save()
176
177
493f7aab
OL
178
179 ##########
180 # Employés
181 ##########
182 self.employe_cnf_ngaoundere = rh.Employe(
bcc0c52d 183 id=1,
493f7aab
OL
184 nom="Employé",
185 prenom="ngaoundere",
186 )
187 self.employe_cnf_ngaoundere.save()
188 self.employe_cnf_bangui = rh.Employe(
bcc0c52d 189 id=2,
493f7aab
OL
190 nom="Employé",
191 prenom="bangui",
192 )
193 self.employe_cnf_bangui.save()
194 self.employe_bap_bureau = rh.Employe(
bcc0c52d 195 id=3,
493f7aab
OL
196 nom="Employé",
197 prenom="BAP bureau",
198 )
199 self.employe_bap_bureau.save()
200 self.employe_bap_ifi = rh.Employe(
bcc0c52d 201 id=4,
493f7aab
OL
202 nom="Employé",
203 prenom="BAP IFI",
204 )
205 self.employe_bap_ifi.save()
206
207 ######
208 # ACGL
209 ######
210 self.poste_cnf_ngaoundere = rh.Poste(nom="poste à NGAOUNDERE",
211 implantation=self.IMPLANTATION_ACGL_CNF_NGAOUNDERE)
212
213 self.poste_cnf_bangui = rh.Poste(nom="poste à BANGUI",
214 implantation=self.IMPLANTATION_ACGL_CNF_BANGUI)
215
216 self.poste_cnf_ngaoundere.save()
217 self.poste_cnf_bangui.save()
218
219 self.dossier_cnf_ngaoundere = rh.Dossier(poste=self.poste_cnf_ngaoundere,
f96ec25c 220 employe=self.employe_cnf_ngaoundere, date_debut=self.today)
493f7aab 221 self.dossier_cnf_bangui = rh.Dossier(poste=self.poste_cnf_bangui,
f96ec25c 222 employe=self.employe_cnf_bangui, date_debut=self.today)
493f7aab
OL
223
224 self.dossier_cnf_ngaoundere.save()
225 self.dossier_cnf_bangui.save()
226
227 #####
228 # BAP
229 #####
230 self.poste_bap_bureau = rh.Poste(nom="poste au Bureau BAP",
231 implantation=self.IMPLANTATION_BAP_BUREAU)
232 self.poste_bap_ifi = rh.Poste(nom="poste à l'IFI",
233 implantation=self.IMPLANTATION_BAP_IFI)
234
235 self.poste_bap_bureau.save()
236 self.poste_bap_ifi.save()
237
238 self.dossier_bap_bureau = rh.Dossier(poste=self.poste_bap_bureau,
f96ec25c 239 employe=self.employe_bap_bureau, date_debut=self.today)
493f7aab 240 self.dossier_bap_ifi = rh.Dossier(poste=self.poste_bap_ifi,
f96ec25c 241 employe=self.employe_bap_ifi, date_debut=self.today)
493f7aab
OL
242
243 self.dossier_bap_bureau.save()
244 self.dossier_bap_ifi.save()
245
246 ##############
247 # Users Django
248 ##############
bcc0c52d
OL
249 self._clean_refs()
250 for idx, e in enumerate(rh.Employe.objects.all().order_by('id')):
493f7aab
OL
251 email = u"%s@test.auf" % idx
252 u = User(first_name=e.prenom,
253 is_staff=True,
254 last_name=e.nom,
255 username=email,
256 email=email)
257 u.set_password(self.password)
258 u.save()
259
260 # on le porte dans le référentiel employé
261 ref_e = ref.Employe(id=u.id,
262 nom=e.nom, prenom=e.prenom,
263 implantation=e.poste_principal().implantation,
264 implantation_physique=e.poste_principal().implantation,
265 service=ref.Service.objects.get(id=1))
266 ref_e.save()
267
bcc0c52d
OL
268 # on le porte dans le référentiel auth
269 ref.Authentification(id=ref_e, courriel=u.email).save()
270
271 def _clean_refs(self):
493f7aab
OL
272 courriels = [u"%s@test.auf" % idx for idx, e in
273 enumerate(rh.Employe.objects.all())]
274 ref.Employe.objects.filter(courriel__in=courriels).delete()
bcc0c52d
OL
275 ref.Authentification.objects.filter(courriel__in=courriels).delete()
276
277 def tearDown(self):
278 self._clean_refs()
493f7aab
OL
279
280 def _test_acces_ok(self, url):
281 response = self.client.get(url, follow=True)
282 self.assertEqual(response.status_code, 200)
283 self.assertEqual('next' in response.context, False)
284
285 def _test_acces_ko(self, url):
286 response = self.client.get(url, follow=True)
7700dae6 287 is_ko = response.status_code in (403, 404) or 'next' in response.context
493f7aab
OL
288 self.assertEqual(is_ko, True)
289
290 def _test_anonyme(self):
291 pass
292
bcc0c52d 293 def _test_correspondant_rh(self, email="0@test.auf"):
493f7aab 294 u = User.objects.get(email=email)
3383b2d1
OL
295 self.grp_correspondants_rh.user_set.add(u)
296 self.grp_correspondants_rh.save()
493f7aab
OL
297
298 credentials = {'username': email, 'password': self.password}
299 self.assertTrue(self.client.login(**credentials), "login failed")
300
bcc0c52d 301 def _test_administrateur_regional(self, email="0@test.auf"):
493f7aab 302 u = User.objects.get(email=email)
3383b2d1
OL
303 self.grp_administrateurs.user_set.add(u)
304 self.grp_administrateurs.save()
493f7aab
OL
305
306 credentials = {'username': email, 'password': self.password}
307 self.assertTrue(self.client.login(**credentials), "login failed")
308
bcc0c52d 309 def _test_directeur_bureau(self, email="0@test.auf"):
493f7aab 310 u = User.objects.get(email=email)
3383b2d1
OL
311 self.grp_directeurs_bureau.user_set.add(u)
312 self.grp_directeurs_bureau.save()
493f7aab
OL
313
314 credentials = {'username': email, 'password': self.password}
315 self.assertTrue(self.client.login(**credentials), "login failed")
316
317 def _test_drh(self):
318 email = "0@test.auf"
319
320 u = User.objects.get(email=email)
3383b2d1
OL
321 self.grp_drh.user_set.add(u)
322 self.grp_drh.save()
493f7aab
OL
323
324 credentials = {'username': email, 'password': self.password}
325 self.assertTrue(self.client.login(**credentials), "login failed")
326
327 def _test_drh2(self):
328 email = "0@test.auf"
329
330 u = User.objects.get(email=email)
3383b2d1
OL
331 self.grp_drh2.user_set.add(u)
332 self.grp_drh2.save()
493f7aab
OL
333
334 credentials = {'username': email, 'password': self.password}
335 self.assertTrue(self.client.login(**credentials), "login failed")
336
337 def _test_grp_accior(self):
338 email = "0@test.auf"
339
340 u = User.objects.get(email=email)
3383b2d1
OL
341 self.grp_accior.user_set.add(u)
342 self.grp_accior.save()
493f7aab
OL
343
344 credentials = {'username': email, 'password': self.password}
345 self.assertTrue(self.client.login(**credentials), "login failed")
346
347 def _test_grp_abf(self):
348 email = "0@test.auf"
349
350 u = User.objects.get(email=email)
3383b2d1
OL
351 self.grp_abf.user_set.add(u)
352 self.grp_abf.save()
493f7aab
OL
353
354 credentials = {'username': email, 'password': self.password}
355 self.assertTrue(self.client.login(**credentials), "login failed")
356
357 def _test_grp_haute_direction(self):
358 email = "0@test.auf"
359
360 u = User.objects.get(email=email)
3383b2d1
OL
361 self.grp_haute_direction.user_set.add(u)
362 self.grp_haute_direction.save()
493f7aab
OL
363
364 credentials = {'username': email, 'password': self.password}
365 self.assertTrue(self.client.login(**credentials), "login failed")
366
367 def _test_grp_service_utilisateurs(self):
368 email = "0@test.auf"
369
370 u = User.objects.get(email=email)
3383b2d1
OL
371 self.grp_service_utilisateurs.user_set.add(u)
372 self.grp_service_utilisateurs.save()
493f7aab
OL
373
374 credentials = {'username': email, 'password': self.password}
375 self.assertTrue(self.client.login(**credentials), "login failed")