Esempio n. 1
0
    def test_own_absences_evolution_success(self, mocked_method):
        self.client.login(username=self.student.username, password='******')

        catalog1 = StudentCatalogPerSubjectFactory(student=self.student)
        for day in [5, 10]:
            absence = SubjectAbsenceFactory(student=self.student,
                                            catalog_per_subject=catalog1,
                                            is_founded=True,
                                            taken_at=datetime.date(
                                                2020, 6, day))
            absence.created = datetime.datetime(2020, 6,
                                                day).replace(tzinfo=utc)
            absence.save()
        catalog2 = StudentCatalogPerSubjectFactory(student=self.student)
        for day in [5, 11]:
            absence = SubjectAbsenceFactory(student=self.student,
                                            catalog_per_subject=catalog2,
                                            is_founded=False,
                                            taken_at=datetime.date(
                                                2020, 6, day))
            absence.created = datetime.datetime(2020, 6,
                                                day).replace(tzinfo=utc)
            absence.save()
        SubjectAbsenceFactory(student=self.student,
                              catalog_per_subject=catalog2,
                              is_founded=True,
                              taken_at=datetime.date(2020, 6, 16))

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 30)

        self.assertEqual(response.data[4]['day'], 5)
        self.assertEqual(response.data[4]['weekday'], 'Vi')
        self.assertEqual(response.data[4]['total_count'], 2)

        self.assertEqual(response.data[9]['day'], 10)
        self.assertEqual(response.data[9]['weekday'], 'Mi')
        self.assertEqual(response.data[9]['total_count'], 1)

        self.assertEqual(response.data[10]['day'], 11)
        self.assertEqual(response.data[10]['weekday'], 'Jo')
        self.assertEqual(response.data[10]['total_count'], 1)

        response = self.client.get(self.url, {'by_category': 'true'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 30)

        self.assertEqual(response.data[4]['day'], 5)
        self.assertEqual(response.data[4]['weekday'], 'Vi')
        self.assertEqual(response.data[4]['founded_count'], 1)
        self.assertEqual(response.data[4]['unfounded_count'], 1)

        self.assertEqual(response.data[9]['day'], 10)
        self.assertEqual(response.data[9]['weekday'], 'Mi')
        self.assertEqual(response.data[9]['founded_count'], 1)
        self.assertEqual(response.data[9]['unfounded_count'], 0)

        self.assertEqual(response.data[10]['day'], 11)
        self.assertEqual(response.data[10]['weekday'], 'Jo')
        self.assertEqual(response.data[10]['founded_count'], 0)
        self.assertEqual(response.data[10]['unfounded_count'], 1)
Esempio n. 2
0
    def test_own_child_absences_evolution_month_filter(self, mocked_method):
        self.client.login(username=self.parent.username, password='******')

        catalog1 = StudentCatalogPerSubjectFactory(student=self.student)
        for day in [5, 11]:
            absence = SubjectAbsenceFactory(student=self.student,
                                            catalog_per_subject=catalog1,
                                            is_founded=True,
                                            taken_at=datetime.date(
                                                2020, 5, day))
            absence.created = datetime.datetime(2020, 5,
                                                day).replace(tzinfo=utc)
            absence.save()
        catalog2 = StudentCatalogPerSubjectFactory(student=self.student)
        for day in [5, 13]:
            absence = SubjectAbsenceFactory(student=self.student,
                                            catalog_per_subject=catalog2,
                                            is_founded=False,
                                            taken_at=datetime.date(
                                                2020, 5, day))
            absence.created = datetime.datetime(2020, 5,
                                                day).replace(tzinfo=utc)
            absence.save()

        response = self.client.get(self.build_url(self.student.id),
                                   {'month': 5})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 31)

        self.assertEqual(response.data[4]['day'], 5)
        self.assertEqual(response.data[4]['weekday'], 'Ma')
        self.assertEqual(response.data[4]['total_count'], 2)

        self.assertEqual(response.data[10]['day'], 11)
        self.assertEqual(response.data[10]['weekday'], 'Lu')
        self.assertEqual(response.data[10]['total_count'], 1)

        self.assertEqual(response.data[12]['day'], 13)
        self.assertEqual(response.data[12]['weekday'], 'Mi')
        self.assertEqual(response.data[12]['total_count'], 1)

        response = self.client.get(self.build_url(self.student.id), {
            'month': 5,
            'by_category': 'true'
        })
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 31)

        self.assertEqual(response.data[4]['day'], 5)
        self.assertEqual(response.data[4]['weekday'], 'Ma')
        self.assertEqual(response.data[4]['founded_count'], 1)
        self.assertEqual(response.data[4]['unfounded_count'], 1)

        self.assertEqual(response.data[10]['day'], 11)
        self.assertEqual(response.data[10]['weekday'], 'Lu')
        self.assertEqual(response.data[10]['founded_count'], 1)
        self.assertEqual(response.data[10]['unfounded_count'], 0)

        self.assertEqual(response.data[12]['day'], 13)
        self.assertEqual(response.data[12]['weekday'], 'Mi')
        self.assertEqual(response.data[12]['founded_count'], 0)
        self.assertEqual(response.data[12]['unfounded_count'], 1)