Exemplo n.º 1
0
    def test_education_groups_search(self, mock_render, mock_decorators):
        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func

        request_factory = RequestFactory()

        # Create educations group year
        EducationGroupYearFactory(acronym='EDPH2',
                                  academic_year=self.academic_year)
        EducationGroupYearFactory(acronym='ARKE2A',
                                  academic_year=self.academic_year)
        EducationGroupYearFactory(acronym='HIST2A',
                                  academic_year=self.academic_year)

        request = request_factory.get(
            reverse('education_groups'),
            data={
                'acronym': 'EDPH2',
                'academic_year': self.academic_year.id,
                'type': ''  #Simulate all type
            })
        request.user = mock.Mock()

        from base.views.education_group import education_groups
        education_groups(request)

        self.assertTrue(mock_render.called)

        request, template, context = mock_render.call_args[0]

        self.assertEqual(template, 'education_groups.html')
        self.assertEqual(len(context['object_list']), 1)
Exemplo n.º 2
0
    def test_education_groups_search_by_category(self, mock_render,
                                                 mock_decorators):
        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func

        request_factory = RequestFactory()

        EducationGroupYearFactory(acronym='EDPH2',
                                  academic_year=self.academic_year)
        EducationGroupYearFactory(acronym='ARKE2A',
                                  academic_year=self.academic_year)
        result = EducationGroupYearFactory(
            acronym='HIST2A',
            academic_year=self.academic_year,
            education_group_type=self.type_minitraining)

        request = request_factory.get(reverse(education_groups),
                                      data={
                                          'academic_year':
                                          self.academic_year.id,
                                          'category': MINI_TRAINING
                                      })
        request.user = mock.Mock()

        education_groups(request)

        self.assertTrue(mock_render.called)

        request, template, context = mock_render.call_args[0]

        self.assertEqual(template, 'education_groups.html')
        self.assertEqual(len(context['object_list']), 1)
        self.assertIn(result, context['object_list'])
Exemplo n.º 3
0
    def test_education_groups_search_by_code_scs(self, mock_render,
                                                 mock_decorators):
        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func
        request_factory = RequestFactory()

        EducationGroupYearFactory(acronym='EDPH2',
                                  partial_acronym='EDPH2_SCS',
                                  academic_year=self.academic_year)
        EducationGroupYearFactory(acronym='ARKE2A',
                                  partial_acronym='ARKE2A_SCS',
                                  academic_year=self.academic_year)
        EducationGroupYearFactory(acronym='HIST2A',
                                  partial_acronym='HIST2A_SCS',
                                  academic_year=self.academic_year)

        request = request_factory.get(reverse(education_groups),
                                      data={
                                          'partial_acronym': 'EDPH2_SCS',
                                          'academic_year':
                                          self.academic_year.id,
                                      })
        request.user = mock.Mock()
        education_groups(request)
        self.assertTrue(mock_render.called)
        request, template, context = mock_render.call_args[0]
        self.assertEqual(template, 'education_groups.html')
        self.assertEqual(len(context['object_list']), 1)
Exemplo n.º 4
0
    def test_education_groups_search_post(self, mock_render, mock_decorators):
        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func

        request_factory = RequestFactory()

        request = request_factory.post(reverse(education_groups), data={})
        request.user = mock.Mock()

        education_groups(request)

        self.assertTrue(mock_render.called)

        request, template, context = mock_render.call_args[0]

        self.assertEqual(template, 'education_groups.html')
        self.assertIsInstance(context.get('form'), EducationGroupFilter)
Exemplo n.º 5
0
    def test_education_groups_search_by_requirement_entity(
            self, mock_render, mock_decorators):
        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func
        request_factory = RequestFactory()

        self._prepare_context_education_groups_search()

        request = request_factory.get(reverse('education_groups'),
                                      data={
                                          'academic_year':
                                          self.academic_year.id,
                                          'requirement_entity_acronym': 'AGRO'
                                      })
        request.user = mock.Mock()
        setattr(request, 'session', 'session')
        setattr(request, '_messages', FallbackStorage(request))

        education_groups(request)
        self.assertTrue(mock_render.called)
        request, template, context = mock_render.call_args[0]
        self.assertEqual(template, 'education_groups.html')
        self.assertEqual(len(context['object_list']), 1)