Beispiel #1
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create(**{
            'project': project
        })
        comment = CommentFactory.create()

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (project.id, contribution.id),
            {
                'text': 'Response to a comment',
                'respondsto': comment.id
            }
        )
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(
            request,
            project_id=project.id,
            contribution_id=contribution.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            json.loads(response.content).get('error'),
            'The comment you try to respond to is not a comment to the '
            'contribution.'
        )
Beispiel #2
0
 def get_response(self, user):
     factory = APIRequestFactory()
     request = factory.get('/api/projects/%s/contributions/%s/comments/' %
                           (self.project.id, self.contribution.id))
     force_authenticate(request, user=user)
     view = CommentsAPIView.as_view()
     return view(request,
                 project_id=self.project.id,
                 contribution_id=self.contribution.id).render()
Beispiel #3
0
 def get_response(self, user):
     factory = APIRequestFactory()
     request = factory.post(
         "/api/projects/%s/contributions/%s/comments/" % (self.project.id, self.contribution.id),
         {"text": "A comment to the contribution."},
     )
     force_authenticate(request, user=user)
     view = CommentsAPIView.as_view()
     return view(request, project_id=self.project.id, contribution_id=self.contribution.id).render()
Beispiel #4
0
    def get_response(self, user):
        if user.is_anonymous and not User.objects.filter(display_name="AnonymousUser").exists():
            UserFactory.create(display_name="AnonymousUser")

        factory = APIRequestFactory()
        request = factory.post(
            "/api/projects/%s/maps/all-contributions/%s/comments/" % (self.project.id, self.contribution.id),
            {"text": "A comment to the contribution."},
        )
        force_authenticate(request, user=user)
        view = CommentsAPIView.as_view()
        return view(request, project_id=self.project.id, contribution_id=self.contribution.id).render()
Beispiel #5
0
    def test_add_closed_review_comment_to_contribution_with_contributor(self):
        factory = APIRequestFactory()
        request = factory.post(
            "/api/projects/%s/contributions/%s/comments/" % (self.project.id, self.contribution.id),
            {"text": "A review comment to the contribution.", "review_status": "resolved"},
        )
        force_authenticate(request, user=self.contributor)
        view = CommentsAPIView.as_view()
        response = view(request, project_id=self.project.id, contribution_id=self.contribution.id).render()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Observation.objects.get(pk=self.contribution.id).status, "active")
Beispiel #6
0
 def get_response(self, user):
     factory = APIRequestFactory()
     request = factory.get(
         '/api/projects/%s/contributions/%s/comments/' %
         (self.project.id, self.contribution.id)
     )
     force_authenticate(request, user=user)
     view = CommentsAPIView.as_view()
     return view(
         request,
         project_id=self.project.id,
         contribution_id=self.contribution.id
     ).render()
Beispiel #7
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create()

        factory = APIRequestFactory()
        request = factory.post(
            "/api/projects/%s/contributions/%s/comments/" % (project.id, contribution.id),
            {"text": "A comment to the contribution."},
        )
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(request, project_id=project.id, contribution_id=contribution.id).render()
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Beispiel #8
0
    def get_response(self, user):
        if user.is_anonymous and not User.objects.filter(
                display_name='AnonymousUser').exists():
            UserFactory.create(display_name='AnonymousUser')

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/maps/all-contributions/%s/comments/' %
            (self.project.id, self.contribution.id),
            {'text': 'A comment to the contribution.'})
        force_authenticate(request, user=user)
        view = CommentsAPIView.as_view()
        return view(request,
                    project_id=self.project.id,
                    contribution_id=self.contribution.id).render()
Beispiel #9
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create()

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (project.id, contribution.id),
            {'text': 'A comment to the contribution.'})
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(request,
                        project_id=project.id,
                        contribution_id=contribution.id).render()
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Beispiel #10
0
    def test_add_closed_review_comment_to_contribution_with_contributor(self):
        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (self.project.id, self.contribution.id), {
                'text': 'A review comment to the contribution.',
                'review_status': 'resolved'
            })
        force_authenticate(request, user=self.contributor)
        view = CommentsAPIView.as_view()
        response = view(request,
                        project_id=self.project.id,
                        contribution_id=self.contribution.id).render()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            Observation.objects.get(pk=self.contribution.id).status, 'active')
Beispiel #11
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create(**{"project": project})
        comment = CommentFactory.create(**{"commentto": contribution})

        factory = APIRequestFactory()
        request = factory.post(
            "/api/projects/%s/contributions/%s/comments/" % (project.id, contribution.id),
            {"text": "Response to a comment", "respondsto": comment.id},
        )
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(request, project_id=project.id, contribution_id=contribution.id).render()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(json.loads(response.content).get("respondsto"), comment.id)
Beispiel #12
0
    def test_add_review_comment_to_contribution_with_contributor(self):
        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (self.project.id, self.contribution.id),
            {
                'text': 'A review comment to the contribution.',
                'review_status': 'open'
            }
        )
        force_authenticate(request, user=self.contributor)
        view = CommentsAPIView.as_view()
        response = view(
            request,
            project_id=self.project.id,
            contribution_id=self.contribution.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            Observation.objects.get(pk=self.contribution.id).status,
            'review'
        )