示例#1
0
 def test_get_contribution_with_creator(self):
     view = SingleCommentAPIView()
     view.get_contribution(
         self.creator,
         self.project.id,
         self.contribution.id
     )
示例#2
0
 def test_get_contribution_with_some_dude(self):
     some_dude = UserFactory.create()
     view = SingleCommentAPIView()
     view.get_contribution(
         some_dude,
         self.project.id,
         self.contribution.id
     )
示例#3
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()
示例#4
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()
示例#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)
示例#6
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()
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
0
 def test_get_contribution_with_admin(self):
     view = SingleCommentAPIView()
     contribution = view.get_contribution(
         self.admin, self.project.id, self.contribution.id)
     self.assertEqual(contribution, self.contribution)