def test(self): admin = UserF.create() project = ProjectF(add_admins=[admin]) observation = ObservationFactory.create(**{ 'project': project }) comment = CommentFactory.create() factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (project.id, observation.id), { 'text': 'Response to a comment', 'respondsto': comment.id } ) force_authenticate(request, user=admin) view = AllContributionsCommentsAPIView.as_view() response = view( request, project_id=project.id, observation_id=observation.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 ' 'observation.' )
def test(self): admin = UserFactory.create() project = ProjectFactory(add_admins=[admin]) observation = ObservationFactory.create(**{ 'project': project }) comment = CommentFactory.create(**{ 'commentto': observation }) factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (project.id, observation.id), { 'text': 'Response to a comment', 'respondsto': comment.id } ) force_authenticate(request, user=admin) view = AllContributionsCommentsAPIView.as_view() response = view( request, project_id=project.id, observation_id=observation.id ).render() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( json.loads(response.content).get('respondsto'), comment.id )
def get_response(self, user): factory = APIRequestFactory() request = factory.get('/api/projects/%s/observations/%s/comments/' % (self.project.id, self.observation.id)) force_authenticate(request, user=user) view = AllContributionsCommentsAPIView.as_view() return view(request, project_id=self.project.id, observation_id=self.observation.id).render()
def get_response(self, user): factory = APIRequestFactory() request = factory.get( '/api/projects/%s/observations/%s/comments/' % (self.project.id, self.observation.id) ) force_authenticate(request, user=user) view = AllContributionsCommentsAPIView.as_view() return view( request, project_id=self.project.id, observation_id=self.observation.id ).render()
def test(self): admin = UserF.create() project = ProjectF(add_admins=[admin]) observation = ObservationFactory.create() factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (project.id, observation.id), {'text': 'A comment to the observation'}) force_authenticate(request, user=admin) view = AllContributionsCommentsAPIView.as_view() response = view(request, project_id=project.id, observation_id=observation.id).render() self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_add_closed_review_comment_to_observation_with_contributor(self): factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (self.project.id, self.observation.id), { 'text': 'A review comment to the observation', 'review_status': 'resolved' }) force_authenticate(request, user=self.contributor) view = AllContributionsCommentsAPIView.as_view() response = view(request, project_id=self.project.id, observation_id=self.observation.id).render() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( Observation.objects.get(pk=self.observation.id).status, 'active')
def get_response(self, user): if user.is_anonymous and not User.objects.filter( display_name='AnonymousUser').exists(): UserF.create(display_name='AnonymousUser') factory = APIRequestFactory() request = factory.post( '/api/projects/%s/maps/all-contributions/%s/comments/' % (self.project.id, self.observation.id), {'text': 'A comment to the observation'} ) force_authenticate(request, user=user) view = AllContributionsCommentsAPIView.as_view() return view( request, project_id=self.project.id, observation_id=self.observation.id ).render()
def test(self): admin = UserF.create() project = ProjectF(add_admins=[admin]) observation = ObservationFactory.create() factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (project.id, observation.id), {'text': 'A comment to the observation'} ) force_authenticate(request, user=admin) view = AllContributionsCommentsAPIView.as_view() response = view( request, project_id=project.id, observation_id=observation.id ).render() self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test(self): admin = UserF.create() project = ProjectF(add_admins=[admin]) observation = ObservationFactory.create(**{'project': project}) comment = CommentFactory.create(**{'commentto': observation}) factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (project.id, observation.id), { 'text': 'Response to a comment', 'respondsto': comment.id }) force_authenticate(request, user=admin) view = AllContributionsCommentsAPIView.as_view() response = view(request, project_id=project.id, observation_id=observation.id).render() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( json.loads(response.content).get('respondsto'), comment.id)
def test_add_closed_review_comment_to_observation_with_contributor(self): factory = APIRequestFactory() request = factory.post( '/api/projects/%s/observations/%s/comments/' % (self.project.id, self.observation.id), { 'text': 'A review comment to the observation', 'review_status': 'resolved' } ) force_authenticate(request, user=self.contributor) view = AllContributionsCommentsAPIView.as_view() response = view( request, project_id=self.project.id, observation_id=self.observation.id ).render() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( Observation.objects.get(pk=self.observation.id).status, 'active' )