예제 #1
0
    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)
예제 #2
0
    def test_check_learning_unit_year_deletion(self):
        l_container_year = LearningContainerYearFactory(
            acronym="LBIR1212", academic_year=self.academic_year)
        l_unit_1 = LearningUnitYearFactory(
            acronym="LBIR1212",
            learning_container_year=l_container_year,
            academic_year=self.academic_year,
            subtype=learning_unit_year_subtypes.FULL)
        msg = deletion.check_learning_unit_year_deletion(l_unit_1)

        msg = list(msg.values())
        self.assertEqual(msg, [])

        l_unit_2 = LearningUnitYearFactory(
            acronym="LBIR1212A",
            learning_container_year=l_container_year,
            academic_year=self.academic_year,
            subtype=learning_unit_year_subtypes.PARTIM)
        LearningUnitYearFactory(acronym="LBIR1212B",
                                learning_container_year=l_container_year,
                                academic_year=self.academic_year,
                                subtype=learning_unit_year_subtypes.PARTIM)

        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_1)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)

        msg = deletion.check_learning_unit_year_deletion(l_unit_1)

        msg = list(msg.values())
        self.assertEqual(len(msg), 2)
예제 #3
0
    def setUp(self):
        today = datetime.datetime.today()
        twenty_days = datetime.timedelta(days=20)

        #Take same academic year as the one in the associated xls file
        an_academic_year = AcademicYearFactory(year=2017)

        a_learning_unit_year = LearningUnitYearFakerFactory(
            academic_year=an_academic_year, acronym=LEARNING_UNIT_ACRONYM)

        tutor = TutorFactory()

        an_academic_calendar = AcademicCalendarFactory(
            academic_year=an_academic_year,
            start_date=today - twenty_days,
            end_date=today + twenty_days,
            reference=academic_calendar_type.SCORES_EXAM_SUBMISSION)
        SessionExamCalendarFactory(number_session=number_session.ONE,
                                   academic_calendar=an_academic_calendar)
        AttributionFactory(learning_unit_year=a_learning_unit_year,
                           tutor=tutor)
        a_session_exam = SessionExamFactory(
            number_session=number_session.ONE,
            learning_unit_year=a_learning_unit_year)

        self.person_student_1 = PersonFactory(email=EMAIL_1)
        person_student_2 = PersonFactory(email=EMAIL_2)

        student_1 = StudentFactory(registration_id=REGISTRATION_ID_1,
                                   person=self.person_student_1)
        student_2 = StudentFactory(registration_id=REGISTRATION_ID_2,
                                   person=person_student_2)

        an_offer_year = OfferYearFactory(academic_year=an_academic_year,
                                         acronym=OFFER_ACRONYM)
        offer_enrollment_1 = OfferEnrollmentFactory(offer_year=an_offer_year,
                                                    student=student_1)
        offer_enrollment_2 = OfferEnrollmentFactory(offer_year=an_offer_year,
                                                    student=student_2)

        learning_unit_enrollment_1 = LearningUnitEnrollmentFactory(
            learning_unit_year=a_learning_unit_year,
            offer_enrollment=offer_enrollment_1)
        learning_unit_enrollment_2 = LearningUnitEnrollmentFactory(
            learning_unit_year=a_learning_unit_year,
            offer_enrollment=offer_enrollment_2)

        ExamEnrollmentFactory(
            session_exam=a_session_exam,
            learning_unit_enrollment=learning_unit_enrollment_1)
        ExamEnrollmentFactory(
            session_exam=a_session_exam,
            learning_unit_enrollment=learning_unit_enrollment_2)

        user = tutor.person.user
        self.client = Client()
        self.client.force_login(user=user)
        self.url = reverse(
            'upload_encoding',
            kwargs={'learning_unit_year_id': a_learning_unit_year.id})
예제 #4
0
 def setUp(self):
     academic_year = AcademicYearFactory(year=datetime.datetime.now().year)
     offer_year = OfferYearFactory(academic_year=academic_year)
     student_1 = StudentFactory(person=PersonFactory(last_name='Durant', first_name='Thomas'))
     student_2 = StudentFactory(person=PersonFactory(last_name='Dupont', first_name='Raph'))
     student_3 = StudentFactory(person=PersonFactory(last_name='Duclou', first_name='Paul'))
     offer_enrollement_1 = OfferEnrollmentFactory(offer_year=offer_year,student=student_1)
     offer_enrollement_2 = OfferEnrollmentFactory(offer_year=offer_year, student=student_2)
     offer_enrollement_3 = OfferEnrollmentFactory(offer_year=offer_year,student=student_3)
     self.l_unit_year = LearningUnitYearFactory(academic_year=academic_year)
     LearningUnitEnrollmentFactory(learning_unit_year=self.l_unit_year, offer_enrollment=offer_enrollement_1)
     LearningUnitEnrollmentFactory(learning_unit_year=self.l_unit_year, offer_enrollment=offer_enrollement_2)
     LearningUnitEnrollmentFactory(learning_unit_year=self.l_unit_year, offer_enrollment=offer_enrollement_3)
예제 #5
0
    def setUp(self):
        self.academic_year = AcademicYearFactory()
        self.offer_year = OfferYearFactory(academic_year=self.academic_year)
        self.learning_unit_year = LearningUnitYearFactory(
            academic_year=self.academic_year,
            acronym="LBIR1100",
            decimal_scores=False)
        # Create tutor and score responsible
        _create_attribution(self.learning_unit_year,
                            person=PersonFactory(last_name='Alibra',
                                                 first_name='Paul'))
        _create_attribution(self.learning_unit_year,
                            person=PersonFactory(last_name='Durant',
                                                 first_name='Thomas'),
                            is_score_responsible=True)
        _create_attribution(self.learning_unit_year,
                            person=PersonFactory(last_name='Lobradi',
                                                 first_name='Pierre'))
        self.session_exam = SessionExamFactory(
            number_session=1, learning_unit_year=self.learning_unit_year)
        # Create three students and enrol them to learning unit year
        self.student_1 = StudentFactory(
            person=PersonFactory(last_name='Dupont', first_name='Jacques'))
        offer_enrollment = OfferEnrollmentFactory(offer_year=self.offer_year,
                                                  student=self.student_1)
        l_unit_enrollment = LearningUnitEnrollmentFactory(
            offer_enrollment=offer_enrollment,
            learning_unit_year=self.learning_unit_year)
        ExamEnrollmentFactory(learning_unit_enrollment=l_unit_enrollment,
                              session_exam=self.session_exam)

        self.student_2 = StudentFactory(
            person=PersonFactory(last_name='Dupont', first_name='Axel'))
        offer_enrollment = OfferEnrollmentFactory(offer_year=self.offer_year,
                                                  student=self.student_2)
        l_unit_enrollment = LearningUnitEnrollmentFactory(
            offer_enrollment=offer_enrollment,
            learning_unit_year=self.learning_unit_year)
        ExamEnrollmentFactory(learning_unit_enrollment=l_unit_enrollment,
                              session_exam=self.session_exam)

        self.student_3 = StudentFactory(
            person=PersonFactory(last_name='Armand', first_name='Zoe'))
        offer_enrollment = OfferEnrollmentFactory(offer_year=self.offer_year,
                                                  student=self.student_3)
        l_unit_enrollment = LearningUnitEnrollmentFactory(
            offer_enrollment=offer_enrollment,
            learning_unit_year=self.learning_unit_year)
        ExamEnrollmentFactory(learning_unit_enrollment=l_unit_enrollment,
                              session_exam=self.session_exam)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
    def setUpTestData(cls):
        group = ProgramManagerGroupFactory()
        group.permissions.add(
            Permission.objects.get(codename='view_scoresresponsible'))
        group.permissions.add(
            Permission.objects.get(codename='change_scoresresponsible'))

        cls.academic_year = create_current_academic_year()

        # FIXME: Old structure model [To remove]
        cls.structure = structure.StructureFactory()

        entities_hierarchy = create_entities_hierarchy()
        cls.root_entity = entities_hierarchy.get('root_entity')

        cls.learning_unit_year = LearningUnitYearFactory(
            academic_year=cls.academic_year,
            acronym="LBIR1210",
            structure=cls.structure,
            learning_container_year__academic_year=cls.academic_year,
            learning_container_year__acronym="LBIR1210",
            learning_container_year__requirement_entity=cls.root_entity,
        )
        cls.education_group_year = EducationGroupYearFactory(
            academic_year=cls.academic_year,
            administration_entity=cls.root_entity)
        cls.program_manager = ProgramManagerFactory(
            education_group=cls.education_group_year.education_group)
        cls.program_manager.person.user.groups.add(group)
        offer_enrollment = OfferEnrollmentFactory(
            education_group_year=cls.education_group_year)
        LearningUnitEnrollmentFactory(
            offer_enrollment=offer_enrollment,
            learning_unit_year=cls.learning_unit_year)
예제 #9
0
 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)
예제 #10
0
    def test_with_attribution_students(self):
        today = datetime.datetime.today()
        an_academic_year = AcademicYearFactory(
            year=today.year,
            start_date=today - datetime.timedelta(days=5),
            end_date=today + datetime.timedelta(days=5))
        a_learning_unit_year = LearningUnitYearFactory(
            academic_year=an_academic_year)
        AttributionFactory(learning_unit_year=a_learning_unit_year,
                           tutor=self.tutor)
        offer_year = OfferYearFactory(academic_year=an_academic_year)

        # Create two enrollment to exam [Enrolled]
        off_enrollment = OfferEnrollmentFactory(offer_year=offer_year)
        LearningUnitEnrollmentFactory(learning_unit_year=a_learning_unit_year,
                                      offer_enrollment=off_enrollment)
        off_enrollment = OfferEnrollmentFactory(offer_year=offer_year)
        LearningUnitEnrollmentFactory(learning_unit_year=a_learning_unit_year,
                                      offer_enrollment=off_enrollment)
        # Create an enrollment to exam [NOT enrolled]
        off_enrollment = OfferEnrollmentFactory(offer_year=offer_year)
        LearningUnitEnrollmentFactory(learning_unit_year=a_learning_unit_year,
                                      offer_enrollment=off_enrollment,
                                      enrollment_state="")

        url = reverse('attribution_students',
                      kwargs={
                          'learning_unit_year_id': a_learning_unit_year.id,
                          'a_tutor': self.tutor.id
                      })
        response = self.client.get(url)
        self.assertEqual(response.status_code, OK)
        self.assertTemplateUsed(response, 'students_list.html')

        self.assertEqual(response.context['global_id'],
                         self.tutor.person.global_id)
        self.assertEqual(response.context['learning_unit_year'],
                         a_learning_unit_year)
        self.assertTrue(response.context['students'])
        self.assertEqual(len(response.context['students']), 2)
예제 #11
0
def generate_exam_enrollments(year, with_different_offer=False):
    number_enrollments = 2
    academic_year = AcademicYearFactory(year=year)

    an_academic_calendar = AcademicCalendarFactory(
        academic_year=academic_year,
        start_date=(datetime.datetime.today() -
                    datetime.timedelta(days=20)).date(),
        end_date=(datetime.datetime.today() +
                  datetime.timedelta(days=20)).date(),
        reference=academic_calendar_type.SCORES_EXAM_SUBMISSION)
    session_exam_calendar = SessionExamCalendarFactory(
        number_session=number_session.ONE,
        academic_calendar=an_academic_calendar)

    learning_unit_year = LearningUnitYearFakerFactory(
        academic_year=academic_year,
        learning_container_year__academic_year=academic_year,
        acronym=LEARNING_UNIT_ACRONYM)
    attribution = AttributionFactory(learning_unit_year=learning_unit_year)

    if with_different_offer:
        session_exams = [
            SessionExamFactory(number_session=number_session.ONE,
                               learning_unit_year=learning_unit_year,
                               offer_year__academic_year=academic_year)
            for _ in range(0, number_enrollments)
        ]
    else:
        session_exams = [
            SessionExamFactory(number_session=number_session.ONE,
                               learning_unit_year=learning_unit_year,
                               offer_year__academic_year=academic_year)
        ] * number_enrollments
    offer_years = [session_exam.offer_year for session_exam in session_exams]

    exam_enrollments = list()
    for i in range(0, number_enrollments):
        student = StudentFactory()
        offer_enrollment = OfferEnrollmentFactory(offer_year=offer_years[i],
                                                  student=student)
        learning_unit_enrollment = LearningUnitEnrollmentFactory(
            learning_unit_year=learning_unit_year,
            offer_enrollment=offer_enrollment)
        exam_enrollments.append(
            ExamEnrollmentFactory(
                session_exam=session_exams[i],
                learning_unit_enrollment=learning_unit_enrollment,
                enrollment_state=exam_enrollment_state.ENROLLED,
                date_enrollment=an_academic_calendar.start_date))
    return locals()
예제 #12
0
 def test_get_learning_unit_enrollments_list(self):
     luy_full = self.data[0]['learning_unit_year']
     luy_partim = test_learning_unit_year.create_learning_unit_year({
         'acronym':
         "{}A".format(ACRONYM),
         'specific_title':
         TITLE,
         'academic_year':
         self.data[0]['academic_year'],
         'weight':
         WEIGHT,
         'subtype':
         learning_unit_year_subtypes.PARTIM,
     })
     luy_partim.learning_container_year = luy_full.learning_container_year
     luy_partim.save()
     for i in range(5):
         LearningUnitEnrollmentFactory(learning_unit_year=luy_full)
         LearningUnitEnrollmentFactory(learning_unit_year=luy_partim)
     # The students of the partim don't have to be in the result list
     self.assertEqual(
         len(tutor_charge._get_learning_unit_yr_enrollments_list(luy_full)),
         5)
예제 #13
0
    def _build_enrollment(self, students, enrollment_state):
        for student in students:
            offer_enrollment = OfferEnrollmentFactory(offer_year=self.offer_year, student=student)

            SessionExamDeadlineFactory(offer_enrollment=offer_enrollment,
                                       number_session=self.session_exam.number_session,
                                       deadline=self.deadline,
                                       deadline_tutor=0)
            lu_enrollment = LearningUnitEnrollmentFactory(
                offer_enrollment=offer_enrollment,
                learning_unit_year=self.learning_unit_year
            )
            ExamEnrollmentFactory(learning_unit_enrollment=lu_enrollment,
                                  session_exam=self.session_exam,
                                  enrollment_state=enrollment_state)
예제 #14
0
    def test_delete_from_given_learning_unit_year_case_error_have_enrollment(
            self, mock_render):
        learning_unit_years = self.learning_unit_year_list
        ly1 = learning_unit_years[1]
        LearningUnitEnrollmentFactory(learning_unit_year=ly1)

        from base.views.learning_unit_deletion import delete_from_given_learning_unit_year

        request_factory = RequestFactory()

        request = request_factory.get(
            reverse(delete_from_given_learning_unit_year, args=[ly1.id]))
        request.user = self.user

        setattr(request, 'session', 'session')

        delete_from_given_learning_unit_year(request, ly1.id)

        self.assertTrue(mock_render.called)
        request, template, context = mock_render.call_args[0]

        msg = context.get('messages_deletion', [])
        self.assertEqual(
            _('cannot_delete_learning_unit_year') % {
                'learning_unit': ly1.acronym,
                'year': ly1.academic_year
            }, context['title'])

        subtype = _(
            'The partim'
        ) if ly1.subtype == learning_unit_year_subtypes.PARTIM else _(
            'The learning unit')
        self.assertIn(
            _("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s"
              ) % {
                  'subtype': subtype,
                  'acronym': ly1.acronym,
                  'year': ly1.academic_year,
                  'count': 1
              }, msg)

        self.assertIsNotNone(LearningUnitYear.objects.get(id=ly1.id))
예제 #15
0
    def test_delete_all_learning_units_year_case_error_have_enrollment(self):
        learning_unit_years = self.learning_unit_year_list
        ly1 = learning_unit_years[1]
        LearningUnitEnrollmentFactory(learning_unit_year=ly1)

        request_factory = RequestFactory()

        request = request_factory.post(
            reverse(delete_all_learning_units_year, args=[ly1.id]))
        request.user = self.user

        setattr(request, 'session', 'session')
        setattr(request, '_messages', FallbackStorage(request))

        response = delete_all_learning_units_year(request, ly1.id)

        # Get message from context
        msg = [m.message for m in get_messages(request)]
        msg_level = [m.level for m in get_messages(request)]
        self.assertEqual(len(msg), 1)
        self.assertIn(messages.ERROR, msg_level)

        # Check error message
        subtype = _('The partim') if ly1.is_partim() else _(
            'The learning unit')
        self.assertIn(
            _("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s"
              ) % {
                  'subtype': subtype,
                  'acronym': ly1.acronym,
                  'year': ly1.academic_year,
                  'count': 1
              }, msg)

        # Check that record is not deleted
        self.assertTrue(LearningUnitYear.objects.filter(pk=ly1.pk).exists())

        # Check redirection to identification
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.url,
            reverse('learning_unit', kwargs={'learning_unit_year_id': ly1.pk}))
예제 #16
0
    def test_check_related_partims_deletion(self):
        l_container_year = LearningContainerYearFactory()
        LearningUnitYearFactory(
            acronym="LBIR1212",
            learning_container_year=l_container_year,
            academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL,
            learning_unit=self.learning_unit)
        msg = deletion._check_related_partims_deletion(l_container_year)
        self.assertEqual(len(msg.values()), 0)

        l_unit_2 = LearningUnitYearFactory(acronym="LBIR1213", learning_container_year=l_container_year,
                                           academic_year=self.academic_year, subtype=learning_unit_year_subtypes.PARTIM)

        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)

        group_1 = GroupElementYearFactory(child_branch=None, child_leaf=l_unit_2)
        group_2 = GroupElementYearFactory(child_branch=None, child_leaf=l_unit_2)

        component = LearningComponentYearFactory(learning_unit_year=l_unit_2)

        attribution_1 = AttributionNewFactory(learning_container_year=l_unit_2.learning_container_year)
        attribution_2 = AttributionNewFactory(learning_container_year=l_unit_2.learning_container_year)

        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_1)
        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_1)
        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_2)

        msg = deletion._check_related_partims_deletion(l_container_year)
        msg = list(msg.values())

        self.assertEqual(len(msg), 5)
        self.assertIn(_("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s")
                      % {'subtype': _('The partim'),
                         'acronym': l_unit_2.acronym,
                         'year': l_unit_2.academic_year,
                         'count': 3},
                      msg)

        msg_delete_tutor = _("%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s")
        self.assertIn(msg_delete_tutor % {'subtype': _('The partim'),
                                          'acronym': l_unit_2.acronym,
                                          'year': l_unit_2.academic_year,
                                          'tutor': attribution_1.tutor},
                      msg)
        self.assertIn(msg_delete_tutor % {'subtype': _('The partim'),
                                          'acronym': l_unit_2.acronym,
                                          'year': l_unit_2.academic_year,
                                          'tutor': attribution_2.tutor},
                      msg)

        msg_delete_offer_type = _('%(subtype)s %(acronym)s is included in the group %(group)s for the year %(year)s')

        self.assertIn(msg_delete_offer_type
                      % {'subtype': _('The partim'),
                         'acronym': l_unit_2.acronym,
                         'group': group_1.parent.partial_acronym,
                         'year': l_unit_2.academic_year},
                      msg)
        self.assertIn(msg_delete_offer_type
                      % {'subtype': _('The partim'),
                         'acronym': l_unit_2.acronym,
                         'group': group_2.parent.partial_acronym,
                         'year': l_unit_2.academic_year},
                      msg)
예제 #17
0
def create_learning_unit_enrollment(learning_unit_year, offer_enrollment):
    return LearningUnitEnrollmentFactory(learning_unit_year=learning_unit_year,
                                         offer_enrollment=offer_enrollment)