Пример #1
0
    def test_get_tasks_as_anonymous(self):
        TaskFactory.create_batch(size=5)

        url = reverse('task-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data, {'detail': 'Authentication credentials were not provided.'})
Пример #2
0
    def test_get_tasks_as_project_owner(self):
        task, *_ = TaskFactory.create_batch(size=5)
        self.client.force_login(task.project.owner)

        url = reverse('task-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(Task.objects.filter(project__owner=task.project.owner).count(), len(response.data))
        self.assertEqual(Task.objects.available_for_user(task.project.owner).count(), len(response.data))
Пример #3
0
    def test_get_tasks_as_member(self):
        user = UserFactory()
        self.client.force_login(user)

        task1, task2, task3, *_ = TaskFactory.create_batch(size=5)
        task1.memberships.create(user=user)
        task2.memberships.create(user=user)
        task3.memberships.create(user=user, is_active=False)

        url = reverse('task-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            Task.objects.filter(memberships__user=user, memberships__is_active=True).count(), len(response.data))
        self.assertEqual(Task.objects.available_for_user(user).count(), len(response.data))