Ejemplo n.º 1
0
    def test_invalid_update_discipline_by_not_logged_teacher(self):
        """
        Test to update discipline by not logged user.
        """

        data = DisciplineSerializer(self.discipline).data
        data.update({'title': 'Discipline 02'})
        response = self.client.put(self.url, data)
        self.assertEquals(response.status_code, status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 2
0
    def test_invalid_update_by_student(self):
        """
        Only teacher can update discipline
        """

        self.client.force_authenticate(self.student)
        data = DisciplineSerializer(self.discipline).data
        data.update({'description': 'Update description'})
        response = self.client.put(self.url, data)
        self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 3
0
    def test_discipline_not_found(self):
        """
        Test to find discipline that not exists.
        """

        url_invalid = reverse('discipline:details', kwargs={'pk': 30})
        data = DisciplineSerializer(self.discipline).data
        data.update({'title': 'Update Title'})
        response = self.client.put(url_invalid, data)
        self.assertEquals(response.status_code, status.HTTP_404_NOT_FOUND)
Ejemplo n.º 4
0
    def test_valid_update_discipline(self):
        """
        Test to update the own discipline.
        """

        self.client.force_authenticate(self.teacher)
        data = DisciplineSerializer(self.discipline).data
        data.update({'title': 'Discipline 02'})
        response = self.client.put(self.url, data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data['title'], 'Discipline 02')
Ejemplo n.º 5
0
    def test_invalid_title_update_discipline(self):
        """
        Test can't update a specific discipline. Invalid title.
        """

        self.client.force_authenticate(self.teacher)
        data = DisciplineSerializer(self.discipline).data
        data.update({'title': ''})
        response = self.client.put(self.url, data)
        self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEquals(response.data,
                          {'title': [_('This field may not be blank.')]})
Ejemplo n.º 6
0
    def test_invalid_update_another_discipline(self):
        """
        Can't Update another teacher discipline of system.
        """

        self.teacher2 = Teacher.objects.create(name='Teacher 02',
                                               email='*****@*****.**',
                                               is_teacher=True,
                                               password='******')
        self.client.force_authenticate(self.teacher2)
        data = DisciplineSerializer(self.discipline).data
        data.update({'description': 'Update description'})
        response = self.client.put(self.url, data)
        self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 7
0
    def test_valid_not_logged_discipline_detail(self):
        """
        Test found the discipline without be logged.
        """

        serializer = DisciplineSerializer(self.discipline)
        response = self.client.get(self.url)
        self.assertEquals(response.data, serializer.data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 8
0
    def test_valid_own_discipline_detail(self):
        """
        Test found the own discipline.
        """

        self.client.force_authenticate(self.teacher)
        serializer = DisciplineSerializer(self.discipline)
        response = self.client.get(self.url)
        self.assertEquals(response.data, serializer.data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 9
0
    def test_valid_not_logged_discipline_list(self):
        """
        Test found the discipline list not logged.
        """

        disciplines = Discipline.objects.all()
        serializer = DisciplineSerializer(disciplines, many=True)
        url = reverse('discipline:list-create')
        response = self.client.get(url)
        self.assertEquals(Discipline.objects.count(), 1)
        self.assertEquals(response.data, serializer.data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 10
0
    def test_valid_another_discipline_detail(self):
        """
        Test found the specific discipline.
        """

        self.teacher2 = Teacher.objects.create(name='Teacher 02',
                                               email='*****@*****.**',
                                               is_teacher=True,
                                               password='******')
        self.discipline2 = Discipline.objects.create(
            title="Discipline 02",
            description="Description 02",
            course="Course 02",
            teacher=self.teacher2)
        self.client.force_authenticate(self.teacher)
        url = reverse('discipline:details', kwargs={'pk': self.discipline2.id})
        serializer = DisciplineSerializer(self.discipline2)
        response = self.client.get(url)
        self.assertEquals(response.data, serializer.data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)