Beispiel #1
0
def project_task_detail(request, pk, tk):
    projects = Project.objects.filter(id=pk)
    serializer = ProjectTaskSerializer(projects, many=True)
    try:
        task_keys = dict(serializer.data[0])['tasks']
    except Exception as e:
        return Response("Invalid Project")

    if tk in task_keys:
        try:
            task = Task.objects.filter(id=tk)
        except Snippet.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)

        if request.method == 'GET':
            serializer = TaskSerializer(task, many=True)
            return Response(serializer.data)

        elif request.method == 'PUT':
            serializer = TaskSerializer(task, data=request.data)
            if serializer.is_valid():
                serializer.save()
                return Response(serializer.data)
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        elif request.method == 'DELETE':
            task.delete()
            return Response(status=status.HTTP_204_NO_CONTENT)
    else:
        return Response("Task does not belong to project")
Beispiel #2
0
    def test_get_task_with_same_name(self):
        response = self.client.get('/api/v1/tasks/' + '?task_name=Протри+пыль')

        tasks = Task.objects.filter(task_name='Протри пыль')
        serializer = TaskSerializer(tasks, many=True)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #3
0
    def test_get_task_with_same_project_name(self):
        response = self.client.get('/api/v1/tasks/' +
                                   '?project_name=Работа+по+дому')

        tasks = Task.objects.filter(project_name='Работа по дому')
        serializer = TaskSerializer(tasks, many=True)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #4
0
    def test_get_task_with_same_author(self):
        response = self.client.get('/api/v1/tasks/' + '?author=' +
                                   str(self.user_id))

        tasks = Task.objects.filter(author=User.objects.get(id=self.user_id))
        serializer = TaskSerializer(tasks, many=True)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #5
0
    def test_get_one_task(self):
        # Ответ API
        response = self.client.get('/api/v1/tasks/' + str(self.task_id) + '/')

        # Ответ базы данных
        task = Task.objects.get(id=self.task_id)
        serializer = TaskSerializer(task)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #6
0
    def test_get_all_tasks(self):
        # Ответ API
        response = self.client.get('/api/v1/tasks/')

        # Ответ базы данных
        tasks = Task.objects.all()
        serializer = TaskSerializer(tasks, many=True)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #7
0
    def test_get_task_with_same_status(self):
        # Ответ API
        response = self.client.get('/api/v1/tasks/' + '?status=1')
        # Ответ базы данных
        tasks = Task.objects.filter(status="1")

        serializer = TaskSerializer(tasks, many=True)
        self.assertEqual(response.data, serializer.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #8
0
def project_task(request, pk):
    projects = Project.objects.filter(id=pk)
    serializer = ProjectTaskSerializer(projects, many=True)
    try:
        task_keys = dict(serializer.data[0])['tasks']
    except Exception as e:
        return Response("Invalid Project")
    tasks = Task.objects.filter(id__in=task_keys)
    serializer = TaskSerializer(tasks, many=True)
    return Response(serializer.data)