def test_count_learning_unit_enrollments(self): LearningUnitEnrollmentFactory( offer_enrollment=OfferEnrollmentFactory( education_group_year=self.education_group_year), learning_unit_year=self.learning_unit_year) result = find_with_enrollments_count(self.learning_unit_year) self.assertEqual(result[0].count_learning_unit_enrollments, 1)
def test_ordered_by_acronym(self): group_1 = GroupElementYearFactory( parent=EducationGroupYearFactory(acronym='XDRT1234'), child_branch=None, child_leaf=self.learning_unit_year) group_2 = GroupElementYearFactory( parent=EducationGroupYearFactory(acronym='BMED1000'), child_branch=None, child_leaf=self.learning_unit_year) group_3 = GroupElementYearFactory( parent=EducationGroupYearFactory(acronym='LDROI1001'), child_branch=None, child_leaf=self.learning_unit_year) LearningUnitEnrollmentFactory( learning_unit_year=self.learning_unit_year, offer_enrollment__education_group_year=group_1.parent) LearningUnitEnrollmentFactory( learning_unit_year=self.learning_unit_year, offer_enrollment__education_group_year=group_2.parent) LearningUnitEnrollmentFactory( learning_unit_year=self.learning_unit_year, offer_enrollment__education_group_year=group_3.parent) result = find_with_enrollments_count(self.learning_unit_year) expected_list_order = [group_2.parent, group_3.parent, group_1.parent] self.assertEqual(list(result), expected_list_order)
def test_with_learning_unit_enrollment_and_with_offer_enrollments(self): enrol_not_in_education_group = LearningUnitEnrollmentFactory( learning_unit_year=LearningUnitYearFactory()) result = find_with_enrollments_count( enrol_not_in_education_group.learning_unit_year) self.assertEqual(result[0].count_learning_unit_enrollments, 1) self.assertEqual(result[0].count_formation_enrollments, 1)
def learning_unit_formations(request, learning_unit_year_id): context = get_common_context_learning_unit_year(learning_unit_year_id, get_object_or_404(Person, user=request.user)) learn_unit_year = context["learning_unit_year"] group_elements_years = learn_unit_year.child_leaf.select_related( "parent", "child_leaf", "parent__education_group_type" ).order_by('parent__partial_acronym') education_groups_years = [group_element_year.parent for group_element_year in group_elements_years] formations_by_educ_group_year = mdl.group_element_year.find_learning_unit_roots( education_groups_years, return_result_params={ 'parents_as_instances': True, 'with_parents_of_parents': True }, luy=learn_unit_year ) context['formations_by_educ_group_year'] = formations_by_educ_group_year context['group_elements_years'] = group_elements_years context['root_formations'] = education_group_year.find_with_enrollments_count(learn_unit_year) context['total_formation_enrollments'] = 0 context['total_learning_unit_enrollments'] = 0 for root_formation in context['root_formations']: context['total_formation_enrollments'] += root_formation.count_formation_enrollments context['total_learning_unit_enrollments'] += root_formation.count_learning_unit_enrollments context['tab_active'] = "learning_unit_formations" # Corresponds to url_name return render(request, "learning_unit/formations.html", context)
def test_count_formation_enrollments_with_pending_enrollment(self): luy = LearningUnitYearFactory() edy = EducationGroupYearFactory() for k in dict(offer_enrollment_state.STATES): LearningUnitEnrollmentFactory( learning_unit_year=luy, offer_enrollment=OfferEnrollmentFactory( enrollment_state=k, education_group_year=edy), ) result = find_with_enrollments_count(luy) self.assertEqual(result[0].count_learning_unit_enrollments, 5) self.assertEqual(result[0].count_formation_enrollments, 2)
def learning_unit_formations(request, learning_unit_year_id): context = get_common_context_learning_unit_year(learning_unit_year_id, get_object_or_404(Person, user=request.user)) learn_unit_year = context["learning_unit_year"] group_elements_years = learn_unit_year.child_leaf.select_related( "parent", "child_leaf", "parent__education_group_type" ).order_by('parent__partial_acronym') education_groups_years = [group_element_year.parent for group_element_year in group_elements_years] formations_by_educ_group_year = mdl.group_element_year.find_learning_unit_formations( education_groups_years, parents_as_instances=True, with_parents_of_parents=True ) context['formations_by_educ_group_year'] = formations_by_educ_group_year context['group_elements_years'] = group_elements_years context['root_formations'] = education_group_year.find_with_enrollments_count(learn_unit_year) return render(request, "learning_unit/formations.html", context)
def test_without_learning_unit_enrollment_but_with_offer_enrollments(self): OfferEnrollmentFactory(education_group_year=self.education_group_year) result = find_with_enrollments_count(self.learning_unit_year) self.assertEqual(list(result), [])