Beispiel #1
0
    def test_invalid_not_logged_update_discipline_class(self):
        """
        Not logged user can't update discipline classes
        """

        url = self.get_url(self.discipline01.id, self.classroom01.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'title': 'Turma B'})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_401_UNAUTHORIZED)
Beispiel #2
0
    def test_update_discipline_class_not_found(self):
        """
        Test to edit class that not exists for specific discipline.
        """

        self.client.force_authenticate(self.teacher01)
        url = self.get_url(self.discipline01.id, self.classroom02.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'title': 'Turma B'})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_404_NOT_FOUND)
Beispiel #3
0
    def test_invalid_update_another_discipline_class(self):
        """
        Can't update discipline classes by another teacher.
        """

        self.client.force_authenticate(self.teacher02)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'title': 'Turma B'})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN)
Beispiel #4
0
    def test_valid_update_discipline_class(self):
        """
        Test to update the own discipline class.
        """

        self.client.force_authenticate(self.teacher01)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'title': 'Turma B'})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data['title'], 'Turma B')
Beispiel #5
0
    def test_valid_update_discipline_class_without_students(self):
        """
        Test can take off all students from discipline class.
        """

        self.client.force_authenticate(self.teacher01)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'students': []})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(response.data['students'], [])
Beispiel #6
0
    def test_update_invalid_zero_student_limit_by_discipline_class(self):
        """
        Test can't update a specific discipline class. Invalid student limit.
        """

        self.client.force_authenticate(self.teacher01)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'student_limit': 0})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEquals(
            response.data,
            {'student_limit': [_('0 is not bigger than 0.')]}
        )
Beispiel #7
0
    def test_update_invalid_title_by_discipline_class(self):
        """
        Test can't update a specific discipline class. Invalid title.
        """

        self.client.force_authenticate(self.teacher01)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        data = ClassRoomSerializer(self.classroom01).data
        data.update({'title': ''})
        response = self.client.put(url, data)
        self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEquals(
            response.data,
            {'title': [_('This field may not be blank.')]}
        )
Beispiel #8
0
    def test_not_logged_valid_discipline_class_detail(self):
        """
        Test found the discipline class by not logged user.
        """

        serializer = ClassRoomSerializer(self.classroom01)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        response = self.client.get(url)
        self.assertEquals(response.data, serializer.data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
Beispiel #9
0
    def test_valid_another_discipline_class_detail(self):
        """
        Test found the discipline from another teacher.
        """

        self.client.force_authenticate(self.teacher02)
        serializer = ClassRoomSerializer(self.classroom01)
        url = self.get_url(self.discipline01.id, self.classroom01.id)
        response = self.client.get(url)
        self.assertEquals(response.data, serializer.data)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
Beispiel #10
0
    def get(self, request):
        """查询所有"""
        try:
            classroom = classroom_table.objects.all()
        except:
            return Response({"error": "查询失败"})

        # 序列化
        classroom_serializer = ClassRoomSerializer(classroom, many=True)
        classroom_dict = classroom_serializer.data

        return Response(classroom_dict)
Beispiel #11
0
    def patch(self, request, pk):
        """局部更新"""
        try:
            classroom = classroom_table.objects.get(crid=pk)
        except:
            return Response({"error": "查询错误"})

        # 接收
        classroom_dict = request.data

        # 验证
        classroom_serilizer = ClassRoomSerializer(classroom,
                                                  data=classroom_dict,
                                                  partial=True)
        if not classroom_serilizer.is_valid():
            return Response(classroom_serilizer.errors)

        print(classroom_serilizer)
        # 保存  update
        classroom = classroom_serilizer.save()

        # 响应
        classroom_serilizer = ClassRoomSerializer(classroom)
        classroom_dict = classroom_serilizer.data
        return Response(classroom_dict, status=201)