def test_with_filters_case_childs_with_different_academic_years(self):
     child_leaf_other_ac_year = LearningUnitYearFactory(
         academic_year=AcademicYearFactory(
             year=self.current_academic_year.year - 1))
     with self.assertRaises(AttributeError):
         group_element_year.find_learning_unit_roots(
             [self.child_leaf, child_leaf_other_ac_year])
 def test_find_learning_unit_roots_improper_parameters(self):
     with self.assertRaisesMessage(
             ValueError,
             "If parameter with_parents_of_parents is True, parameter parents_as_instances must be True"
     ):
         group_element_year.find_learning_unit_roots(
             [],
             return_result_params={
                 'parents_as_instances': False,
                 'with_parents_of_parents': True
             })
 def test_with_filters_case_direct_parent_id_root_and_matches_filters(self):
     element_year = GroupElementYearFactory(parent=self.root,
                                            child_branch=None,
                                            child_leaf=self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     expected_result = {self.child_leaf.id: [element_year.parent.id]}
     self.assertEqual(result, expected_result)
示例#4
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data()

        learning_unit_year = context["learning_unit_year"]
        education_group_year_root = EducationGroupYear.objects.get(
            id=context["root_id"])

        formations = group_element_year.find_learning_unit_roots(
            [learning_unit_year],
            return_result_params={
                'parents_as_instances': True,
                'with_parents_of_parents': True
            })

        formations_set = set(
            flatten([parents for child_id, parents in formations.items()]))

        if education_group_year_root not in formations_set:
            raise PermissionDenied(
                _("You must be in the context of a training to modify the prerequisites to a learning unit "
                  "(current context: %(partial_acronym)s - %(acronym)s)") % {
                      'acronym': education_group_year_root.acronym,
                      'partial_acronym':
                      education_group_year_root.partial_acronym
                  })

        return context
 def test_with_kwarg_parents_as_instances_is_true(self):
     group_element = GroupElementYearFactory(child_branch=None,
                                             child_leaf=self.child_leaf)
     result = group_element_year.find_learning_unit_roots(
         [self.child_leaf],
         return_result_params={'parents_as_instances': True})
     self.assertEqual(result[self.child_leaf.id], [group_element.parent])
示例#6
0
 def _parents(self):
     return group_element_year.find_learning_unit_roots(
         [self.parent],
         return_result_params={
             'parents_as_instances': True
         }
     )[self.parent.pk] + [self.parent]
示例#7
0
 def has_or_is_prerequisite(self, education_group_year):
     formations = group_element_year.find_learning_unit_roots(
         [education_group_year])[education_group_year.id]
     return PrerequisiteItem.objects.filter(
         Q(prerequisite__learning_unit_year=self,
           prerequisite__education_group_year__in=formations)
         | Q(prerequisite__education_group_year__in=formations,
             learning_unit=self.learning_unit)).exists()
 def test_with_filters_case_objects_are_education_group_instance(self):
     root = EducationGroupYearFactory(
         academic_year=self.current_academic_year, )
     child_branch = EducationGroupYearFactory(
         academic_year=self.current_academic_year, )
     GroupElementYearFactory(parent=root, child_branch=child_branch)
     result = group_element_year.find_learning_unit_roots([child_branch])
     expected_result = {child_branch.id: [root.id]}
     self.assertDictEqual(result, expected_result)
 def test_with_kwarg_is_root_when_matches_is_complementary_module_and_not_in_it(
         self):
     group_element = GroupElementYearFactory(child_branch=None,
                                             child_leaf=self.child_leaf)
     result = group_element_year.find_learning_unit_roots(
         [self.child_leaf],
         luy=self.child_leaf,
         is_root_when_matches=[GroupType.COMPLEMENTARY_MODULE])
     self.assertEqual(result[self.child_leaf.id], [group_element.parent.id])
示例#10
0
文件: detail.py 项目: allouchmed/osis
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context["group_element_years"] = self.object.child_branch.select_related("parent")
     context["formations"] = find_learning_unit_roots(
         list(grp.parent for grp in self.object.child_branch.select_related("parent")),
         return_result_params={
             'parents_as_instances': True
         }
     )
     return context
示例#11
0
 def test_case_group_category_is_not_root(self):
     a_group_type = EducationGroupTypeFactory(
         name='Subgroup', category=education_group_categories.GROUP)
     hierarchy = self._build_hierarchy(self.current_academic_year,
                                       a_group_type, self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertNotIn(hierarchy['group_element_child'].parent.id,
                      result[self.child_leaf.id])
     self.assertIn(hierarchy['group_element_root'].parent.id,
                   result[self.child_leaf.id])
示例#12
0
 def test_all_group_types_of_category_training_stops_recursivity(self):
     type_bachelor = EducationGroupTypeFactory(
         name='Bachelor', category=education_group_categories.TRAINING)
     hierarchy = self._build_hierarchy(self.current_academic_year,
                                       type_bachelor, self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertNotIn(hierarchy['group_element_root'].parent.id,
                      result[self.child_leaf.id])
     self.assertIn(hierarchy['group_element_child'].parent.id,
                   result[self.child_leaf.id])
示例#13
0
 def test_group_type_option_is_correctly_excluded(self):
     type_option = EducationGroupTypeFactory(
         name=MiniTrainingType.OPTION.name,
         category=education_group_categories.MINI_TRAINING)
     hierarchy = self._build_hierarchy(self.current_academic_year,
                                       type_option, self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertNotIn(hierarchy['group_element_child'].parent.id,
                      result[self.child_leaf.id])
     self.assertIn(hierarchy['group_element_root'].parent.id,
                   result[self.child_leaf.id])
示例#14
0
 def test_ids_correctly_converted_to_instances(self):
     group_element = GroupElementYearFactory(
         child_branch=None, child_leaf=LearningUnitYearFactory())
     root_ids_by_object_id = group_element_year.find_learning_unit_roots(
         [group_element.child_leaf])
     result = group_element_year._convert_parent_ids_to_instances(
         root_ids_by_object_id)
     expected_result = {group_element.child_leaf.id: [group_element.parent]}
     self.assertDictEqual(result, expected_result)
     self.assertIsInstance(list(result.keys())[0], int)
     self.assertIsInstance(result[group_element.child_leaf.id][0],
                           EducationGroupYear)
示例#15
0
 def test_case_group_category_is_root(self):
     a_group_type = EducationGroupTypeFactory(
         name='Subgroup', category=education_group_categories.GROUP)
     group_element = GroupElementYearFactory(
         parent=EducationGroupYearFactory(
             academic_year=self.current_academic_year,
             education_group_type=a_group_type),
         child_branch=None,
         child_leaf=self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertEqual(result[self.child_leaf.id], [])
     self.assertNotIn(group_element.parent.id, result[self.child_leaf.id])
示例#16
0
 def test_with_filters_case_direct_parent_is_root_and_not_matches_filter(
         self):
     root = EducationGroupYearFactory(
         academic_year=self.current_academic_year,
         education_group_type=EducationGroupTypeFactory(
             name='Options choices',
             category=education_group_categories.GROUP))
     GroupElementYearFactory(parent=root,
                             child_branch=None,
                             child_leaf=self.child_leaf)
     expected_result = {self.child_leaf.id: []}
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertDictEqual(result, expected_result)
示例#17
0
    def test_with_kwarg_is_root_when_matches_is_complementary_module_and_in_it(
            self):
        group_type = EducationGroupTypeFactory(
            name=GroupType.COMPLEMENTARY_MODULE.name,
            category=education_group_categories.GROUP)
        hierarchy = self._build_hierarchy(self.current_academic_year,
                                          group_type, self.child_leaf)
        result = group_element_year.find_learning_unit_roots(
            [self.child_leaf],
            luy=self.child_leaf,
            is_root_when_matches=[GroupType.COMPLEMENTARY_MODULE])

        self.assertEqual(result[self.child_leaf.id],
                         [hierarchy['group_element_child'].parent.id])
示例#18
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data()

        learning_unit_year = context["learning_unit_year"]
        formations_id = group_element_year.find_learning_unit_roots([learning_unit_year]). \
            get(learning_unit_year.id, [])
        qs = EducationGroupYear.objects.filter(id__in=formations_id)
        prefetch_prerequisites = Prefetch(
            "prerequisite_set",
            Prerequisite.objects.filter(learning_unit_year=learning_unit_year),
            to_attr="prerequisites")

        context["formations"] = qs.prefetch_related(prefetch_prerequisites)

        return context
示例#19
0
    def get_queryset(self):
        learning_unit_year = get_object_or_404(
            LearningUnitYear.objects.all().select_related('academic_year'),
            acronym=self.kwargs['acronym'].upper(),
            academic_year__year=self.kwargs['year']
        )
        education_group_root_ids = group_element_year.find_learning_unit_roots(
            [learning_unit_year],
            luy=learning_unit_year,
            is_root_when_matches=[GroupType.COMPLEMENTARY_MODULE]
        ).get(learning_unit_year.id, [])

        return EducationGroupYear.objects.filter(
            pk__in=education_group_root_ids
        ).select_related(
            'education_group_type', 'academic_year'
        )
示例#20
0
def map_learning_unit_year_with_entities_of_education_groups(learning_unit_year_qs):
    formations = group_element_year.find_learning_unit_roots(
        learning_unit_year_qs,
        return_result_params={
            'parents_as_instances': False
        }
    )
    education_group_ids = list(itertools.chain.from_iterable(formations.values()))
    offer_year_entity = OfferYearEntity.objects.filter(education_group_year__in=education_group_ids). \
        values_list("education_group_year", "entity")
    dict_entity_of_education_group = {education_group_year_id: entity_id for education_group_year_id, entity_id
                                      in offer_year_entity}

    dict_education_group_year_entities_for_learning_unit_year = {}
    for luy_id, formations_ids in formations.items():
        dict_education_group_year_entities_for_learning_unit_year[luy_id] = \
            [dict_entity_of_education_group.get(formation_id) for formation_id in formations_ids]
    return dict_education_group_year_entities_for_learning_unit_year
示例#21
0
 def test_with_filters_case_multiple_parents_in_2nd_level(self):
     root_2 = EducationGroupYearFactory(
         academic_year=self.current_academic_year,
         education_group_type=EducationGroupTypeFactory(
             name='Master', category=education_group_categories.TRAINING))
     child_branch = EducationGroupYearFactory(
         academic_year=self.current_academic_year,
         education_group_type=EducationGroupTypeFactory(
             category=education_group_categories.GROUP))
     GroupElementYearFactory(parent=self.root, child_branch=child_branch)
     GroupElementYearFactory(parent=root_2, child_branch=child_branch)
     GroupElementYearFactory(parent=child_branch,
                             child_branch=None,
                             child_leaf=self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertEqual(len(result[self.child_leaf.id]), 2)
     self.assertIn(self.root.id, result[self.child_leaf.id])
     self.assertIn(root_2.id, result[self.child_leaf.id])
示例#22
0
 def test_with_filters_case_root_in_2nd_level_and_direct_parent_matches_filter(
         self):
     root = EducationGroupYearFactory(
         academic_year=self.current_academic_year,
         education_group_type=EducationGroupTypeFactory(
             name='Master', category=education_group_categories.TRAINING))
     child_branch = EducationGroupYearFactory(
         academic_year=self.current_academic_year,
         education_group_type=EducationGroupTypeFactory(
             name='Didactic Master',
             category=education_group_categories.TRAINING))
     GroupElementYearFactory(parent=root, child_branch=child_branch)
     GroupElementYearFactory(parent=child_branch,
                             child_branch=None,
                             child_leaf=self.child_leaf)
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     expected_result = {self.child_leaf.id: [child_branch.id]}
     self.assertDictEqual(result, expected_result)
     self.assertNotIn(root.id, result)
示例#23
0
 def test_ordered_by_acronym(self):
     learn_unit_year = LearningUnitYearFactory()
     group_element1 = GroupElementYearFactory(
         parent=EducationGroupYearFactory(acronym='ECGE1BA'),
         child_branch=None,
         child_leaf=learn_unit_year)
     group_element2 = GroupElementYearFactory(
         parent=EducationGroupYearFactory(acronym='DROI1BA'),
         child_branch=None,
         child_leaf=learn_unit_year)
     group_element3 = GroupElementYearFactory(
         parent=EducationGroupYearFactory(acronym='SPOL2MS/G'),
         child_branch=None,
         child_leaf=learn_unit_year)
     root_ids_by_object_id = group_element_year.find_learning_unit_roots(
         [learn_unit_year])
     result = group_element_year._convert_parent_ids_to_instances(
         root_ids_by_object_id)
     expected_order = [
         group_element2.parent, group_element1.parent, group_element3.parent
     ]
     self.assertListEqual(result[learn_unit_year.id], expected_order)
示例#24
0
def publish(education_group_year):
    if not all([
            settings.ESB_API_URL, settings.ESB_AUTHORIZATION,
            settings.ESB_REFRESH_PEDAGOGY_ENDPOINT,
            settings.ESB_REFRESH_COMMON_PEDAGOGY_ENDPOINT,
            settings.ESB_REFRESH_COMMON_ADMISSION_ENDPOINT
    ]):
        raise ImproperlyConfigured(
            'ESB_API_URL / ESB_AUTHORIZATION / ESB_REFRESH_PEDAGOGY_ENDPOINT / '
            'ESB_REFRESH_COMMON_PEDAGOGY_ENDPOINT /  '
            'ESB_REFRESH_COMMON_ADMISSION_ENDPOINT must be set in configuration'
        )

    trainings = find_learning_unit_roots([education_group_year],
                                         return_result_params={
                                             'parents_as_instances': True
                                         }).get(education_group_year.pk, [])

    education_groups_to_publish = [education_group_year] + trainings \
        if education_group_year.education_group_type.name != GroupType.COMMON_CORE.name \
        else trainings
    t = Thread(target=_bulk_publish, args=(education_groups_to_publish, ))
    t.start()
    return True
示例#25
0
 def test_objects_instances_check_is_called(self, mock_check_instance):
     group_element_year.find_learning_unit_roots([self.child_leaf])
     self.assertTrue(mock_check_instance.called)
示例#26
0
 def test_case_filters_arg_is_none(self):
     result = group_element_year.find_learning_unit_roots([self.child_leaf])
     expected_result = {self.child_leaf.id: []}
     self.assertDictEqual(result, expected_result)
示例#27
0
 def test_case_arg_is_none(self):
     result = group_element_year.find_learning_unit_roots(None)
     self.assertEqual(result, {})