def test_private_node_delete_report_detail_auth_misc(self, app, user, contributor, non_contrib, private_project, payload, private_url, comment):
        # test_private_node_reported_contributor_cannot_delete_report_detail
        res = app.delete_json_api(private_url, auth=contributor.auth, expect_errors=True)
        assert res.status_code == 403

        # test_private_node_logged_in_non_contrib_cannot_delete_report_detail
        res = app.delete_json_api(private_url, auth=non_contrib.auth, expect_errors=True)
        assert res.status_code == 403

        # test_private_node_logged_out_contributor_cannot_delete_detail
        res = app.delete_json_api(private_url, expect_errors=True)
        assert res.status_code == 401

        # test_private_node_reporting_contributor_can_delete_report_detail
        comment_new = CommentFactory.build(node=private_project, user=contributor, target=comment.target)
        comment_new.reports = {user._id: {
            'category': 'spam',
            'text': 'This is spam',
            'date': timezone.now(),
            'retracted': False,
        }}
        comment_new.save()
        url = '/{}comments/{}/reports/{}/'.format(API_BASE, comment_new._id, user._id)
        res = app.delete_json_api(url, auth=user.auth)
        assert res.status_code == 204
示例#2
0
 def _set_up_public_project_comment_reports(self, comment_level='public'):
     self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level=comment_level)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     self.public_comment = CommentFactory.build(node=self.public_project, user=self.contributor)
     self.public_comment.reports = self.public_comment.reports or {}
     self.public_comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._id)
 def _set_up_public_project_comment_reports(self, comment_level='public'):
     self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level=comment_level)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     self.public_comment = CommentFactory.build(node=self.public_project, user=self.contributor)
     self.public_comment.reports = self.public_comment.reports or {}
     self.public_comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._id)
示例#4
0
 def _set_up_private_project_comment_reports(self):
     self.private_project = ProjectFactory.create(is_public=False, creator=self.user)
     self.private_project.add_contributor(contributor=self.contributor, save=True)
     self.file = test_utils.create_test_file(self.private_project, self.user)
     self.comment = CommentFactory.build(node=self.private_project, target=self.file.get_guid(), user=self.contributor)
     self.comment.reports = self.comment.reports or {}
     self.comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     self.comment.save()
     self.private_url = '/{}comments/{}/reports/'.format(API_BASE, self.comment._id)
 def _set_up_private_project_comment_reports(self):
     self.private_project = ProjectFactory.create(is_public=False, creator=self.user)
     self.private_project.add_contributor(contributor=self.contributor, save=True)
     self.file = test_utils.create_test_file(self.private_project, self.user)
     self.comment = CommentFactory.build(node=self.private_project, target=self.file.get_guid(), user=self.contributor)
     self.comment.reports = self.comment.reports or {}
     self.comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     self.comment.save()
     self.private_url = '/{}comments/{}/reports/'.format(API_BASE, self.comment._id)
示例#6
0
 def _set_up_public_project_comment_reports(self, comment_level='public'):
     self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level=comment_level)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     with mock.patch('osf.models.AbstractNode.update_search'):
         self.public_wiki = NodeWikiFactory(node=self.public_project, user=self.user)
     self.public_comment = CommentFactory.build(node=self.public_project, target=Guid.load(self.public_wiki._id), user=self.contributor)
     self.public_comment.reports = self.public_comment.reports or {}
     self.public_comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._id)
 def _set_up_public_project_comment_reports(self, comment_level='public'):
     self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level=comment_level)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     with mock.patch('osf.models.AbstractNode.update_search'):
         self.public_wiki = NodeWikiFactory(node=self.public_project, user=self.user)
     self.public_comment = CommentFactory.build(node=self.public_project, target=Guid.load(self.public_wiki._id), user=self.contributor)
     self.public_comment.reports = self.public_comment.reports or {}
     self.public_comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._id)
 def _set_up_private_project_comment_reports(self):
     self.private_project = ProjectFactory.create(is_public=False,
                                                  creator=self.user)
     self.private_project.add_contributor(contributor=self.contributor,
                                          save=True)
     self.comment = CommentFactory.build(node=self.private_project,
                                         user=self.contributor)
     self.comment.reports = {
         self.user._id: {
             'category': 'spam',
             'text': 'This is spam',
             'date': timezone.now(),
             'retracted': False,
         }
     }
     self.comment.save()
     self.private_url = '/{}comments/{}/reports/{}/'.format(
         API_BASE, self.comment._id, self.user._id)
 def test_private_node_reporting_contributor_can_delete_report_detail(self):
     self._set_up_private_project_comment_reports()
     comment = CommentFactory.build(node=self.private_project,
                                    user=self.contributor,
                                    target=self.comment.target)
     comment.reports = {
         self.user._id: {
             'category': 'spam',
             'text': 'This is spam',
             'date': timezone.now(),
             'retracted': False,
         }
     }
     comment.save()
     url = '/{}comments/{}/reports/{}/'.format(API_BASE, comment._id,
                                               self.user._id)
     res = self.app.delete_json_api(url, auth=self.user.auth)
     assert_equal(res.status_code, 204)
    def test_private_node_delete_report_detail_auth_misc(
            self, app, user, contributor, non_contrib,
            private_project, private_url, comment
    ):
        # test_private_node_reported_contributor_cannot_delete_report_detail
        res = app.delete_json_api(
            private_url, auth=contributor.auth,
            expect_errors=True
        )
        assert res.status_code == 403

        # test_private_node_logged_in_non_contrib_cannot_delete_report_detail
        res = app.delete_json_api(
            private_url, auth=non_contrib.auth,
            expect_errors=True
        )
        assert res.status_code == 403

        # test_private_node_logged_out_contributor_cannot_delete_detail
        res = app.delete_json_api(private_url, expect_errors=True)
        assert res.status_code == 401

        # test_private_node_reporting_contributor_can_delete_report_detail
        comment_new = CommentFactory.build(
            node=private_project,
            user=contributor,
            target=comment.target
        )
        comment_new.reports = {user._id: {
            'category': 'spam',
            'text': 'This is spam',
            'date': timezone.now(),
            'retracted': False,
        }}
        comment_new.save()
        url = '/{}comments/{}/reports/{}/'.format(
            API_BASE, comment_new._id, user._id)
        res = app.delete_json_api(url, auth=user.auth)
        assert res.status_code == 204