delete offre emploi
[auf_rh_dae.git] / project / rh / test / common.py
1 # -*- coding: utf-8 -*-
2
3 import datetime
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
9
10 class RhTest(TestCase):
11
12 def setUp(self):
13 """
14 GROUPES
15 =======
16 self.grp_correspondants_rh
17 self.grp_administrateurs
18 self.grp_directeurs_bureau
19 self.grp_drh
20 self.grp_drh2
21 self.grp_accior
22 self.grp_abf
23 self.grp_haute_direction
24 self.grp_service_utilisateurs
25
26 POSTES
27 ======
28 self.poste_cnf_ngaoundere
29 self.poste_cnf_bangui
30 self.poste_bap_bureau
31 self.poste_bap_ifi
32
33 EMPLOYES
34 ========
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
39
40 USERS DJANGO
41 ============
42 cf. EMPLOYES
43
44 DOSSIERS
45 ========
46 self.dossier_cnf_ngaoundere
47 self.dossier_cnf_bangui
48 self.dossier_bap_bureau
49 self.dossier_bap_ifi
50
51
52 """
53 self.grp_correspondants_rh = Group(name=groups.CORRESPONDANT_RH)
54 self.grp_correspondants_rh.save()
55
56 self.grp_administrateurs = Group(name=groups.ADMINISTRATEURS)
57 self.grp_administrateurs.save()
58
59 self.grp_directeurs_bureau = Group(name=groups.DIRECTEUR_DE_BUREAU)
60 self.grp_directeurs_bureau.save()
61
62 self.grp_drh = Group(name=groups.DRH_NIVEAU_1)
63 self.grp_drh.save()
64
65 self.grp_drh2 = Group(name=groups.DRH_NIVEAU_2)
66 self.grp_drh2.save()
67
68 self.grp_accior = Group(name=groups.ACCIOR)
69 self.grp_accior.save()
70
71 self.grp_abf = Group(name=groups.ABF)
72 self.grp_abf.save()
73
74 self.grp_haute_direction = Group(name=groups.HAUTE_DIRECTION)
75 self.grp_haute_direction.save()
76
77 self.grp_service_utilisateurs = Group(name=groups.SERVICE_UTILISATEURS)
78 self.grp_service_utilisateurs.save()
79
80 self.password = "0000"
81 self.today = datetime.datetime.now()
82 self.tomorrow = self.today + datetime.timedelta(days=1)
83
84 #########################
85 # Régions / Implantations
86 #########################
87 self.REGION_ACGL = ref.Region.objects.get(id=1)
88 self.IMPLANTATION_ACGL_CNF_NGAOUNDERE = ref.Implantation.objects.get(id=90)
89 self.IMPLANTATION_ACGL_CNF_BANGUI = ref.Implantation.objects.get(id=85)
90
91 self.REGION_BAP = ref.Region.objects.get(id=4)
92 self.IMPLANTATION_BAP_BUREAU = ref.Implantation.objects.get(id=51)
93 self.IMPLANTATION_BAP_IFI = ref.Implantation.objects.get(id=55)
94
95
96 ##########
97 # Employés
98 ##########
99 self.employe_cnf_ngaoundere = rh.Employe(
100 id=1,
101 nom="Employé",
102 prenom="ngaoundere",
103 )
104 self.employe_cnf_ngaoundere.save()
105 self.employe_cnf_bangui = rh.Employe(
106 id=2,
107 nom="Employé",
108 prenom="bangui",
109 )
110 self.employe_cnf_bangui.save()
111 self.employe_bap_bureau = rh.Employe(
112 id=3,
113 nom="Employé",
114 prenom="BAP bureau",
115 )
116 self.employe_bap_bureau.save()
117 self.employe_bap_ifi = rh.Employe(
118 id=4,
119 nom="Employé",
120 prenom="BAP IFI",
121 )
122 self.employe_bap_ifi.save()
123
124 ######
125 # ACGL
126 ######
127 self.poste_cnf_ngaoundere = rh.Poste(nom="poste à NGAOUNDERE",
128 implantation=self.IMPLANTATION_ACGL_CNF_NGAOUNDERE)
129
130 self.poste_cnf_bangui = rh.Poste(nom="poste à BANGUI",
131 implantation=self.IMPLANTATION_ACGL_CNF_BANGUI)
132
133 self.poste_cnf_ngaoundere.save()
134 self.poste_cnf_bangui.save()
135
136 self.dossier_cnf_ngaoundere = rh.Dossier(poste=self.poste_cnf_ngaoundere,
137 employe=self.employe_cnf_ngaoundere, date_debut=self.today)
138 self.dossier_cnf_bangui = rh.Dossier(poste=self.poste_cnf_bangui,
139 employe=self.employe_cnf_bangui, date_debut=self.today)
140
141 self.dossier_cnf_ngaoundere.save()
142 self.dossier_cnf_bangui.save()
143
144 #####
145 # BAP
146 #####
147 self.poste_bap_bureau = rh.Poste(nom="poste au Bureau BAP",
148 implantation=self.IMPLANTATION_BAP_BUREAU)
149 self.poste_bap_ifi = rh.Poste(nom="poste à l'IFI",
150 implantation=self.IMPLANTATION_BAP_IFI)
151
152 self.poste_bap_bureau.save()
153 self.poste_bap_ifi.save()
154
155 self.dossier_bap_bureau = rh.Dossier(poste=self.poste_bap_bureau,
156 employe=self.employe_bap_bureau, date_debut=self.today)
157 self.dossier_bap_ifi = rh.Dossier(poste=self.poste_bap_ifi,
158 employe=self.employe_bap_ifi, date_debut=self.today)
159
160 self.dossier_bap_bureau.save()
161 self.dossier_bap_ifi.save()
162
163 ##############
164 # Users Django
165 ##############
166 self._clean_refs()
167 for idx, e in enumerate(rh.Employe.objects.all().order_by('id')):
168 email = u"%s@test.auf" % idx
169 u = User(first_name=e.prenom,
170 is_staff=True,
171 last_name=e.nom,
172 username=email,
173 email=email)
174 u.set_password(self.password)
175 u.save()
176
177 # on le porte dans le référentiel employé
178 ref_e = ref.Employe(id=u.id,
179 nom=e.nom, prenom=e.prenom,
180 implantation=e.poste_principal().implantation,
181 implantation_physique=e.poste_principal().implantation,
182 service=ref.Service.objects.get(id=1))
183 ref_e.save()
184
185 # on le porte dans le référentiel auth
186 ref.Authentification(id=ref_e, courriel=u.email).save()
187
188 def _clean_refs(self):
189 courriels = [u"%s@test.auf" % idx for idx, e in
190 enumerate(rh.Employe.objects.all())]
191 ref.Employe.objects.filter(courriel__in=courriels).delete()
192 ref.Authentification.objects.filter(courriel__in=courriels).delete()
193
194 def tearDown(self):
195 self._clean_refs()
196
197 def _test_acces_ok(self, url):
198 response = self.client.get(url, follow=True)
199 self.assertEqual(response.status_code, 200)
200 self.assertEqual('next' in response.context, False)
201
202 def _test_acces_ko(self, url):
203 response = self.client.get(url, follow=True)
204 is_ko = response.status_code == 403 or 'next' in response.context
205 self.assertEqual(is_ko, True)
206
207 def _test_anonyme(self):
208 pass
209
210 def _test_correspondant_rh(self, email="0@test.auf"):
211 u = User.objects.get(email=email)
212 self.grp_correspondants_rh.user_set.add(u)
213 self.grp_correspondants_rh.save()
214
215 credentials = {'username': email, 'password': self.password}
216 self.assertTrue(self.client.login(**credentials), "login failed")
217
218 def _test_administrateur_regional(self, email="0@test.auf"):
219 u = User.objects.get(email=email)
220 self.grp_administrateurs.user_set.add(u)
221 self.grp_administrateurs.save()
222
223 credentials = {'username': email, 'password': self.password}
224 self.assertTrue(self.client.login(**credentials), "login failed")
225
226 def _test_directeur_bureau(self, email="0@test.auf"):
227 u = User.objects.get(email=email)
228 self.grp_directeurs_bureau.user_set.add(u)
229 self.grp_directeurs_bureau.save()
230
231 credentials = {'username': email, 'password': self.password}
232 self.assertTrue(self.client.login(**credentials), "login failed")
233
234 def _test_drh(self):
235 email = "0@test.auf"
236
237 u = User.objects.get(email=email)
238 self.grp_drh.user_set.add(u)
239 self.grp_drh.save()
240
241 credentials = {'username': email, 'password': self.password}
242 self.assertTrue(self.client.login(**credentials), "login failed")
243
244 def _test_drh2(self):
245 email = "0@test.auf"
246
247 u = User.objects.get(email=email)
248 self.grp_drh2.user_set.add(u)
249 self.grp_drh2.save()
250
251 credentials = {'username': email, 'password': self.password}
252 self.assertTrue(self.client.login(**credentials), "login failed")
253
254 def _test_grp_accior(self):
255 email = "0@test.auf"
256
257 u = User.objects.get(email=email)
258 self.grp_accior.user_set.add(u)
259 self.grp_accior.save()
260
261 credentials = {'username': email, 'password': self.password}
262 self.assertTrue(self.client.login(**credentials), "login failed")
263
264 def _test_grp_abf(self):
265 email = "0@test.auf"
266
267 u = User.objects.get(email=email)
268 self.grp_abf.user_set.add(u)
269 self.grp_abf.save()
270
271 credentials = {'username': email, 'password': self.password}
272 self.assertTrue(self.client.login(**credentials), "login failed")
273
274 def _test_grp_haute_direction(self):
275 email = "0@test.auf"
276
277 u = User.objects.get(email=email)
278 self.grp_haute_direction.user_set.add(u)
279 self.grp_haute_direction.save()
280
281 credentials = {'username': email, 'password': self.password}
282 self.assertTrue(self.client.login(**credentials), "login failed")
283
284 def _test_grp_service_utilisateurs(self):
285 email = "0@test.auf"
286
287 u = User.objects.get(email=email)
288 self.grp_service_utilisateurs.user_set.add(u)
289 self.grp_service_utilisateurs.save()
290
291 credentials = {'username': email, 'password': self.password}
292 self.assertTrue(self.client.login(**credentials), "login failed")