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()
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()
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)
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)
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)
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)