def get_education_group(self, obj):
     # return last education_group_year
     return TrainingListSerializer(
         obj.get_most_recent_education_group_year(),
         context={
             'request': self.context['request']
         }).data
Пример #2
0
    def test_get_all_training_ensure_default_order(self):
        """ This test ensure that default order is academic_year [DESC Order] + acronym [ASC Order]"""
        TrainingFactory(acronym='BIR1BA', partial_acronym='LBIR1000I', academic_year__year=2017)

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

        trainings = EducationGroupYear.objects.filter(
            education_group_type__category=education_group_categories.TRAINING,
        ).order_by('-academic_year__year', 'acronym')
        serializer = TrainingListSerializer(trainings, many=True, context={'request': RequestFactory().get(self.url)})
        self.assertEqual(response.data['results'], serializer.data)
 def get_education_group(self, obj):
     # return last education_group_year
     education_group = obj.get_current_education_group_year()
     standard_version = education_group.educationgroupversion_set.filter(
         version_name='', transition_name=NOT_A_TRANSITION).select_related(
             'offer', 'offer__academic_year',
             'offer__administration_entity',
             'offer__management_entity').first()
     return TrainingListSerializer(standard_version,
                                   context={
                                       'request': self.context['request']
                                   }).data
Пример #4
0
 def setUpTestData(cls):
     cls.academic_year = AcademicYearFactory(year=2018)
     cls.entity_version = EntityVersionFactory(
         entity__organization__type=organization_type.MAIN)
     cls.training = TrainingFactory(
         acronym='BIR1BA',
         partial_acronym='LBIR1000I',
         academic_year=cls.academic_year,
         management_entity=cls.entity_version.entity,
         administration_entity=cls.entity_version.entity,
     )
     url = reverse('education_group_api_v1:training-list')
     cls.serializer = TrainingListSerializer(
         cls.training, context={'request': RequestFactory().get(url)})
Пример #5
0
    def test_get_training_case_filter_type_params(self):
        query_string = {'in_type': 'continue'}

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

        trainings = EducationGroupYear.objects.filter(
            education_group_type__category=education_group_categories.TRAINING,
            education_group_type__name__contains=query_string['in_type'])

        serializer = TrainingListSerializer(
            trainings,
            many=True,
            context={'request': RequestFactory().get(self.url, query_string)},
        )
        self.assertEqual(response.data['results'], serializer.data)
Пример #6
0
    def test_get_training_case_filter_to_year_params(self):
        query_string = {'to_year': 2019}

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

        trainings = EducationGroupYear.objects.filter(
            education_group_type__category=education_group_categories.TRAINING,
            academic_year__year__lte=query_string['to_year']
        ).order_by('-academic_year__year', 'acronym')

        serializer = TrainingListSerializer(
            trainings,
            many=True,
            context={'request': RequestFactory().get(self.url, query_string)},
        )
        self.assertEqual(response.data['results'], serializer.data)
Пример #7
0
    def test_get_all_training_specify_ordering_field(self):
        ordering_managed = ['acronym', 'partial_acronym', 'title', 'title_english']

        for order in ordering_managed:
            with self.subTest(ordering=order):
                query_string = {api_settings.ORDERING_PARAM: order}
                response = self.client.get(self.url, data=query_string)
                self.assertEqual(response.status_code, status.HTTP_200_OK)

                trainings = EducationGroupYear.objects.filter(
                    education_group_type__category=education_group_categories.TRAINING,
                ).order_by(order)
                serializer = TrainingListSerializer(
                    trainings,
                    many=True,
                    context={'request': RequestFactory().get(self.url, query_string)},
                )
                self.assertEqual(response.data['results'], serializer.data)
Пример #8
0
 def setUpTestData(cls):
     cls.academic_year = AcademicYearFactory(year=2018)
     cls.entity_version = EntityVersionFactory(
         entity__organization__type=organization_type.MAIN
     )
     cls.training = TrainingFactory(
         acronym='GERM2MA',
         partial_acronym='LGERM905A',
         academic_year=cls.academic_year,
         education_group_type__name=education_group_types.TrainingType.MASTER_MA_120.name,
         management_entity=cls.entity_version.entity,
         administration_entity=cls.entity_version.entity,
     )
     url = reverse('education_group_api_v1:training-list')
     cls.serializer = TrainingListSerializer(cls.training, context={
         'request': RequestFactory().get(url),
         'language': settings.LANGUAGE_CODE_EN
     })