示例#1
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)
示例#2
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
示例#3
0
 def setUpTestData(cls) -> None:
     cls.cohort = CohortFactory()
     cls.student = StudentFactory()
     cls.period = PeriodFactory(cohort=cls.cohort)
     cls.internship_score = ScoreFactory(
         student_affectation__student=cls.student,
         student_affectation__period=cls.period,
     )
示例#4
0
 def test_ajax_delete_score(self):
     edited_score = 10
     computed_score = 20
     student = StudentFactory()
     score = ScoreFactory(student_affectation__student=student,
                          student_affectation__period=self.period,
                          score=edited_score,
                          validated=True)
     url = reverse('delete_edited_score',
                   kwargs={'cohort_id': self.cohort.pk})
     self.assertEqual(score.score, edited_score)
     response = self.client.post(
         url,
         data={
             'student': score.student_affectation.student.registration_id,
             'computed': computed_score,
             'period': self.period.name,
         })
     score.refresh_from_db()
     self.assertTemplateUsed(response, 'fragment/score_cell.html')
     self.assertIsNone(score.score)
示例#5
0
    def setUpTestData(cls):
        cls.valid_grade = 'D'
        cls.not_valid_grade = 'A'
        cls.na_grade = 'E'
        cls.apd_index = 0
        cls.exception_apd_index = 7
        cls.exception_valid_grade = 'B'

        cls.cohort = CohortFactory()

        cls.good_student = StudentFactory()
        cls.score = ScoreFactory(
            student_affectation__period__cohort=cls.cohort,
            student_affectation__student=cls.good_student,
            APD_1='D')

        cls.bad_student = StudentFactory()
        cls.score = ScoreFactory(
            student_affectation__period__cohort=cls.cohort,
            student_affectation__student=cls.bad_student,
            APD_1='A')
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
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)
     }
示例#11
0
 def setUp(self) -> None:
     self.score = ScoreFactory()