示例#1
0
 def generate_workbook(self):
     students = [StudentFactory() for _ in range(0, 10)]
     [
         InternshipStudentInformationFactory(person=student.person,
                                             cohort=self.cohort)
         for student in students
     ]
     affectations = [
         StudentAffectationStatFactory(student=student, period=self.period)
         for student in students
     ]
     self.existing_score_not_validated = ScoreFactory(
         student_affectation=affectations[0], validated=False)
     workbook = openpyxl.Workbook()
     worksheet = workbook.active
     worksheet.cell(row=1,
                    column=1).value = 'PERIOD{}'.format(self.period.name)
     for row, student in enumerate(students):
         columns = [(0, student.registration_id), (1, '1')]
         for i in range(1, APDS_COUNT * LINE_INTERVAL, LINE_INTERVAL):
             columns.append((LINE_INTERVAL + 1 + i,
                             random.choice(['A', 'B', 'C', 'D', 'E',
                                            None])))
         for column, value in columns:
             worksheet.cell(row=row + 6, column=column + 1).value = value
     return workbook
示例#2
0
 def test_ajax_delete_evolution_score(self):
     computed_score = 0
     student_info = InternshipStudentInformationFactory(cohort=self.cohort,
                                                        evolution_score=20)
     student = StudentFactory(person=student_info.person)
     url = reverse('delete_evolution_score',
                   kwargs={'cohort_id': self.cohort.pk})
     response = self.client.post(url,
                                 data={
                                     'computed': computed_score,
                                     'scores': '{"P1": 0, "P2": 0}',
                                     'student': student.registration_id
                                 })
     student_info.refresh_from_db()
     self.assertTemplateUsed(response, 'fragment/evolution_score_cell.html')
     self.assertIsNone(student_info.evolution_score)
示例#3
0
 def test_compute_evolution_score(self):
     student_name = "test_student"
     student_info = InternshipStudentInformationFactory(
         person__last_name=student_name, cohort=self.cohort)
     student = StudentFactory(person=student_info.person)
     PeriodFactory(name='last_period', cohort=self.cohort)
     ScoreFactory(student_affectation__student=student,
                  student_affectation__period=self.period,
                  APD_1='A',
                  validated=True)
     ScoreFactory(student_affectation__student=student,
                  student_affectation__period=self.other_period,
                  APD_1='C',
                  validated=True)
     ScoreMappingFactory(period=self.other_period,
                         cohort=self.cohort,
                         score_A=20,
                         score_B=15,
                         score_C=10,
                         score_D=0,
                         apd=1)
     url = reverse('internship_scores_encoding',
                   kwargs={'cohort_id': self.cohort.pk})
     response = self.client.get(url, {'free_text': student_name})
     evolution_score = response.context['students'].object_list[
         0].evolution_score
     self.assertEqual(evolution_score, 15)
示例#4
0
 def test_filter_students_by_current_internship(self):
     period = PeriodFactory(cohort=self.cohort,
                            date_start=date.today(),
                            date_end=date.today())
     student_info = InternshipStudentInformationFactory(
         cohort=self.cohort, person=self.student_1.person)
     affectation = StudentAffectationStatFactory(student=self.student_1,
                                                 period=period)
     url = reverse(internships_student_resume,
                   kwargs={
                       'cohort_id': self.cohort.id,
                   })
     response = self.client.get(url)
     actual, stats = student._get_students_with_status(
         request=response.wsgi_request,
         cohort=self.cohort,
         filters=(None, True))
     expected = [student_info]
     self.assertCountEqual(expected, actual)
     for item_expected in expected:
         self.assertIn(item_expected, actual)
     self.assertEqual(
         actual[0].current_internship,
         "{}{}".format(affectation.speciality.acronym,
                       affectation.organization.reference))
示例#5
0
 def setUpTestData(cls):
     cls.cohort = CohortFactory()
     cls.students = [
         InternshipStudentInformationFactory(cohort=cls.cohort)
         for _ in range(0, 9)
     ]
     cls.student_with_accent = InternshipStudentInformationFactory(
         cohort=cls.cohort, person=PersonFactory(last_name='Éçàüî'))
     cls.students.append(cls.student_with_accent)
     cls.url = reverse(internships_student_resume,
                       kwargs={
                           'cohort_id': cls.cohort.id,
                       })
     cls.user = User.objects.create_user('demo', '*****@*****.**',
                                         'passtest')
     permission = Permission.objects.get(codename='is_internship_manager')
     cls.user.user_permissions.add(permission)
示例#6
0
 def test_ajax_save_evolution_score(self):
     computed_score = 0
     new_score = 20
     student_info = InternshipStudentInformationFactory(cohort=self.cohort)
     student = StudentFactory(person=student_info.person)
     self.assertIsNone(student_info.evolution_score)
     url = reverse('save_evolution_score',
                   kwargs={'cohort_id': self.cohort.pk})
     response = self.client.post(url,
                                 data={
                                     'computed': computed_score,
                                     'edited': new_score,
                                     'student': student.registration_id,
                                     'scores': '{}',
                                 })
     student_info.refresh_from_db()
     self.assertTemplateUsed(response, 'fragment/evolution_score_cell.html')
     self.assertEqual(student_info.evolution_score, new_score)
示例#7
0
 def test_when_internship_installed(self, mock_get_master_by_email):
     user = get_or_create_user(self.user_infos)
     person = PersonFactory(user=user,
                            first_name="user3",
                            last_name="user3",
                            email='*****@*****.**',
                            global_id="1111111")
     InternshipStudentInformationFactory(person=person)
     _add_person_to_group(person)
     self.assertTrue(
         person.user.groups.filter(name=GROUP_STUDENTS_INTERNSHIP).exists())
示例#8
0
def _create_internship_students(cls):
    internship_students = [
        InternshipStudentInformationFactory(cohort=cls.cohort,
                                            person=PersonFactory())
        for _ in range(0, N_STUDENTS)
    ]
    students = [
        StudentFactory(person=student.person)
        for student in internship_students
    ]
    return students
示例#9
0
 def test_search_student_by_name_unaccent(self):
     url = reverse('internship_scores_encoding',
                   kwargs={'cohort_id': self.cohort.pk})
     person = PersonFactory(last_name="Éçàüî")
     searched_student = InternshipStudentInformationFactory(
         person=person, cohort=self.cohort)
     data = {
         'free_text': searched_student.person.last_name,
     }
     response = self.client.get(url, data=data)
     self.assertEqual(response.context['students'].object_list[0],
                      searched_student)
示例#10
0
 def test_export_only_validated_scores(self, mock_export: Mock):
     # create student with no validated score
     student_with_no_validated_score = StudentFactory(
         person=InternshipStudentInformationFactory(
             person__last_name='AAA', cohort=self.cohort).person)
     ScoreFactory(
         student_affectation__period=self.period,
         student_affectation__student=student_with_no_validated_score,
         APD_1='A',
         validated=False)
     url = reverse('internship_download_scores',
                   kwargs={'cohort_id': self.cohort.pk})
     self.client.post(url, data={'period': self.period.name})
     args, kwargs = mock_export.call_args
     exported_students = args[2]
     student_with_score_not_validated = exported_students[0]
     student_with_score_validated = exported_students[1]
     self.assertFalse(student_with_score_not_validated.scores)
     self.assertTrue(student_with_score_validated.scores)
示例#11
0
 def test_show_only_validated_scores(self):
     # create student with no validated score
     student_with_no_validated_score = StudentFactory(
         person=InternshipStudentInformationFactory(
             person__last_name='AAA', cohort=self.cohort).person)
     ScoreFactory(
         student_affectation__period=self.period,
         student_affectation__student=student_with_no_validated_score,
         APD_1='A',
         validated=False)
     url = reverse('internship_scores_encoding',
                   kwargs={'cohort_id': self.cohort.pk})
     response = self.client.get(url)
     student_with_score_not_validated = response.context[
         'students'].object_list[0]
     student_with_score_validated = response.context[
         'students'].object_list[1]
     self.assertTrue(student_with_score_validated.scores)
     self.assertFalse(student_with_score_not_validated.scores)
示例#12
0
 def test_show_excused_score_disregarded_in_evolution_score_computation(
         self):
     student_info = InternshipStudentInformationFactory(
         cohort=self.cohort, person__last_name="A")
     student = StudentFactory(person=student_info.person)
     new_score = 10
     ScoreFactory(student_affectation__student=student,
                  student_affectation__period=self.period,
                  excused=True,
                  score=new_score,
                  validated=True)
     url = reverse('internship_scores_encoding',
                   kwargs={'cohort_id': self.cohort.pk})
     response = self.client.get(url)
     filtered_object_list = [
         obj for obj in response.context['students'].object_list
         if obj == student_info
     ]
     numeric_scores = filtered_object_list[0].numeric_scores
     evolution_score = filtered_object_list[0].evolution_score
     self.assertEqual(numeric_scores[self.period.name],
                      {'excused': new_score})
     self.assertEqual(evolution_score, 0)
示例#13
0
 def test_send_recap(self, mock_send_mail):
     student_info = InternshipStudentInformationFactory(cohort=self.cohort)
     student = StudentFactory(person=student_info.person)
     period = PeriodFactory(name='PTEST',
                            cohort=self.cohort,
                            date_end=date.today() - timedelta(days=1))
     student_affectation = StudentAffectationStatFactory(student=student,
                                                         period=period)
     ScoreFactory(student_affectation=student_affectation, validated=True)
     url = reverse('send_summary',
                   kwargs={
                       'cohort_id': self.cohort.pk,
                       'period_id': period.pk
                   })
     response = self.client.post(
         url, data={'selected_student': [student_info.pk]})
     messages_list = [
         str(msg)
         for msg in list(messages.get_messages(response.wsgi_request))
     ]
     self.assertIn(_("Summaries have been sent successfully"),
                   messages_list)
     self.assertTrue(mock_send_mail.called)
示例#14
0
 def setUpTestData(cls):
     cls.cohort = CohortFactory()
     cls.period = PeriodFactory(name='P1',
                                date_end=date.today() -
                                relativedelta(months=2),
                                cohort=cls.cohort)
     cls.other_period = PeriodFactory(
         name='P2',
         date_end=date.today() - relativedelta(months=1),
         cohort=cls.cohort,
     )
     cls.xlsfile = SimpleUploadedFile(
         name='upload.xls',
         content=str.encode('test'),
         content_type="application/vnd.ms-excel",
     )
     cls.xlsxfile = SimpleUploadedFile(
         name='upload.xlsx',
         content=str.encode('test'),
         content_type=
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
     )
     cls.students = [
         InternshipStudentInformationFactory(cohort=cls.cohort)
         for _ in range(11)
     ]
     cls.mandatory_internship = InternshipFactory(
         cohort=cls.cohort, speciality=SpecialtyFactory(cohort=cls.cohort))
     cls.long_internship = InternshipFactory(cohort=cls.cohort,
                                             speciality=SpecialtyFactory(
                                                 cohort=cls.cohort,
                                                 sequence=1))
     cls.chosen_internship = InternshipFactory(cohort=cls.cohort,
                                               speciality=None)
     internships = [
         cls.mandatory_internship, cls.long_internship,
         cls.chosen_internship
     ]
     periods = [cls.period
                ] + [PeriodFactory(cohort=cls.cohort) for _ in range(2)]
     for student_info in cls.students:
         student = StudentFactory(person=student_info.person)
         for index, internship in enumerate(internships):
             StudentAffectationStatFactory(
                 student=student,
                 internship=internship,
                 speciality=internship.speciality
                 if internship.speciality else SpecialtyFactory(),
                 period=periods[index])
         ScoreFactory(student_affectation__student=student,
                      student_affectation__period=cls.period,
                      APD_1='A',
                      validated=True)
     for apd in range(1, APD_NUMBER):
         ScoreMappingFactory(period=cls.period,
                             cohort=cls.cohort,
                             score_A=20,
                             score_B=15,
                             score_C=10,
                             score_D=0,
                             apd=apd)
     cls.unused_period = PeriodFactory(name="P99",
                                       cohort=cls.cohort,
                                       date_end=date.today() +
                                       relativedelta(months=+2))
     cls.user = User.objects.create_user('demo', '*****@*****.**',
                                         'passtest')
     permission = Permission.objects.get(codename='is_internship_manager')
     cls.user.user_permissions.add(permission)
     cls.all_apds_validated = {
         'APD_{}'.format(i): 'D'
         for i in range(1, APD_NUMBER + 1)
     }
示例#15
0
 def setUp(self) -> None:
     self.cohort = CohortFactory()
     self.student_info = InternshipStudentInformationFactory(
         cohort=self.cohort)
     self.student = StudentFactory(person=self.student_info.person)
     self.period = PeriodFactory(cohort=self.cohort)