def test_find_by_offer_year(self): tmp_student = StudentFactory() tmp_offer_year = OfferYearFactory() OfferEnrollmentFactory.create(offer_year=tmp_offer_year, student=tmp_student) db_student = list(student.find_by_offer_year([tmp_offer_year][0]))[0] self.assertIsNotNone(db_student) self.assertEqual(db_student, tmp_student)
def setUpTestData(cls): cls.manager = AdviserManagerFactory() a_person_teacher = PersonFactory(first_name='Pierre', last_name='Dupont') cls.teacher = AdviserTeacherFactory(person=a_person_teacher) a_person_student1 = PersonFactory(last_name="Durant", user=None) cls.student1 = StudentFactory(person=a_person_student1) a_person_student2 = PersonFactory(last_name="Robert", user=None) cls.student2 = StudentFactory(person=a_person_student2) cls.education_group1 = EducationGroupFactory() cls.current_academic_year = create_current_academic_year() cls.current_education_group_year = EducationGroupYearFactory( education_group=cls.education_group1, acronym="test_offer1", academic_year=cls.current_academic_year) cls.education_group2 = EducationGroupFactory() cls.education_group_year = EducationGroupYearFactory( education_group=cls.education_group2, academic_year=cls.current_academic_year) cls.academic_year2015 = AcademicYearFactory(year=2015) cls.education_group_year_2015 = EducationGroupYearFactory( acronym="test_offer1", education_group=cls.education_group1, academic_year=cls.academic_year2015) cls.offer_enrollment_curent_year = OfferEnrollmentFactory( student=cls.student1, education_group_year=cls.current_education_group_year, enrollment_state=offer_enrollment_state.SUBSCRIBED) cls.offer_enrollment2015 = OfferEnrollmentFactory( student=cls.student2, education_group_year=cls.education_group_year_2015, enrollment_state=offer_enrollment_state.SUBSCRIBED) cls.proposition_dissertation = PropositionDissertationFactory( author=cls.teacher, creator=a_person_teacher, title='Proposition de memoire') cls.dissertation_to_put_back_to_draft = DissertationFactory( author=cls.student1, education_group_year=cls.current_education_group_year, proposition_dissertation=cls.proposition_dissertation, status='DIR_SUBMIT', active=True, dissertation_role__adviser=cls.teacher, dissertation_role__status=dissertation_role_status.PROMOTEUR) cls.dissertation_test_count2015 = DissertationFactory( author=cls.student1, education_group_year=cls.education_group_year_2015, proposition_dissertation=cls.proposition_dissertation, status='COM_SUBMIT', active=True, dissertation_role__adviser=cls.teacher, dissertation_role__status=dissertation_role_status.PROMOTEUR) cls.dissertation_test_count2017 = DissertationFactory( author=cls.student2, education_group_year=cls.current_education_group_year, proposition_dissertation=cls.proposition_dissertation, status='COM_SUBMIT', active=True, dissertation_role__adviser=cls.teacher, dissertation_role__status=dissertation_role_status.PROMOTEUR)
def test_search(self): result = search(id=[ self.education_group_year_1.id, self.education_group_year_2.id ]) self.assertEqual(len(result), 2) result = search(education_group_type=self.education_group_year_2. education_group_type) self.assertEqual(result.first().education_group_type, self.education_group_year_2.education_group_type) result = search(education_group_type=[ self.education_group_type_training, self.education_group_type_minitraining ]) self.assertEqual(len(result), 4) OfferEnrollmentFactory( education_group_year=self.education_group_year_2, enrollment_state=offer_enrollment_state.SUBSCRIBED) OfferEnrollmentFactory( education_group_year=self.education_group_year_2, enrollment_state=offer_enrollment_state.PENDING) result = search(enrollment_states=[offer_enrollment_state.SUBSCRIBED]) self.assertEqual(len(result), 1)
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})
def test_get_student_programs(self): academic_year = AcademicYearFactory() off_year = OfferYearFactory(academic_year=academic_year) student = StudentFactory() OfferEnrollmentFactory(student=student, offer_year=off_year, enrollment_state=offer_enrollment_state.PROVISORY) OfferEnrollmentFactory(student=student, offer_year=off_year, enrollment_state=offer_enrollment_state.SUBSCRIBED) OfferEnrollmentFactory(student=student, offer_year=off_year, enrollment_state=None) enrollments = exam_enrollment._get_student_programs(student, academic_year) self.assertEqual(len(enrollments), 2)
def setUp(self): self.client = Client() self.academic_year = test_academic_year.create_academic_year() group = _create_group('students') group.permissions.add(Permission.objects.get(codename='is_student')) self.user = User.objects.create_user(username='******', email='jsmith@localhost', password='******') self.user2 = User.objects.create_user(username='******', email='jsmath@localhost', password='******') self.user_not_student = User.objects.create_user( username='******', email='pjashar@localhost', password='******') self.user.groups.add(group) self.user2.groups.add(group) self.person = test_person.create_person_with_user(self.user, first_name="James", last_name="Smith") self.person2 = test_person.create_person_with_user(self.user2, first_name="Jimmy", last_name="Smath") self.student = test_student.create_student_with_registration_person( "12345678", self.person) self.student2 = test_student.create_student_with_registration_person( "12457896", self.person2) offer_year_id = 1234 self.off_year = test_offer_year.create_offer_year_from_kwargs( **{ 'id': offer_year_id, 'acronym': 'SINF1BA', 'title': 'Bechelor in informatica', 'academic_year': self.academic_year }) self.url = "/exam_enrollment/{}/form/".format(offer_year_id) self.correct_exam_enrol_form = load_json_file( "exam_enrollment/tests/resources/exam_enrollment_form_example.json" ) self.current_academic_year = test_academic_year.create_academic_year_current( ) self.off_enrol = OfferEnrollmentFactory( student=self.student, offer_year=OfferYearFactory( academic_year=self.current_academic_year)) learn_unit_year = test_learning_unit_year.create_learning_unit_year({ 'acronym': 'LDROI1234', 'specific_title': 'Bachelor in law', 'academic_year': self.academic_year }) self.learn_unit_enrol = test_learning_unit_enrollment.create_learning_unit_enrollment( self.off_enrol, learn_unit_year)
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)
def test_find_by_offers_and_academic_year(self): tmp_student = StudentFactory() tmp_offer = OfferFactory() tmp_academic_year = AcademicYearFactory() tmp_offer_year = OfferYearFactory(offer=tmp_offer, academic_year=tmp_academic_year) OfferEnrollmentFactory.create(offer_year=tmp_offer_year, student=tmp_student) db_student = list( student.find_by_offers_and_academic_year([tmp_offer], tmp_academic_year))[0] self.assertIsNotNone(db_student) self.assertEqual(db_student, tmp_student)
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)
def test_get_protected_messages_with_protected_datas(self): # Insert multiple in future with protected datas all_edy = [] for ac_year in self.generated_ac_years.academic_years: edy = EducationGroupYearFactory( education_group=self.education_group_year.education_group, management_entity=self.entity, administration_entity=self.entity, academic_year=ac_year, ) # Protected data [Offer enrollment] OfferEnrollmentFactory(education_group_year=edy) all_edy.append(edy) protected_messages = shorten._get_protected_messages(all_edy) self.assertIsInstance(protected_messages, list) self.assertEqual(len(protected_messages), 10) # Ensure that the order of protected messages is by academic_year.year + Message expected count_enrollment = 1 msg_expected = [ ngettext_lazy( "%(count_enrollment)d student is enrolled in the offer.", "%(count_enrollment)d students are enrolled in the offer.", count_enrollment ) % {"count_enrollment": count_enrollment} ] for idx, ac_year in enumerate(self.generated_ac_years.academic_years): protected_message = protected_messages self.assertEqual(protected_message[idx]['education_group_year'].academic_year, ac_year) self.assertEqual(protected_message[idx]['messages'], msg_expected)
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)
def test_delete_get_with_protected_objects(self): # Create protected data OfferEnrollmentFactory(education_group_year=self.education_group_year1) GroupElementYearFactory(parent=self.education_group_year1, child_branch__academic_year=self.current_ac) GroupElementYearFactory(parent=self.education_group_year1, child_branch__academic_year=self.current_ac) count_enrollment = 1 msg_offer_enrollment = ngettext_lazy( "%(count_enrollment)d student is enrolled in the offer.", "%(count_enrollment)d students are enrolled in the offer.", count_enrollment) % { "count_enrollment": count_enrollment } msg_pgrm_content = _( "The content of the education group is not empty.") protected_messages = [{ 'education_group_year': self.education_group_year1, 'messages': [msg_offer_enrollment, msg_pgrm_content] }] response = self.client.get(self.url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context["protected_messages"], protected_messages) self.assertTemplateUsed(response, "education_group/protect_delete.html")
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 setUp(self): now = datetime.date.today() a_year = now.year self.education_group = EducationGroupFactory() self.education_group2 = EducationGroupFactory() self.education_group3 = EducationGroupFactory() self.academic_year = AcademicYearFactory(year=2015) self.academic_year2 = AcademicYearFactory(year=2017) self.curent_academic_year = AcademicYearFactory( year=a_year, start_date=datetime.datetime(a_year, now.month, 1), end_date=datetime.datetime(a_year + 1, now.month, 28)) self.education_group_year1 = EducationGroupYearFactory( education_group=self.education_group, academic_year=self.academic_year) self.education_group_year2 = EducationGroupYearFactory( education_group=self.education_group, academic_year=self.academic_year2) self.education_group_year_current = EducationGroupYearFactory( education_group=self.education_group2, academic_year=self.curent_academic_year) self.student = StudentFactory() self.OfferEnrollment = OfferEnrollmentFactory( student=self.student, education_group_year=self.education_group_year_current, date_enrollment=now)
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_find_by_offers_year(self): student1 = StudentFactory.create() offer_year1 = OfferYearFactory() OfferEnrollmentFactory(student=student1, offer_year=offer_year1) result = list(offer_enrollment.find_by_offers_years([offer_year1])) self.assertEqual(result[0].student, student1) self.assertEqual(result[0].offer_year, offer_year1) self.assertEqual(len(result), 1)
def test_with_learning_unit_enrollment_and_with_offer_enrollments(self): enrol_not_in_education_group = LearningUnitEnrollmentFactory( learning_unit_year=LearningUnitYearFactory(), offer_enrollment=OfferEnrollmentFactory( enrollment_state=offer_enrollment_state.SUBSCRIBED)) 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 _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 test_find_by_student(self): Group.objects.create(name='students') a_student = StudentFactory() an_offer_year = OfferYearFactory(offer=self.offer) OfferEnrollmentFactory(offer_year=an_offer_year, student=a_student, date_enrollment=datetime.datetime( an_offer_year.academic_year.year + 1, 2, 1)) self.assertListEqual(list(mdl_offer.find_by_student(a_student)), [self.offer])
def test_case_student_has_no_learning_unit_enrollment(self, mock_find): mock_find.return_value = None off_year_enrol = OfferEnrollmentFactory( student=self.student, offer_year=OfferYearFactory( academic_year=self.current_academic_year)) self.client.force_login(self.user) response = self.client.get(reverse('exam_enrollment_form', args=[off_year_enrol.offer_year.id ]), follow=True) self.assertRedirects(response, reverse('dashboard_home'))
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 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)
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()
def test_delete_get_with_protected_objects(self): protected_objects = { OfferEnrollmentFactory( education_group_year=self.education_group_year), GroupElementYearFactory(parent=self.education_group_year), GroupElementYearFactory(parent=self.education_group_year), } response = self.client.get(self.url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context["protected_objects"], protected_objects) self.assertTemplateUsed(response, "education_group/protect_delete.html")
def test_check_education_group_end_date_with_protected_data(self): edy = EducationGroupYearFactory( education_group=self.education_group_year.education_group, management_entity=self.entity, administration_entity=self.entity, academic_year=self.ac_year_in_future, ) # Protected data [Offer enrollment] OfferEnrollmentFactory(education_group_year=edy) with self.assertRaises(ValidationError): check_education_group_end_date( education_group=self.education_group_year.education_group, end_year=self.ac_year_in_future.year - 1)
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)
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 )
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), [])
class ExamEnrollmentFormTest(TestCase): def setUp(self): self.client = Client() self.academic_year = test_academic_year.create_academic_year() group = _create_group('students') group.permissions.add(Permission.objects.get(codename='is_student')) self.user = User.objects.create_user(username='******', email='jsmith@localhost', password='******') self.user2 = User.objects.create_user(username='******', email='jsmath@localhost', password='******') self.user_not_student = User.objects.create_user( username='******', email='pjashar@localhost', password='******') self.user.groups.add(group) self.user2.groups.add(group) self.person = test_person.create_person_with_user(self.user, first_name="James", last_name="Smith") self.person2 = test_person.create_person_with_user(self.user2, first_name="Jimmy", last_name="Smath") self.student = test_student.create_student_with_registration_person( "12345678", self.person) self.student2 = test_student.create_student_with_registration_person( "12457896", self.person2) offer_year_id = 1234 self.off_year = test_offer_year.create_offer_year_from_kwargs( **{ 'id': offer_year_id, 'acronym': 'SINF1BA', 'title': 'Bechelor in informatica', 'academic_year': self.academic_year }) self.url = "/exam_enrollment/{}/form/".format(offer_year_id) self.correct_exam_enrol_form = load_json_file( "exam_enrollment/tests/resources/exam_enrollment_form_example.json" ) self.current_academic_year = test_academic_year.create_academic_year_current( ) self.off_enrol = OfferEnrollmentFactory( student=self.student, offer_year=OfferYearFactory( academic_year=self.current_academic_year)) learn_unit_year = test_learning_unit_year.create_learning_unit_year({ 'acronym': 'LDROI1234', 'specific_title': 'Bachelor in law', 'academic_year': self.academic_year }) self.learn_unit_enrol = test_learning_unit_enrollment.create_learning_unit_enrollment( self.off_enrol, learn_unit_year) def test_json_form_content(self): form = self.correct_exam_enrol_form self.assertTrue(form.get('registration_id')) self.assertTrue(form.get('current_number_session')) exam_enrollments = form.get('exam_enrollments') self.assertTrue(exam_enrollments) random_exam_enrol_position = random.randrange(len(exam_enrollments)) random_exam_enrol = exam_enrollments[random_exam_enrol_position] self.assertTrue('credits' in random_exam_enrol.keys()) self.assertTrue('credited' in random_exam_enrol.keys()) self.assertTrue('enrolled_by_default' in random_exam_enrol.keys()) self.assertTrue('can_enrol_to_exam' in random_exam_enrol.keys()) self.assertTrue('session_1' in random_exam_enrol.keys() or 'session_2' in random_exam_enrol.keys() or 'session_3' in random_exam_enrol.keys()) self.assertTrue(random_exam_enrol.get('learning_unit_year')) @patch( 'base.models.learning_unit_enrollment.find_by_student_and_offer_year') @patch("exam_enrollment.views.exam_enrollment.ask_exam_enrollment_form") def test_exam_enrollment_form(self, fetch_json, mock_find_learn_unit_enrols): mock_find_learn_unit_enrols.return_value = [self.learn_unit_enrol] fetch_json.return_value = self.correct_exam_enrol_form self.client.force_login(self.user) response = self.client.get(self.url) self.assertEqual(response.status_code, HttpResponse.status_code) self.assertTemplateUsed(response, 'exam_enrollment_form.html') returned_data = response.context[-1] self.assertIn('exam_enrollments', returned_data) self.assertIn('student', returned_data) self.assertIn('current_number_session', returned_data) self.assertIn('academic_year', returned_data) self.assertIn('program', returned_data) @patch("exam_enrollment.views.exam_enrollment.ask_exam_enrollment_form") def test_outside_score_encoding_period(self, fetch_json): fetch_json.return_value = None self.client.force_login(self.user) response = self.client.get(self.url, follow=True) self.assertRedirects(response, reverse('dashboard_home')) def test_case_user_is_not_student(self): self.client.force_login(self.user_not_student) response = self.client.get(self.url, follow=True) self.assertTemplateUsed(response, 'access_denied.html') def test_get_programs_student_is_none(self): self.assertIsNone( exam_enrollment._get_student_programs(None, self.current_academic_year)) def test_get_one_program(self): self.client.force_login(self.user) self.assertEqual( exam_enrollment._get_student_programs( self.student, self.current_academic_year)[0], self.learn_unit_enrol.offer_enrollment.offer_year) def test_navigation_with_no_offer_in_current_academic_year(self): self.client.force_login(self.user2) an_url = reverse('exam_enrollment_form_direct') response = self.client.get(an_url, follow=True) self.assertRedirects(response, reverse('dashboard_home')) self.assertEqual('dashboard.html', response.templates[0].name) @patch('base.models.student.find_by_user') def test_choose_offer_no_student_for_current_user(self, mock_find_by_user): mock_find_by_user.return_value = None self.client.force_login(self.user) an_url = reverse('exam_enrollment_offer_choice') response = self.client.get(an_url, follow=True) self.assertRedirects(response, reverse('dashboard_home')) @patch('exam_enrollment.views.exam_enrollment._get_student_programs') def test_navigation_student_has_no_programs(self, mock_student_programs): mock_student_programs.return_value = None self.client.force_login(self.user) an_url = reverse('exam_enrollment_offer_choice') response = self.client.get(an_url, follow=True) self.assertRedirects(response, reverse('dashboard_home')) self.assertEqual('dashboard.html', response.templates[0].name) @patch('exam_enrollment.views.exam_enrollment._get_student_programs') @patch('exam_enrollment.views.exam_enrollment.ask_exam_enrollment_form') @patch('base.models.academic_year.current_academic_year') @patch('base.models.offer_year.find_by_id') def test_navigation_student_has_programs_but_returned_form_is_none( self, mock_find_by_id, mock_current_academic_year, mock_fetch_exam_form, mock_get_student_programs): mock_find_by_id.return_value = self.off_year mock_current_academic_year.return_value = None mock_get_student_programs.return_value = [self.off_year] mock_fetch_exam_form.return_value = None self.client.force_login(self.user) an_url = reverse('exam_enrollment_form', args=[self.off_year.id]) response = self.client.get(an_url, follow=True) self.assertTrue(mock_current_academic_year.called) self.assertRedirects(response, reverse('dashboard_home')) @patch("exam_enrollment.views.exam_enrollment.ask_exam_enrollment_form") def test_case_exam_enrollment_form_contains_error_message( self, mock_fetch_json): form = self.correct_exam_enrol_form form['error_message'] = "an_error_message_key" mock_fetch_json.return_value = form self.client.force_login(self.user) response = self.client.get(self.url, follow=True) self.assertRedirects(response, reverse('dashboard_home')) @patch( 'base.models.learning_unit_enrollment.find_by_student_and_offer_year') @patch('exam_enrollment.views.exam_enrollment._get_student_programs') @patch('exam_enrollment.views.exam_enrollment.ask_exam_enrollment_form') @patch('base.models.academic_year.current_academic_year') def test_navigation_student_has_programs_with_data( self, mock_current_academic_year, mock_fetch_exam_form, mock_get_student_programs, mock_find_learn_unit_enrols): mock_current_academic_year.return_value = None mock_get_student_programs.return_value = [self.off_year] mock_fetch_exam_form.return_value = { 'exam_enrollments': [], 'current_number_session': 0, } mock_find_learn_unit_enrols.return_value = [self.learn_unit_enrol] self.client.force_login(self.user) an_url = reverse('exam_enrollment_form', args=[self.off_year.id]) response = self.client.get(an_url, follow=True) self.assertTrue(mock_current_academic_year.called) self.assertEqual('exam_enrollment_form.html', response.templates[0].name) if hasattr(settings, 'QUEUES') and settings.QUEUES: @patch("osis_common.queue.queue_sender.send_message") def test_exam_enrollment_form_submission_message(self, send_message): warnings.warn( "The field named 'etat_to_inscr' is only used to call EPC services. It should be deleted when the exam " "enrollment business will be implemented in Osis (not in EPC anymore). " "The flag 'is_enrolled' should be sufficient for Osis.", DeprecationWarning) send_message.return_value = None self.client.force_login(self.user) post_data = { "chckbox_exam_enrol_sess1_LPHYS1234": "on", "etat_to_inscr_current_session_LPHYS1234": "I", "chckbox_exam_enrol_sess1_LBIO4567": "", "etat_to_inscr_current_session_LBIO4567": "None", "chckbox_exam_enrol_sess1_LDROI1111": None, "etat_to_inscr_current_session_LDROI1111": None, "current_number_session": 1, } response = self.client.post(self.url, post_data) result = exam_enrollment._exam_enrollment_form_submission_message( self.off_year, response.wsgi_request, self.student) self.assert_correct_data_structure(result) self.assert_none_etat_to_inscr_not_in_submitted_form( result.get('exam_enrollments')) def assert_correct_data_structure(self, result): exam_enrollment_expected = { "acronym": "LPHYS1234", "is_enrolled": True, "etat_to_inscr": "I" } expected_result = { "registration_id": self.student.registration_id, "offer_year_acronym": self.off_year.acronym, "year": self.off_year.academic_year.year, "exam_enrollments": [exam_enrollment_expected] } self.assertEqual(len(result), len(expected_result)) self.assertEqual(expected_result.get('registration_id'), result.get('registration_id')) self.assertEqual(expected_result.get('offer_year_acronym'), result.get('offer_year_acronym')) self.assertEqual(expected_result.get('year'), result.get('year')) exam_enrollments = result.get('exam_enrollments') self.assertEqual(len(exam_enrollments), 1) for exam_enrol in expected_result.get('exam_enrollments'): self.assertIn(exam_enrol, exam_enrollments) def assert_none_etat_to_inscr_not_in_submitted_form( self, exam_enrollments): exam_enrollments_unexpected = [{ "acronym": "LBIO4567", "is_enrolled": False, "etat_to_inscr": None }, { "acronym": "LDROI1111", "is_enrolled": False, "etat_to_inscr": None }] for index in range(0, len(exam_enrollments_unexpected)): self.assertNotIn(exam_enrollments_unexpected[index], exam_enrollments) @patch( 'base.models.learning_unit_enrollment.find_by_student_and_offer_year') def test_case_student_has_no_learning_unit_enrollment(self, mock_find): mock_find.return_value = None off_year_enrol = OfferEnrollmentFactory( student=self.student, offer_year=OfferYearFactory( academic_year=self.current_academic_year)) self.client.force_login(self.user) response = self.client.get(reverse('exam_enrollment_form', args=[off_year_enrol.offer_year.id ]), follow=True) self.assertRedirects(response, reverse('dashboard_home')) def test_get_exam_enrollment_form(self): if hasattr(settings, 'QUEUES') and settings.QUEUES: self.assertEqual( exam_enrollment.ask_exam_enrollment_form( self.student, self.off_year).status_code, HttpResponse.status_code) else: self.assertEqual( exam_enrollment.ask_exam_enrollment_form( self.student, self.off_year).status_code, HttpResponseNotAllowed.status_code) def test_check_exam_enrollment_form_up_to_date_in_db_with_document(self): off_year = self.off_enrol.offer_year ExamEnrollmentRequestFactory(student=self.student, offer_year_acronym=off_year.acronym, document={"id": 1}) request_url = reverse(exam_enrollment.check_exam_enrollment_form, args=[off_year.id]) self.client.force_login(self.user) response = self.client.get(request_url) self.assertEqual(response.status_code, HttpResponse.status_code) def test_check_exam_enrollment_form_not_in_db(self): off_year = self.off_enrol.offer_year request_url = reverse(exam_enrollment.check_exam_enrollment_form, args=[off_year.id]) self.client.force_login(self.user) response = self.client.get(request_url) self.assertEqual(response.status_code, HTTP_RESPONSE_NOTFOUND) def test_check_exam_enrollment_form_up_to_date_in_db_with_empty_document( self): off_year = self.off_enrol.offer_year ExamEnrollmentRequestFactory(student=self.student, offer_year_acronym=off_year.acronym, document={}) request_url = reverse(exam_enrollment.check_exam_enrollment_form, args=[off_year.id]) self.client.force_login(self.user) response = self.client.get(request_url) self.assertEqual(response.status_code, HTTP_RESPONSE_NOTFOUND) def test_check_exam_enrollment_form_outdated_in_db(self): request_timeout = queue_utils.get_timeout_or_default( 'EXAM_ENROLLMENT_FORM_RESPONSE') outdated_time = timezone.now() - timezone.timedelta( seconds=request_timeout + 1) off_year = self.off_enrol.offer_year ExamEnrollmentRequestFactory(student=self.student, offer_year_acronym=off_year.acronym, document={"id": 1}) # We must update fetch_date without passing trough save() to bypass auto_now : exam_enroll_request_qs = ExamEnrollmentRequest.objects.filter( student=self.student, offer_year_acronym=off_year.acronym) exam_enroll_request_qs.update(fetch_date=outdated_time) request_url = reverse(exam_enrollment.check_exam_enrollment_form, args=[off_year.id]) self.client.force_login(self.user) response = self.client.get(request_url) self.assertEqual(response.status_code, HTTP_RESPONSE_NOTFOUND) def test_check_exam_enrollment_form_not_in_db_without_offer_enrollment( self): off_year = self.off_enrol.offer_year self.off_enrol.delete() request_url = reverse(exam_enrollment.check_exam_enrollment_form, args=[off_year.id]) self.client.force_login(self.user) response = self.client.get(request_url) self.assertEqual(response.status_code, HTTP_RESPONSE_NOTFOUND)