Esempio n. 1
0
    def test_delete_case_remove_mandatory_structure_case_reused_item_which_are_mandatory(
            self):
        """
        In this test, we ensure that the mandatory elem is not removed if it is reused in another structure
        """
        education_group_year = TrainingFactory(
            academic_year=self.academic_year)

        child_mandatory = GroupFactory(
            academic_year=self.academic_year,
            education_group_type__name=GroupType.COMMON_CORE.name)
        AuthorizedRelationshipFactory(
            parent_type=education_group_year.education_group_type,
            child_type=child_mandatory.education_group_type,
            min_count_authorized=1,
        )
        link_parent_child = GroupElementYearFactory(
            parent=education_group_year, child_branch=child_mandatory)

        # Create another training
        another_training = TrainingFactory(academic_year=self.academic_year)
        GroupElementYearFactory(parent=another_training,
                                child_branch=child_mandatory)

        delete.start(education_group_year)
        with self.assertRaises(EducationGroupYear.DoesNotExist):
            EducationGroupYear.objects.get(pk=education_group_year.pk)
        with self.assertRaises(GroupElementYear.DoesNotExist):
            GroupElementYear.objects.get(pk=link_parent_child.pk)

        self.assertEqual(child_mandatory,
                         EducationGroupYear.objects.get(pk=child_mandatory.pk))
Esempio n. 2
0
    def test_delete_case_no_mandatory_structure(self):
        education_group_year = TrainingFactory(
            academic_year=self.academic_year)
        delete.start(education_group_year)

        with self.assertRaises(EducationGroupYear.DoesNotExist):
            EducationGroupYear.objects.get(pk=education_group_year.pk)
Esempio n. 3
0
def start(education_group, until_year):
    """
    This function will delete all education group year
    """
    education_group_years_to_delete = delete.get_education_group_years_to_delete(education_group, end_year=until_year)
    egy_deleted = []
    for education_group_year in education_group_years_to_delete:
        egy_deleted.append(education_group_year)
        delete.start(education_group_year)
    return egy_deleted
Esempio n. 4
0
def start(education_group, until_year):
    """
    This function will delete all education group year
    """
    education_group_years_to_delete = delete.get_education_group_years_to_delete(
        education_group, end_year=until_year)
    egy_deleted = []
    for education_group_year in education_group_years_to_delete:
        egy_deleted.append(education_group_year)
        delete.start(education_group_year)
    return egy_deleted
Esempio n. 5
0
    def test_delete_case_remove_mandatory_structure(self):
        education_group_year = TrainingFactory(
            academic_year=self.academic_year)

        child_mandatory = GroupFactory(
            academic_year=self.academic_year,
            education_group_type__name=GroupType.COMMON_CORE.name)
        AuthorizedRelationshipFactory(
            parent_type=education_group_year.education_group_type,
            child_type=child_mandatory.education_group_type,
            min_count_authorized=1,
        )
        link_parent_child = GroupElementYearFactory(
            parent=education_group_year, child_branch=child_mandatory)

        delete.start(education_group_year)
        with self.assertRaises(EducationGroupYear.DoesNotExist):
            EducationGroupYear.objects.get(pk=education_group_year.pk)
        with self.assertRaises(EducationGroupYear.DoesNotExist):
            EducationGroupYear.objects.get(pk=child_mandatory.pk)
        with self.assertRaises(GroupElementYear.DoesNotExist):
            GroupElementYear.objects.get(pk=link_parent_child.pk)
Esempio n. 6
0
 def delete(self, request, *args, **kwargs):
     for education_group_year in delete.get_education_group_years_to_delete(
             self.get_object()):
         delete.start(education_group_year)
     common.display_success_messages(request, self.success_message)
     return JsonResponse({'success': True, 'success_url': self.success_url})