Exemple #1
0
    def test_is_eligible_case_raising_exception(self, mock_is_eligible):
        person = PersonWithPermissionsFactory()
        perm = CommonEducationGroupStrategyPerms(person.user,
                                                 TrainingFactory())

        with self.assertRaises(PermissionDenied):
            perm.is_eligible(raise_exception=True)
Exemple #2
0
    def test_ensure_is_eligible_case_permission_denied(
            self, mock_linked_to_management, mock_is_current_in_range):
        perm = CommonEducationGroupStrategyPerms(self.person.user,
                                                 TrainingFactory())

        with self.assertRaises(PermissionDenied):
            perm._is_eligible()
Exemple #3
0
    def test_ensure_is_eligible_case_all_submethod_true(
            self, mock_linked_to_management, mock_is_current_in_range):
        perm = CommonEducationGroupStrategyPerms(self.person.user,
                                                 TrainingFactory())

        self.assertTrue(perm._is_eligible())
        self.assertTrue(mock_linked_to_management.called)
        self.assertTrue(mock_is_current_in_range.called)
Exemple #4
0
    def test_is_eligible_case_user_as_superuser_case_greater_or_equal_limit_year(
            self):
        super_user = UserFactory(is_superuser=True)
        training = TrainingFactory(
            academic_year__year=settings.YEAR_LIMIT_EDG_MODIFICATION)

        perm = CommonEducationGroupStrategyPerms(super_user, training)
        self.assertTrue(perm._is_eligible())
Exemple #5
0
    def test_is_lower_than_limit_edg_year_case_lower(self):
        """This test ensure that we cannot modify OF which lower than limit year"""
        training_lower = TrainingFactory(
            academic_year__year=settings.YEAR_LIMIT_EDG_MODIFICATION - 1)

        perm = CommonEducationGroupStrategyPerms(self.person.user,
                                                 training_lower)
        self.assertTrue(perm._is_lower_than_limit_edg_year())
Exemple #6
0
    def test_is_current_academic_year_in_range_of_editable_education_group_year_case_in_range(self):
        """This test ensure that we modify OF which lower than N+1"""
        training_n1 = TrainingFactory(academic_year__year=self.current_academic_year.year + 1)
        training = TrainingFactory(academic_year=self.current_academic_year)

        for education_group_year in [training_n1, training]:
            perm = CommonEducationGroupStrategyPerms(self.person.user, education_group_year)
            self.assertTrue(perm._is_current_academic_year_in_range_of_editable_education_group_year())
Exemple #7
0
    def test_is_eligible_case_user_as_superuser_case_lower_than_limit_year(
            self):
        super_user = UserFactory(is_superuser=True)
        training = TrainingFactory(
            academic_year__year=settings.YEAR_LIMIT_EDG_MODIFICATION - 1)

        perm = CommonEducationGroupStrategyPerms(super_user, training)
        with self.assertRaises(PermissionDenied):
            perm._is_eligible()
Exemple #8
0
    def test_is_lower_than_limit_edg_year_case_greater(self):
        """This test ensure that we modify OF which greater or equal than limit year"""
        training_limit_year = TrainingFactory(
            academic_year__year=settings.YEAR_LIMIT_EDG_MODIFICATION + 1)
        training_greater = TrainingFactory(
            academic_year__year=settings.YEAR_LIMIT_EDG_MODIFICATION)

        for education_group_year in [training_limit_year, training_greater]:
            with self.subTest(msg=education_group_year):
                perm = CommonEducationGroupStrategyPerms(
                    self.person.user, education_group_year)
                self.assertFalse(perm._is_lower_than_limit_edg_year())
Exemple #9
0
    def test_is_current_academic_year_in_range_of_editable_education_group_year_case_not_in_range(
            self):
        """This test ensure that we cannot modify OF which greater than N+1"""
        training_in_future = TrainingFactory(
            academic_year__year=self.current_academic_year.year + 2)

        perm = CommonEducationGroupStrategyPerms(self.person.user,
                                                 training_in_future)
        self.assertFalse(
            perm.
            _is_current_academic_year_in_range_of_editable_education_group_year(
            ))
Exemple #10
0
    def test_is_eligible_case_user_as_superuser(self):
        super_user = UserFactory(is_superuser=True)
        training = TrainingFactory()

        perm = CommonEducationGroupStrategyPerms(super_user, training)
        self.assertTrue(perm._is_eligible())
Exemple #11
0
    def test_is_linked_to_management_entity(self, mock_check_link):
        training = TrainingFactory()
        perm = CommonEducationGroupStrategyPerms(self.person.user, training)

        self.assertTrue(perm._is_linked_to_management_entity())
        self.assertTrue(mock_check_link.called)
Exemple #12
0
    def test_is_eligible_case_no_raising_exception(self, mock_is_eligible):
        person = PersonWithPermissionsFactory()
        perm = CommonEducationGroupStrategyPerms(person.user,
                                                 TrainingFactory())

        self.assertFalse(perm.is_eligible(raise_exception=False))
Exemple #13
0
 def test_person_property(self):
     person = PersonWithPermissionsFactory()
     perm = CommonEducationGroupStrategyPerms(person.user,
                                              TrainingFactory())
     self.assertEqual(perm.person, person)