Ejemplo n.º 1
0
 def _load_one_student_session_exam_deadline(self):
     off_enrol = OfferEnrollmentFactory(
         offer_year=self.offer_year_calendar_deliberation.offer_year)
     self.sess_exam_dealine = SessionExamDeadlineFactory(
         offer_enrollment=off_enrol,
         deliberation_date=None,
         deadline=scores_encodings_deadline._one_day_before(
             self.academic_calendar_deliberation.end_date),
         deadline_tutor=0,
         number_session=self.nb_session)
Ejemplo n.º 2
0
class SessionExamDeadlineTest(TestCase):
    def setUp(self):
        self.sess_exam_deadline = SessionExamDeadlineFactory()

    def test_compute_deadline_is_called_case_changing_student_deliberation_date(
            self):
        with mock.patch.object(compute_student_score_encoding_deadline,
                               'send') as mock_method:
            self.sess_exam_deadline.deadline_tutor = 5  # Changing a different field from deliberation_date
            self.sess_exam_deadline.save()
            self.assertTrue(not mock_method.called)

            self.sess_exam_deadline.deliberation_date = datetime.datetime.now()
            self.sess_exam_deadline.save()
            self.assertTrue(mock_method.called)
Ejemplo n.º 3
0
    def test_case_mutliple_students_offer_enrollments(self):
        students = [StudentFactory() for _ in range(10)]
        offer_enrollments = [
            OfferEnrollmentFactory(
                student=student,
                offer_year=self.offer_year_calendar_deliberation.offer_year)
            for student in students
        ]

        session_exam_deadlines = [
            SessionExamDeadlineFactory(
                offer_enrollment=offer_enrollment,
                number_session=self.nb_session,
                deliberation_date=self.offer_year_calendar_deliberation.
                end_date,
                deadline=scores_encodings_deadline._one_day_before(
                    self.offer_year_calendar_deliberation.end_date),
                deadline_tutor=0) for offer_enrollment in offer_enrollments
        ]

        new_global_submission_date = self.offer_year_calendar_deliberation.end_date - timedelta(
            days=20)
        self.offer_year_calendar_deliberation.end_date = new_global_submission_date
        self.offer_year_calendar_deliberation.save()
        persistent_session_exams = SessionExamDeadline.objects.filter(
            pk__in=[obj.id for obj in session_exam_deadlines])
        for obj in persistent_session_exams:
            self._assert_date_equal(
                obj.deadline,
                scores_encodings_deadline._one_day_before(
                    new_global_submission_date))
 def test_is_deadline_tutor_not_set_reached(self):
     self.exam_enrollment.save()
     SessionExamDeadlineFactory(deadline=datetime.date.today() - datetime.timedelta(days=1),
                                deadline_tutor=None,
                                number_session=self.session_exam.number_session,
                                offer_enrollment=self.offer_enrollment)
     self.assertTrue(exam_enrollment.is_deadline_tutor_reached(self.exam_enrollment))
Ejemplo n.º 5
0
 def test_is_deadline_not_reached(self):
     self.exam_enrollment.save()
     SessionExamDeadlineFactory(
         deadline=datetime.date.today() + datetime.timedelta(days=2),
         number_session=self.session_exam.number_session,
         offer_enrollment=self.offer_enrollment)
     self.assertFalse(
         exam_enrollment.is_deadline_reached(self.exam_enrollment))
 def setUp(self):
     self.offer_year_calendar_deliberation = OfferYearCalendarFactory(
         academic_calendar=self.academic_calendar_deliberation,
         offer_year=self.off_year,
         start_date=self.academic_calendar_deliberation.start_date,
         end_date=self.academic_calendar_deliberation.end_date,
         education_group_year=self.education_group_year
     )
     off_enrol = OfferEnrollmentFactory(offer_year=self.offer_year_calendar_deliberation.offer_year)
     self.sess_exam_dealine = SessionExamDeadlineFactory(offer_enrollment=off_enrol, deliberation_date=None,
                                                         deadline=scores_encodings_deadline._one_day_before(
                                                             self.academic_calendar_deliberation.end_date),
                                                         deadline_tutor=0,
                                                         number_session=self.nb_session)
     self.ac_score_exam_submission = AcademicCalendarFactory(
         academic_year=self.academic_year,
         reference=academic_calendar_type.SCORES_EXAM_SUBMISSION,
         start_date=self.academic_year.start_date,
         end_date=self.academic_year.end_date,
     )
     SessionExamCalendarFactory(
         academic_calendar=self.ac_score_exam_submission,
         number_session=self.nb_session
     )
Ejemplo n.º 7
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)
class ComputeScoresEncodingsDeadlinesTest(TestCase):

    def setUp(self):
        self.nb_session = number_session.ONE

        current_year = datetime.now().year
        current_date = datetime(year=current_year, month=9, day=1, hour=12)
        academic_year = AcademicYearFactory(year=current_year,
                                            start_date=current_date,
                                            end_date=current_date + timedelta(days=365))

        self.off_year = OfferYearFactory()
        self.education_group_year = EducationGroupYearFactory()

        self._load_initial_data_of_type_deliberation(academic_year)

        self._load_initial_data_of_type_scores_exam_submission(academic_year)

        self._load_one_student_session_exam_deadline()

    def _load_initial_data_of_type_deliberation(self, academic_year):
        self.academic_calendar_deliberation = AcademicCalendarFactory(
            academic_year=academic_year,
            reference=academic_calendar_type.DELIBERATION,
            start_date=academic_year.start_date,
            end_date=academic_year.end_date,
        )

        SessionExamCalendarFactory(
            academic_calendar=self.academic_calendar_deliberation,
            number_session=self.nb_session,
        )

        self.offer_year_calendar_deliberation = OfferYearCalendarFactory(
            academic_calendar=self.academic_calendar_deliberation,
            offer_year=self.off_year,
            start_date=self.academic_calendar_deliberation.start_date,
            end_date=self.academic_calendar_deliberation.end_date,
            education_group_year=self.education_group_year
        )

    def _load_initial_data_of_type_scores_exam_submission(self, academic_year):
        self.ac_score_exam_submission = AcademicCalendarFactory(
            academic_year=academic_year,
            reference=academic_calendar_type.SCORES_EXAM_SUBMISSION,
            start_date=academic_year.start_date,
            end_date=academic_year.end_date,
        )
        SessionExamCalendarFactory(
            academic_calendar=self.ac_score_exam_submission,
            number_session=self.nb_session
        )

    def _load_one_student_session_exam_deadline(self):
        off_enrol = OfferEnrollmentFactory(offer_year=self.offer_year_calendar_deliberation.offer_year)
        self.sess_exam_dealine = SessionExamDeadlineFactory(offer_enrollment=off_enrol, deliberation_date=None,
                                                            deadline=scores_encodings_deadline._one_day_before(self.academic_calendar_deliberation.end_date),
                                                            deadline_tutor=0,
                                                            number_session=self.nb_session)

    def _create_tutor_scores_submission_end_date(self, end_date):
        return OfferYearCalendarFactory(
            academic_calendar=self.ac_score_exam_submission,
            offer_year=self.off_year,
            start_date=self.academic_calendar_deliberation.start_date,
            end_date=end_date,
            education_group_year=self.education_group_year
        )

    def _get_persistent_session_exam_deadline(self):
        return SessionExamDeadline.objects.get(pk=self.sess_exam_dealine.id)

    def _change_student_deliberation_date(self, new_end_date):
        self.sess_exam_dealine.deliberation_date = new_end_date
        self.sess_exam_dealine.save()

    def _assert_date_equal(self, date1, date2):
        self.assertEqual(scores_encodings_deadline._get_date_instance(date1),
                         scores_encodings_deadline._get_date_instance(date2))

    def test_compute_deadline_wrong_reference(self):
        self.offer_year_calendar_deliberation.academic_calendar.reference = academic_calendar_type.COURSE_ENROLLMENT
        old_deadline = self.sess_exam_dealine.deadline

        self.offer_year_calendar_deliberation.save()

        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline, old_deadline)

    def test_compute_deadline_tutor_by_offer_year(self):
        """
        In this test, we will check if the tutor day delta [deadline is correctly computed]
        """
        self.offer_year_calendar_deliberation.end_date = self.offer_year_calendar_deliberation.end_date + timedelta(
            days=10)
        self.offer_year_calendar_deliberation.save()

        correct_deadlines = [0 for _ in SessionExamDeadline.objects.all()]

        OfferYearCalendarFactory(
            academic_calendar=self.ac_score_exam_submission,
            education_group_year=self.offer_year_calendar_deliberation.education_group_year,
            offer_year=self.offer_year_calendar_deliberation.offer_year
        )

        new_deadlines_tutors = [i.deadline_tutor for i in SessionExamDeadline.objects.all()]
        self.assertListEqual(new_deadlines_tutors, correct_deadlines)

    def test_get_delta_deadline_tutor(self):
        today = datetime.today()
        fourty_day_before = today - timedelta(days=40)
        self.assertEqual(40, scores_encodings_deadline._compute_delta_deadline_tutor(today, fourty_day_before))

    def test_get_delta_deadline_tutor_none_value(self):
        today = datetime.today()
        self.assertFalse(scores_encodings_deadline._compute_delta_deadline_tutor(None, None))
        self.assertFalse(scores_encodings_deadline._compute_delta_deadline_tutor(None, today))
        self.assertFalse(scores_encodings_deadline._compute_delta_deadline_tutor(today, None))

    def test_case_only_global_scores_encoding_end_date_is_set(self):
        self.offer_year_calendar_deliberation.delete()
        OfferYearCalendarFactory(academic_calendar=self.ac_score_exam_submission, start_date=None, end_date=None, offer_year=self.off_year)
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline, self.ac_score_exam_submission.end_date)
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed, self.ac_score_exam_submission.end_date)

    def test_case_tutor_scores_submission_date_gt_student_deliberation_date(self):
        delibe_date = self.offer_year_calendar_deliberation.end_date - timedelta(days=10)
        self._change_student_deliberation_date(delibe_date)
        self._create_tutor_scores_submission_end_date(delibe_date + timedelta(days=5))
        self.assertEqual(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                         scores_encodings_deadline._one_day_before(delibe_date))

    def test_case_tutor_scores_submission_date_gt_offer_year_deliberation_date(self):
        offer_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        self._create_tutor_scores_submission_end_date(offer_year_delibe_date + timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                scores_encodings_deadline._one_day_before(self.offer_year_calendar_deliberation.end_date))

    def test_case_tutor_scores_submission_date_gt_scores_encodings_end_date(self):
        scores_encodings_end_date = self.ac_score_exam_submission.end_date
        self._create_tutor_scores_submission_end_date(scores_encodings_end_date + timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                scores_encodings_deadline._one_day_before(self.ac_score_exam_submission.end_date))

    def test_case_tutor_scores_submission_date_lt_student_deliberation_date(self):
        delibe_date = self.offer_year_calendar_deliberation.end_date - timedelta(days=10)
        self._change_student_deliberation_date(delibe_date)
        off_year_cal = self._create_tutor_scores_submission_end_date(delibe_date - timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                off_year_cal.end_date)

    def test_case_tutor_scores_submission_date_lt_offer_year_deliberation_date(self):
        off_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        off_year_cal = self._create_tutor_scores_submission_end_date(off_year_delibe_date - timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                off_year_cal.end_date)

    def test_case_tutor_scores_submission_date_lt_scores_encodings_end_date(self):
        scores_encodings_end_date = self.ac_score_exam_submission.end_date
        off_year_cal = self._create_tutor_scores_submission_end_date(scores_encodings_end_date - timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                off_year_cal.end_date)

    def test_case_student_deliberation_date_gt_offer_year_deliberation_date(self):
        offer_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        self._change_student_deliberation_date(offer_year_delibe_date + timedelta(days=5))
        before = scores_encodings_deadline._one_day_before(offer_year_delibe_date)
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline,
                                before)

    def test_case_student_deliberation_date_lt_offer_year_deliberation_date(self):
        offer_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        self._change_student_deliberation_date(offer_year_delibe_date - timedelta(days=5))
        self.assertEqual(self._get_persistent_session_exam_deadline().deadline,
                         scores_encodings_deadline._one_day_before(self.sess_exam_dealine.deliberation_date))

    def test_case_global_submission_date_lt_student_and_offer_year_delibe_date(self):
        offer_year_delibe_end_date = self.offer_year_calendar_deliberation.end_date
        self._create_tutor_scores_submission_end_date(offer_year_delibe_end_date)
        global_submission_end_date = offer_year_delibe_end_date - timedelta(days=20)
        self.ac_score_exam_submission.end_date = global_submission_end_date
        self.ac_score_exam_submission.save()
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline, global_submission_end_date)

    def test_case_student_deliberation_date_lt_global_submission_date(self):
        new_student_delibe_date = self.ac_score_exam_submission.end_date - timedelta(days=5)
        self.sess_exam_dealine.deliberation_date = new_student_delibe_date
        self.sess_exam_dealine.save()
        self._assert_date_equal(self.sess_exam_dealine.deadline,
                                scores_encodings_deadline._one_day_before(new_student_delibe_date))

    def test_case_offer_year_deliberation_lt_global_submission_date(self):
        new_offer_year_delibe_date = self.ac_score_exam_submission.end_date - timedelta(days=5)
        self.offer_year_calendar_deliberation.end_date = new_offer_year_delibe_date
        self.offer_year_calendar_deliberation.save()
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline,
                                scores_encodings_deadline._one_day_before(new_offer_year_delibe_date))

    def test_case_mutliple_students_offer_enrollments(self):
        students = [StudentFactory() for _ in range(10)]
        offer_enrollments = [
            OfferEnrollmentFactory(student=student, offer_year=self.offer_year_calendar_deliberation.offer_year)
            for student in students
            ]

        session_exam_deadlines = [
            SessionExamDeadlineFactory(offer_enrollment=offer_enrollment, number_session=self.nb_session,
                                       deliberation_date=self.offer_year_calendar_deliberation.end_date,
                                       deadline=scores_encodings_deadline._one_day_before(self.offer_year_calendar_deliberation.end_date),
                                       deadline_tutor=0)
            for offer_enrollment in offer_enrollments
            ]

        new_global_submission_date = self.offer_year_calendar_deliberation.end_date - timedelta(days=20)
        self.offer_year_calendar_deliberation.end_date = new_global_submission_date
        self.offer_year_calendar_deliberation.save()
        persistent_session_exams = SessionExamDeadline.objects.filter(pk__in=[obj.id for obj in session_exam_deadlines])
        for obj in persistent_session_exams:
            self._assert_date_equal(obj.deadline, scores_encodings_deadline._one_day_before(new_global_submission_date))

    def test_get_oyc_by_reference_when_education_group_year_is_null(self):
        ac_cal = AcademicCalendarFactory(reference=academic_calendar_type.DELIBERATION)
        SessionExamCalendarFactory(academic_calendar=ac_cal)
        OfferYearCalendarFactory(academic_calendar=ac_cal, education_group_year=None)
        off_year_cal_expected = OfferYearCalendarFactory(academic_calendar=ac_cal, education_group_year=None)
        oyc = scores_encodings_deadline._get_oyc_by_reference(off_year_cal_expected,
                                                              academic_calendar_type.DELIBERATION)
        self.assertEqual(oyc, off_year_cal_expected)

    def test_get_oyc_by_reference_when_no_matching_result(self):
        ac_cal = AcademicCalendarFactory(reference=academic_calendar_type.DELIBERATION)
        SessionExamCalendarFactory(academic_calendar=ac_cal)
        off_year_cal = OfferYearCalendarFactory(academic_calendar=ac_cal)
        oyc = scores_encodings_deadline._get_oyc_by_reference(off_year_cal, academic_calendar_type.COURSE_ENROLLMENT)
        self.assertIsNone(oyc)

    @mock.patch("assessments.business.scores_encodings_deadline.compute_deadline")
    def test_recompute_all_deadlines_when_not_impact_scores_encodings_deadlines(self, mock_compute_deadline):
        OfferYearCalendarFactory(
            academic_calendar=AcademicCalendarFactory(reference=academic_calendar_type.DELIBERATION)
        )
        self.assertFalse(mock_compute_deadline.called)

    @mock.patch("assessments.business.scores_encodings_deadline.compute_deadline")
    def test_recompute_all_deadlines_when_not_impact_scores_encodings_deadlines(self, mock_compute_deadline):
        OfferYearCalendarFactory(
            academic_calendar=AcademicCalendarFactory(reference=academic_calendar_type.SCORES_EXAM_SUBMISSION)
        )
        self.assertTrue(mock_compute_deadline.called)
Ejemplo n.º 9
0
 def setUp(self):
     self.sess_exam_deadline = SessionExamDeadlineFactory()
 def _load_one_student_session_exam_deadline(self):
     off_enrol = OfferEnrollmentFactory(offer_year=self.offer_year_calendar_deliberation.offer_year)
     self.sess_exam_dealine = SessionExamDeadlineFactory(offer_enrollment=off_enrol, deliberation_date=None,
                                                         deadline=scores_encodings_deadline._one_day_before(self.academic_calendar_deliberation.end_date),
                                                         deadline_tutor=0,
                                                         number_session=self.nb_session)
class ComputeScoresEncodingsDeadlinesTest(TestCase):

    def setUp(self):
        self.nb_session = number_session.ONE

        current_year = datetime.now().year
        current_date = datetime(year=current_year, month=9, day=1, hour=12)
        academic_year = AcademicYearFactory(year=current_year,
                                            start_date=current_date,
                                            end_date=current_date + timedelta(days=365))

        self.off_year = OfferYearFactory()
        self.education_group_year = EducationGroupYearFactory()

        self._load_initial_data_of_type_deliberation(academic_year)

        self._load_initial_data_of_type_scores_exam_submission(academic_year)

        self._load_one_student_session_exam_deadline()

    def _load_initial_data_of_type_deliberation(self, academic_year):
        self.academic_calendar_deliberation = AcademicCalendarFactory(
            academic_year=academic_year,
            reference=academic_calendar_type.DELIBERATION,
            start_date=academic_year.start_date,
            end_date=academic_year.end_date,
        )

        SessionExamCalendarFactory(
            academic_calendar=self.academic_calendar_deliberation,
            number_session=self.nb_session,
        )

        self.offer_year_calendar_deliberation = OfferYearCalendarFactory(
            academic_calendar=self.academic_calendar_deliberation,
            offer_year=self.off_year,
            start_date=self.academic_calendar_deliberation.start_date,
            end_date=self.academic_calendar_deliberation.end_date,
            education_group_year=self.education_group_year
        )

    def _load_initial_data_of_type_scores_exam_submission(self, academic_year):
        self.ac_score_exam_submission = AcademicCalendarFactory(
            academic_year=academic_year,
            reference=academic_calendar_type.SCORES_EXAM_SUBMISSION,
            start_date=academic_year.start_date,
            end_date=academic_year.end_date,
        )
        SessionExamCalendarFactory(
            academic_calendar=self.ac_score_exam_submission,
            number_session=self.nb_session
        )

    def _load_one_student_session_exam_deadline(self):
        off_enrol = OfferEnrollmentFactory(offer_year=self.offer_year_calendar_deliberation.offer_year)
        self.sess_exam_dealine = SessionExamDeadlineFactory(offer_enrollment=off_enrol, deliberation_date=None,
                                                            deadline=scores_encodings_deadline._one_day_before(self.academic_calendar_deliberation.end_date),
                                                            deadline_tutor=0,
                                                            number_session=self.nb_session)

    def _create_tutor_scores_submission_end_date(self, end_date):
        return OfferYearCalendarFactory(
            academic_calendar=self.ac_score_exam_submission,
            offer_year=self.off_year,
            start_date=self.academic_calendar_deliberation.start_date,
            end_date=end_date,
            education_group_year=self.education_group_year
        )

    def _get_persistent_session_exam_deadline(self):
        return SessionExamDeadline.objects.get(pk=self.sess_exam_dealine.id)

    def _change_student_deliberation_date(self, new_end_date):
        self.sess_exam_dealine.deliberation_date = new_end_date
        self.sess_exam_dealine.save()

    def _assert_date_equal(self, date1, date2):
        self.assertEqual(scores_encodings_deadline._get_date_instance(date1),
                         scores_encodings_deadline._get_date_instance(date2))

    def test_compute_deadline_wrong_reference(self):
        self.offer_year_calendar_deliberation.academic_calendar.reference = academic_calendar_type.COURSE_ENROLLMENT
        old_deadline = self.sess_exam_dealine.deadline

        self.offer_year_calendar_deliberation.save()

        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline, old_deadline)

    def test_compute_deadline_tutor_by_offer_year(self):
        """
        In this test, we will check if the tutor day delta [deadline is correctly computed]
        """
        self.offer_year_calendar_deliberation.end_date = self.offer_year_calendar_deliberation.end_date + timedelta(
            days=10)
        self.offer_year_calendar_deliberation.save()

        correct_deadlines = [0 for _ in SessionExamDeadline.objects.all()]

        OfferYearCalendarFactory(
            academic_calendar=self.ac_score_exam_submission,
            education_group_year=self.offer_year_calendar_deliberation.education_group_year,
            offer_year=self.offer_year_calendar_deliberation.offer_year
        )

        new_deadlines_tutors = [i.deadline_tutor for i in SessionExamDeadline.objects.all()]
        self.assertListEqual(new_deadlines_tutors, correct_deadlines)

    def test_get_delta_deadline_tutor(self):
        today = datetime.today()
        fourty_day_before = today - timedelta(days=40)
        self.assertEqual(40, scores_encodings_deadline._compute_delta_deadline_tutor(today, fourty_day_before))

    def test_get_delta_deadline_tutor_none_value(self):
        today = datetime.today()
        self.assertFalse(scores_encodings_deadline._compute_delta_deadline_tutor(None, None))
        self.assertFalse(scores_encodings_deadline._compute_delta_deadline_tutor(None, today))
        self.assertFalse(scores_encodings_deadline._compute_delta_deadline_tutor(today, None))

    def test_case_only_global_scores_encoding_end_date_is_set(self):
        self.offer_year_calendar_deliberation.delete()
        OfferYearCalendarFactory(academic_calendar=self.ac_score_exam_submission, start_date=None, end_date=None, offer_year=self.off_year)
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline, self.ac_score_exam_submission.end_date)
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed, self.ac_score_exam_submission.end_date)

    def test_case_tutor_scores_submission_date_gt_student_deliberation_date(self):
        delibe_date = self.offer_year_calendar_deliberation.end_date - timedelta(days=10)
        self._change_student_deliberation_date(delibe_date)
        self._create_tutor_scores_submission_end_date(delibe_date + timedelta(days=5))
        self.assertEqual(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                         scores_encodings_deadline._one_day_before(delibe_date))

    def test_case_tutor_scores_submission_date_gt_offer_year_deliberation_date(self):
        offer_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        self._create_tutor_scores_submission_end_date(offer_year_delibe_date + timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                scores_encodings_deadline._one_day_before(self.offer_year_calendar_deliberation.end_date))

    def test_case_tutor_scores_submission_date_gt_scores_encodings_end_date(self):
        scores_encodings_end_date = self.ac_score_exam_submission.end_date
        self._create_tutor_scores_submission_end_date(scores_encodings_end_date + timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                scores_encodings_deadline._one_day_before(self.ac_score_exam_submission.end_date))

    def test_case_tutor_scores_submission_date_lt_student_deliberation_date(self):
        delibe_date = self.offer_year_calendar_deliberation.end_date - timedelta(days=10)
        self._change_student_deliberation_date(delibe_date)
        off_year_cal = self._create_tutor_scores_submission_end_date(delibe_date - timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                off_year_cal.end_date)

    def test_case_tutor_scores_submission_date_lt_offer_year_deliberation_date(self):
        off_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        off_year_cal = self._create_tutor_scores_submission_end_date(off_year_delibe_date - timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                off_year_cal.end_date)

    def test_case_tutor_scores_submission_date_lt_scores_encodings_end_date(self):
        scores_encodings_end_date = self.ac_score_exam_submission.end_date
        off_year_cal = self._create_tutor_scores_submission_end_date(scores_encodings_end_date - timedelta(days=5))
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline_tutor_computed,
                                off_year_cal.end_date)

    def test_case_student_deliberation_date_gt_offer_year_deliberation_date(self):
        offer_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        self._change_student_deliberation_date(offer_year_delibe_date + timedelta(days=5))
        before = scores_encodings_deadline._one_day_before(offer_year_delibe_date)
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline,
                                before)

    def test_case_student_deliberation_date_lt_offer_year_deliberation_date(self):
        offer_year_delibe_date = self.offer_year_calendar_deliberation.end_date
        self._change_student_deliberation_date(offer_year_delibe_date - timedelta(days=5))
        self.assertEqual(self._get_persistent_session_exam_deadline().deadline,
                         scores_encodings_deadline._one_day_before(self.sess_exam_dealine.deliberation_date))

    def test_case_global_submission_date_lt_student_and_offer_year_delibe_date(self):
        offer_year_delibe_end_date = self.offer_year_calendar_deliberation.end_date
        self._create_tutor_scores_submission_end_date(offer_year_delibe_end_date)
        global_submission_end_date = offer_year_delibe_end_date - timedelta(days=20)
        self.ac_score_exam_submission.end_date = global_submission_end_date
        self.ac_score_exam_submission.save()
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline, global_submission_end_date)

    def test_case_student_deliberation_date_lt_global_submission_date(self):
        new_student_delibe_date = self.ac_score_exam_submission.end_date - timedelta(days=5)
        self.sess_exam_dealine.deliberation_date = new_student_delibe_date
        self.sess_exam_dealine.save()
        self._assert_date_equal(self.sess_exam_dealine.deadline,
                                scores_encodings_deadline._one_day_before(new_student_delibe_date))

    def test_case_offer_year_deliberation_lt_global_submission_date(self):
        new_offer_year_delibe_date = self.ac_score_exam_submission.end_date - timedelta(days=5)
        self.offer_year_calendar_deliberation.end_date = new_offer_year_delibe_date
        self.offer_year_calendar_deliberation.save()
        self._assert_date_equal(self._get_persistent_session_exam_deadline().deadline,
                                scores_encodings_deadline._one_day_before(new_offer_year_delibe_date))

    def test_case_mutliple_students_offer_enrollments(self):
        students = [StudentFactory() for _ in range(10)]
        offer_enrollments = [
            OfferEnrollmentFactory(student=student, offer_year=self.offer_year_calendar_deliberation.offer_year)
            for student in students
            ]

        session_exam_deadlines = [
            SessionExamDeadlineFactory(offer_enrollment=offer_enrollment, number_session=self.nb_session,
                                       deliberation_date=self.offer_year_calendar_deliberation.end_date,
                                       deadline=scores_encodings_deadline._one_day_before(self.offer_year_calendar_deliberation.end_date),
                                       deadline_tutor=0)
            for offer_enrollment in offer_enrollments
            ]

        new_global_submission_date = self.offer_year_calendar_deliberation.end_date - timedelta(days=20)
        self.offer_year_calendar_deliberation.end_date = new_global_submission_date
        self.offer_year_calendar_deliberation.save()
        persistent_session_exams = SessionExamDeadline.objects.filter(pk__in=[obj.id for obj in session_exam_deadlines])
        for obj in persistent_session_exams:
            self._assert_date_equal(obj.deadline, scores_encodings_deadline._one_day_before(new_global_submission_date))

    def test_get_oyc_by_reference_when_education_group_year_is_null(self):
        ac_cal = AcademicCalendarFactory(reference=academic_calendar_type.DELIBERATION)
        SessionExamCalendarFactory(academic_calendar=ac_cal)
        OfferYearCalendarFactory(academic_calendar=ac_cal, education_group_year=None)
        off_year_cal_expected = OfferYearCalendarFactory(academic_calendar=ac_cal, education_group_year=None)
        oyc = scores_encodings_deadline._get_oyc_by_reference(off_year_cal_expected,
                                                              academic_calendar_type.DELIBERATION)
        self.assertEqual(oyc, off_year_cal_expected)

    def test_get_oyc_by_reference_when_no_matching_result(self):
        ac_cal = AcademicCalendarFactory(reference=academic_calendar_type.DELIBERATION)
        SessionExamCalendarFactory(academic_calendar=ac_cal)
        off_year_cal = OfferYearCalendarFactory(academic_calendar=ac_cal)
        oyc = scores_encodings_deadline._get_oyc_by_reference(off_year_cal, academic_calendar_type.COURSE_ENROLLMENT)
        self.assertIsNone(oyc)

    @mock.patch("assessments.business.scores_encodings_deadline.compute_deadline")
    def test_recompute_all_deadlines_when_not_impact_scores_encodings_deadlines(self, mock_compute_deadline):
        OfferYearCalendarFactory(
            academic_calendar=AcademicCalendarFactory(reference=academic_calendar_type.DELIBERATION)
        )
        self.assertFalse(mock_compute_deadline.called)

    @mock.patch("assessments.business.scores_encodings_deadline.compute_deadline")
    def test_recompute_all_deadlines_when_not_impact_scores_encodings_deadlines(self, mock_compute_deadline):
        OfferYearCalendarFactory(
            academic_calendar=AcademicCalendarFactory(reference=academic_calendar_type.SCORES_EXAM_SUBMISSION)
        )
        self.assertTrue(mock_compute_deadline.called)
Ejemplo n.º 12
0
 def setUpTestData(cls):
     cls.sess_exam_deadline = SessionExamDeadlineFactory()