Exemplo n.º 1
0
 def get_response(self, user):
     factory = APIRequestFactory()
     request = factory.delete(
         '/api/projects/%s/contributions/%s/comments/%s/' %
         (self.project.id, self.contribution.id, self.comment_to_remove.id),
         {'text': 'A comment to the contribution.'})
     force_authenticate(request, user=user)
     view = SingleCommentAPIView.as_view()
     return view(request,
                 project_id=self.project.id,
                 contribution_id=self.contribution.id,
                 comment_id=self.comment_to_remove.id).render()
Exemplo n.º 2
0
 def get_response(self, user):
     factory = APIRequestFactory()
     request = factory.delete(
         "/api/projects/%s/contributions/%s/comments/%s/"
         % (self.project.id, self.contribution.id, self.comment_to_remove.id),
         {"text": "A comment to the contribution."},
     )
     force_authenticate(request, user=user)
     view = SingleCommentAPIView.as_view()
     return view(
         request,
         project_id=self.project.id,
         contribution_id=self.contribution.id,
         comment_id=self.comment_to_remove.id,
     ).render()
Exemplo n.º 3
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create(**{"project": project})
        comment = CommentFactory.create()

        factory = APIRequestFactory()
        request = factory.delete(
            "/api/projects/%s/contributions/%s/comments/%s/" % (project.id, contribution.id, comment.id),
            {"text": "A comment to the contribution."},
        )
        force_authenticate(request, user=admin)
        view = SingleCommentAPIView.as_view()
        response = view(request, project_id=project.id, contribution_id=contribution.id, comment_id=comment.id).render()

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 4
0
 def get_response(self, user, comment_to_remove=None):
     if not comment_to_remove:
         comment_to_remove = self.comment_to_remove
     factory = APIRequestFactory()
     request = factory.delete(
         '/api/projects/%s/contributions/%s/comments/%s/' %
         (self.project.id, self.contribution.id, comment_to_remove.id),
         {'text': 'A comment to the contribution.'}
     )
     force_authenticate(request, user=user)
     view = SingleCommentAPIView.as_view()
     return view(
         request,
         project_id=self.project.id,
         contribution_id=self.contribution.id,
         comment_id=comment_to_remove.id
     ).render()
Exemplo n.º 5
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create(**{'project': project})
        comment = CommentFactory.create()

        factory = APIRequestFactory()
        request = factory.delete(
            '/api/projects/%s/contributions/%s/comments/%s/' %
            (project.id, contribution.id, comment.id),
            {'text': 'A comment to the contribution.'})
        force_authenticate(request, user=admin)
        view = SingleCommentAPIView.as_view()
        response = view(request,
                        project_id=project.id,
                        contribution_id=contribution.id,
                        comment_id=comment.id).render()

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 6
0
    def test_update_invalid_comment(self):
        self.project.isprivate = False
        self.project.save()

        url = reverse(
            "api:project_single_comment",
            kwargs={
                "project_id": self.project.id,
                "contribution_id": self.contribution.id,
                "comment_id": self.comment.id,
            },
        )
        request = self.factory.patch(url, {"text": "Updated", "review_status": "blah"})
        force_authenticate(request, user=self.commenter)

        view = SingleCommentAPIView.as_view()
        response = view(
            request, project_id=self.project.id, contribution_id=self.contribution.id, comment_id=self.comment.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 7
0
    def test_update_invalid_comment(self):
        self.project.isprivate = False
        self.project.save()

        url = reverse('api:project_single_comment', kwargs={
            'project_id': self.project.id,
            'contribution_id': self.contribution.id,
            'comment_id': self.comment.id
        })
        request = self.factory.patch(
            url, {'text': 'Updated', 'review_status': 'blah'}
        )
        force_authenticate(request, user=self.commenter)

        view = SingleCommentAPIView.as_view()
        response = view(
            request,
            project_id=self.project.id,
            contribution_id=self.contribution.id,
            comment_id=self.comment.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)