def put(self, request, pk, format=None): employee = self.get_object(pk) serializer = EmployeeSerializer(employee, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def test_get_employee(self): self.client.force_login(self.user) response = self.client.get(reverse("employee-list")) employees = Employee.objects.all() serialized_employees = EmployeeSerializer(employees, many=True) self.assertEqual(response.data, serialized_employees.data) self.assertEqual(response.status_code, status.HTTP_200_OK)
def post(self, request, format=None): serializer = EmployeeSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)