test rapport masse salariale
[auf_rh_dae.git] / project / rh / test / rapport.py
index 2e5a4ba..69e3454 100644 (file)
@@ -2,6 +2,7 @@
 
 import datetime
 from django.core.urlresolvers import reverse
+from django.contrib.auth.models import User
 from project.rh.test.common import RhTest
 from project.rh import models as rh
 
@@ -29,31 +30,6 @@ class RapportContratTest(RhTest):
                 dossier=self.dossier_bap_ifi)
         contrat.save()
 
-        salaire = rh.TypeRemuneration(nom="salaire",
-                type_paiement="Régulier",
-                nature_remuneration="Indemnité",
-                )
-        salaire.save()
-
-        remun_cnf_ngaoundere = rh.Remuneration(
-                type=salaire,
-                date_debut=self.today,
-                dossier=self.dossier_cnf_ngaoundere,
-                montant="100",
-                devise=self.devise_cad,
-                )
-        remun_cnf_ngaoundere.save()
-
-        remun_bap_ifi = rh.Remuneration(
-                type=salaire,
-                date_debut=self.today,
-                dossier=self.dossier_bap_ifi,
-                montant="200",
-                devise=self.devise_cad,
-                )
-        remun_bap_ifi.save()
-
-
     def test_anonyme(self):
         """
         Un anonyme ne peut pas accéder à ce rapport
@@ -144,47 +120,8 @@ class RapportMasseSalarialeTest(RhTest):
     """
     url = reverse('rhr_masse_salariale')
 
-    today = datetime.date.today()
-    annee_moins_2 = datetime.date(today.year - 2, 1, 1)
-    annee_moins_1 = datetime.date(today.year - 1, 1, 1)
-    annee_plus_2 = datetime.date(today.year + 2, 1, 1)
-    annee_plus_1 = datetime.date(today.year + 1, 1, 1)
-
-
     def setUp(self):
         super(RapportMasseSalarialeTest, self).setUp()
-        # 2 dossiers actifs
-        self.dossier_cnf_ngaoundere.date_debut = self.annee_moins_1
-        self.dossier_cnf_ngaoundere.date_fin = self.annee_plus_1
-        self.dossier_cnf_ngaoundere.save()
-
-        self.dossier_cnf_bangui.date_debut = self.annee_moins_1
-        self.dossier_cnf_bangui.date_fin = self.annee_plus_1
-        self.dossier_cnf_bangui.save()
-
-        # 1 dossier inactif
-        self.dossier_bap_bureau.date_debut = self.annee_moins_2
-        self.dossier_bap_bureau.date_fin = self.annee_moins_1
-        self.dossier_bap_bureau.save()
-
-        # 1 dossier futur
-        self.dossier_bap_ifi.date_debut = self.annee_plus_1
-        self.dossier_bap_ifi.date_fin = self.annee_plus_2
-        self.dossier_bap_ifi.save()
-
-    def test_filtrage(self):
-        """
-        Test la page avec des paramètres de filtrage.
-        """
-        self._test_drh()
-        self._test_acces_ok(self.url)
-        params = {'implantation': self.IMPLANTATION_ACGL_CNF_NGAOUNDERE.id,
-                'region': self.REGION_ACGL.id,
-                'annee': self.today.year,
-                }
-        resp = self.client.get(self.url, params)
-        self.assertEqual(resp.context['form'].is_valid(), True)
-        self.assertEqual(resp.status_code, 200)
 
     def test_anonyme(self):
         """
@@ -369,3 +306,142 @@ class RapportOrganigrammeTest(RhTest):
         self._test_grp_service_utilisateurs()
         for url in self.urls:
             self._test_acces_ko(url)
+
+class RapportMasseSalarialeCalculTest(RhTest):
+    """
+    Test l'accès au rapport de masse salariale
+    """
+    url = reverse('rhr_masse_salariale')
+
+    today = datetime.date.today()
+    annee_moins_2 = datetime.date(today.year - 2, 1, 1)
+    annee_moins_1 = datetime.date(today.year - 1, 1, 1)
+    annee_plus_2 = datetime.date(today.year + 2, 1, 1)
+    annee_plus_1 = datetime.date(today.year + 1, 1, 1)
+
+
+    def setUp(self):
+        super(RapportMasseSalarialeCalculTest, self).setUp()
+
+        self.type_salaire = rh.TypeRemuneration(nom="salaire",
+                type_paiement="Régulier",
+                nature_remuneration="Indemnité",
+                )
+        self.type_salaire.save()
+
+        # 4 dossiers actifs
+        self.dossier_cnf_ngaoundere.date_debut = self.annee_moins_1
+        self.dossier_cnf_ngaoundere.date_fin = self.annee_plus_1
+        self.dossier_cnf_ngaoundere.save()
+
+        self.dossier_cnf_bangui.date_debut = self.annee_moins_1
+        self.dossier_cnf_bangui.date_fin = self.annee_plus_1
+        self.dossier_cnf_bangui.save()
+
+        self.dossier_bap_bureau.date_debut = self.annee_moins_1
+        self.dossier_bap_bureau.date_fin = self.annee_plus_1
+        self.dossier_bap_bureau.save()
+
+        self.dossier_bap_ifi.date_debut = self.annee_moins_1
+        self.dossier_bap_ifi.date_fin = self.annee_plus_1
+        self.dossier_bap_ifi.save()
+
+
+        self.remun_cnf_ngaoundere = rh.Remuneration(
+                type=self.type_salaire,
+                date_debut=self.annee_moins_1,
+                dossier=self.dossier_cnf_ngaoundere,
+                montant="111",
+                devise=self.devise_cad,
+                )
+        self.remun_cnf_ngaoundere.save()
+
+        self.remun_cnf_bangui = rh.Remuneration(
+                type=self.type_salaire,
+                date_debut=self.annee_moins_1,
+                dossier=self.dossier_cnf_bangui,
+                montant="222",
+                devise=self.devise_cad,
+                )
+        self.remun_cnf_bangui.save()
+
+        self.remun_bap_bureau = rh.Remuneration(
+                type=self.type_salaire,
+                date_debut=self.annee_moins_1,
+                dossier=self.dossier_bap_bureau,
+                montant="333",
+                devise=self.devise_cad,
+                )
+        self.remun_bap_bureau.save()
+
+        self.remun_bap_ifi = rh.Remuneration(
+                type=self.type_salaire,
+                date_debut=self.annee_moins_1,
+                dossier=self.dossier_bap_ifi,
+                montant="444",
+                devise=self.devise_cad,
+                )
+        self.remun_bap_ifi.save()
+
+        self.taux_change_cad = \
+            rh.TauxChange(devise=self.devise_cad,
+                taux=0.5,
+                annee=self.today.year)
+        self.taux_change_cad.save()
+
+    def test_taux_change_presence(self):
+        """
+        Intégrité des rémunérations.
+        """
+        from project.rh.views import rapports_masse_salariale
+
+        self._test_drh()
+        user_drh = User.objects.get(email="0@test.auf")
+        params = {'annee': self.today.year,  }
+
+        class Request:
+            GET = params
+            user = user_drh
+            
+            def get_full_path(self):
+                return
+
+        request = Request()
+        
+        self.taux_change_cad.delete()
+
+        self.assertRaises(rh.RemunIntegrityException,
+                rapports_masse_salariale, request)
+
+
+    def test_filtrage(self):
+        """
+        Test la page avec des paramètres de filtrage.
+        """
+        self._test_drh()
+        self._test_acces_ok(self.url)
+
+        params = {'implantation': self.IMPLANTATION_ACGL_CNF_NGAOUNDERE.id,
+                'annee': self.today.year,
+                }
+        resp = self.client.get(self.url, params)
+        self.assertEqual(resp.status_code, 200)
+        self.assertEqual(resp.context['form'].is_valid(), True, resp.context['form'].errors)
+        self.assertEqual(len(resp.context['lignes']), 1)
+
+        params = {
+                'region': self.REGION_ACGL.id,
+                'annee': self.today.year,
+                }
+        resp = self.client.get(self.url, params)
+        self.assertEqual(resp.status_code, 200)
+        self.assertEqual(resp.context['form'].is_valid(), True)
+        self.assertEqual(len(resp.context['lignes']), 2)
+
+        params = {
+                'annee': self.today.year,
+                }
+        resp = self.client.get(self.url, params)
+        self.assertEqual(resp.status_code, 200)
+        self.assertEqual(resp.context['form'].is_valid(), True)
+        self.assertEqual(len(resp.context['lignes']), 4)