Exemplo n.º 1
0
 def get_response(self, user):
     factory = APIRequestFactory()
     request = factory.delete(
         '/api/projects/%s/observations/%s/comments/%s/' %
         (self.project.id, self.observation.id, self.comment_to_remove.id),
         {'text': 'A comment to the observation'})
     force_authenticate(request, user=user)
     view = AllContributionsSingleCommentAPIView.as_view()
     return view(request,
                 project_id=self.project.id,
                 observation_id=self.observation.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/observations/%s/comments/%s/' %
         (self.project.id, self.observation.id, self.comment_to_remove.id),
         {'text': 'A comment to the observation'}
     )
     force_authenticate(request, user=user)
     view = AllContributionsSingleCommentAPIView.as_view()
     return view(
         request,
         project_id=self.project.id,
         observation_id=self.observation.id,
         comment_id=self.comment_to_remove.id
     ).render()
Exemplo n.º 3
0
    def test(self):
        admin = UserF.create()
        project = ProjectF(add_admins=[admin])
        observation = ObservationFactory.create(**{'project': project})
        comment = CommentFactory.create()

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

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 4
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,
            'observation_id': self.observation.id,
            'comment_id': self.comment.id
        })
        request = self.factory.patch(
            url, {'text': 'Updated', 'review_status': 'blah'}
        )
        force_authenticate(request, user=self.commenter)

        view = AllContributionsSingleCommentAPIView.as_view()
        response = view(
            request,
            project_id=self.project.id,
            observation_id=self.observation.id,
            comment_id=self.comment.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 5
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,
                          'observation_id': self.observation.id,
                          'comment_id': self.comment.id
                      })
        request = self.factory.patch(url, {
            'text': 'Updated',
            'review_status': 'blah'
        })
        force_authenticate(request, user=self.commenter)

        view = AllContributionsSingleCommentAPIView.as_view()
        response = view(request,
                        project_id=self.project.id,
                        observation_id=self.observation.id,
                        comment_id=self.comment.id).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 6
0
    def test(self):
        admin = UserF.create()
        project = ProjectF(add_admins=[admin])
        observation = ObservationFactory.create(**{
            'project': project
        })
        comment = CommentFactory.create()

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

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 7
0
 def test_get_object_with_some_dude(self):
     some_dude = UserF.create()
     view = AllContributionsSingleCommentAPIView()
     view.get_object(some_dude, self.project.id, self.observation.id)
Exemplo n.º 8
0
 def test_get_object_with_creator(self):
     view = AllContributionsSingleCommentAPIView()
     view.get_object(self.creator, self.project.id, self.observation.id)
Exemplo n.º 9
0
 def test_get_object_with_admin(self):
     view = AllContributionsSingleCommentAPIView()
     observation = view.get_object(
         self.admin, self.project.id, self.observation.id)
     self.assertEqual(observation, self.observation)
Exemplo n.º 10
0
 def test_get_object_with_some_dude(self):
     some_dude = UserF.create()
     view = AllContributionsSingleCommentAPIView()
     view.get_object(some_dude, self.project.id, self.observation.id)
Exemplo n.º 11
0
 def test_get_object_with_creator(self):
     view = AllContributionsSingleCommentAPIView()
     view.get_object(self.creator, self.project.id, self.observation.id)
Exemplo n.º 12
0
 def test_get_object_with_admin(self):
     view = AllContributionsSingleCommentAPIView()
     observation = view.get_object(self.admin, self.project.id,
                                   self.observation.id)
     self.assertEqual(observation, self.observation)