Beispiel #1
0
 def setUp(self):
     super(TestSpamDetail, self).setUp()
     self.comment = CommentFactory()
     self.comment.report_abuse(user=AuthUserFactory(), save=True,
                               category='spam')
     self.request = RequestFactory().post('/fake_path')
     self.request.user = UserFactory()
 def test_private_node_logged_out_user_cannot_see_deleted_comment(self):
     self._set_up_private_project_with_comment()
     comment = CommentFactory(node=self.private_project, target=self.private_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 401)
Beispiel #3
0
 def test_private_node_logged_out_user_cannot_see_deleted_comment(self):
     self._set_up_private_project_with_comment()
     comment = CommentFactory(node=self.private_project, target=self.private_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 401)
Beispiel #4
0
class TestSpamDetail(AdminTestCase):
    def setUp(self):
        super(TestSpamDetail, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True,
                                  category='spam')
        self.request = RequestFactory().post('/fake_path')
        self.request.user = UserFactory()

    def test_confirm_spam(self):
        form_data = {'confirm': str(SpamStatus.SPAM)}
        form = ConfirmForm(data=form_data)
        nt.assert_true(form.is_valid())
        view = SpamDetail()
        view = setup_form_view(
            view, self.request, form, spam_id=self.comment._id)
        with transaction.atomic():
            view.form_valid(form)
        obj = OSFLogEntry.objects.latest(field_name='action_time')
        nt.assert_equal(obj.object_id, self.comment._id)
        nt.assert_in('Confirmed SPAM:', obj.message())

    def test_confirm_ham(self):
        form_data = {'confirm': str(SpamStatus.HAM)}
        form = ConfirmForm(data=form_data)
        nt.assert_true(form.is_valid())
        view = SpamDetail()
        view = setup_form_view(
            view, self.request, form, spam_id=self.comment._id)
        with transaction.atomic():
            view.form_valid(form)
        obj = OSFLogEntry.objects.latest(field_name='action_time')
        nt.assert_equal(obj.object_id, self.comment._id)
        nt.assert_in('Confirmed HAM:', obj.message())

    def test_form_valid_bad_id(self):
        form = ConfirmForm()
        view = SpamDetail()
        view = setup_form_view(view, self.request, form, spam_id='a1')
        with nt.assert_raises(Http404):
            view.form_valid(form)

    def test_get_context_data(self):
        view = SpamDetail()
        view = setup_view(view, self.request, spam_id=self.comment._id)
        res = view.get_context_data()
        nt.assert_equal(res['status'], '1')
        nt.assert_equal(res['page_number'], '1')
        nt.assert_is_instance(res['comment'], dict)
        nt.assert_equal(res['SPAM_STATUS'].UNKNOWN, SpamStatus.UNKNOWN)
        nt.assert_equal(res['SPAM_STATUS'].SPAM, SpamStatus.SPAM)
        nt.assert_equal(res['SPAM_STATUS'].HAM, SpamStatus.HAM)
        nt.assert_equal(res['SPAM_STATUS'].FLAGGED, SpamStatus.FLAGGED)

    def test_get_context_data_bad_id(self):
        view = setup_view(SpamDetail(), self.request, spam_id='a1')
        with nt.assert_raises(Http404):
            view.get_context_data()
Beispiel #5
0
 def test_private_node_only_logged_in_commenter_can_view_deleted_comment(self):
     self._set_up_private_project_with_comment()
     comment = CommentFactory(node=self.private_project, target=self.private_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.user.auth)
     assert_equal(res.status_code, 200)
     assert_equal(res.json['data']['attributes']['content'], comment.content)
Beispiel #6
0
 def test_find_unread_includes_comment_replies(self):
     project = ProjectFactory()
     user = UserFactory()
     project.add_contributor(user)
     project.save()
     comment = CommentFactory(node=project, user=user)
     reply = CommentFactory(node=project, target=Guid.load(comment._id), user=project.creator)
     n_unread = Comment.find_n_unread(user=user, node=project, page='node')
     assert_equal(n_unread, 1)
Beispiel #7
0
 def test_public_node_non_contributor_cannot_view_other_users_deleted_comment(self):
     public_project = ProjectFactory(is_public=True, creator=self.user)
     comment = CommentFactory(node=public_project, target=public_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
Beispiel #8
0
 def test_private_node_contributor_cannot_see_other_users_deleted_file_comment(self):
     self._set_up_private_project_with_file_comment()
     comment = CommentFactory(node=self.private_project, target=self.file, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.contributor.auth)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
Beispiel #9
0
 def test_private_node_logged_out_user_cannot_see_deleted_file_comment(self):
     self._set_up_private_project_with_file_comment()
     comment = CommentFactory(node=self.private_project, target=self.file, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 401)
     assert_equal(res.json['errors'][0]['detail'], 'Authentication credentials were not provided.')
Beispiel #10
0
 def test_public_node_logged_out_user_cannot_view_deleted_file_comments(self):
     self._set_up_public_project_with_file_comment()
     comment = CommentFactory(node=self.public_project, target=self.public_file, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
 def _set_up_public_project_comment_reply(self):
     self.public_project = ProjectFactory(is_public=True, creator=self.user)
     self.public_comment = CommentFactory(node=self.public_project,
                                          user=self.user)
     self.public_comment_reply = CommentFactory(node=self.public_project,
                                                target=self.public_comment,
                                                user=self.user)
     self.public_url = '/{}comments/{}/replies/'.format(
         API_BASE, self.public_comment._id)
 def test_private_node_contributor_cannot_see_other_users_deleted_comment(self):
     self._set_up_private_project_with_comment()
     comment = CommentFactory(node=self.private_project, target=self.private_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.contributor.auth)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
 def test_public_node_logged_out_user_cannot_view_deleted_comments(self):
     public_project = ProjectFactory(is_public=True, creator=self.user)
     comment = CommentFactory(node=public_project, target=public_project, user=self.user)
     comment.is_deleted = True
     comment.save()
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url)
     assert_equal(res.status_code, 200)
     assert_is_none(res.json['data']['attributes']['content'])
 def _set_up_registration_comment_reply(self):
     self.registration = RegistrationFactory(creator=self.user)
     self.registration_comment = CommentFactory(node=self.registration,
                                                user=self.user)
     self.registration_comment_reply = CommentFactory(
         node=self.registration,
         target=self.registration_comment,
         user=self.user)
     self.registration_url = '/{}comments/{}/replies/'.format(
         API_BASE, self.registration_comment._id)
Beispiel #15
0
class TestSpamDetail(AdminTestCase):
    def setUp(self):
        super(TestSpamDetail, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True, category="spam")
        self.request = RequestFactory().post("/fake_path")
        self.request.user = UserFactory()

    def test_confirm_spam(self):
        form_data = {"confirm": str(Comment.SPAM)}
        form = ConfirmForm(data=form_data)
        nt.assert_true(form.is_valid())
        view = SpamDetail()
        view = setup_form_view(view, self.request, form, spam_id=self.comment._id)
        with transaction.atomic():
            view.form_valid(form)
        obj = OSFLogEntry.objects.latest(field_name="action_time")
        nt.assert_equal(obj.object_id, self.comment._id)
        nt.assert_in("Confirmed SPAM:", obj.message())

    def test_confirm_ham(self):
        form_data = {"confirm": str(Comment.HAM)}
        form = ConfirmForm(data=form_data)
        nt.assert_true(form.is_valid())
        view = SpamDetail()
        view = setup_form_view(view, self.request, form, spam_id=self.comment._id)
        with transaction.atomic():
            view.form_valid(form)
        obj = OSFLogEntry.objects.latest(field_name="action_time")
        nt.assert_equal(obj.object_id, self.comment._id)
        nt.assert_in("Confirmed HAM:", obj.message())

    def test_form_valid_bad_id(self):
        form = ConfirmForm()
        view = SpamDetail()
        view = setup_form_view(view, self.request, form, spam_id="a1")
        with nt.assert_raises(Http404):
            view.form_valid(form)

    def test_get_context_data(self):
        view = SpamDetail()
        view = setup_view(view, self.request, spam_id=self.comment._id)
        res = view.get_context_data()
        nt.assert_equal(res["status"], "1")
        nt.assert_equal(res["page_number"], "1")
        nt.assert_is_instance(res["comment"], dict)
        nt.assert_equal(res["UNKNOWN"], Comment.UNKNOWN)
        nt.assert_equal(res["SPAM"], Comment.SPAM)
        nt.assert_equal(res["HAM"], Comment.HAM)
        nt.assert_equal(res["FLAGGED"], Comment.FLAGGED)

    def test_get_context_data_bad_id(self):
        view = setup_view(SpamDetail(), self.request, spam_id="a1")
        with nt.assert_raises(Http404):
            view.get_context_data()
Beispiel #16
0
 def test_private_node_only_logged_in_contributor_commenter_can_undelete_own_reply(self):
     self._set_up_private_project_with_comment()
     reply_target = Guid.load(self.comment._id)
     reply = CommentFactory(node=self.private_project, target=reply_target, user=self.user)
     reply_url = '/{}comments/{}/'.format(API_BASE, reply)
     reply.is_deleted = True
     reply.save()
     payload = self._set_up_payload(reply._id, has_content=False)
     res = self.app.patch_json_api(reply_url, payload, auth=self.user.auth)
     assert_equal(res.status_code, 200)
     assert_false(res.json['data']['attributes']['deleted'])
     assert_equal(res.json['data']['attributes']['content'], reply.content)
Beispiel #17
0
class TestEmailView(AdminTestCase):
    def setUp(self):
        super(TestEmailView, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True,
                                  category='spam')
        self.request = RequestFactory().post('/fake_path')
        self.request.user = UserFactory()

    def test_get_object_bad_id(self):
        view = setup_view(EmailView(), self.request, spam_id='a1')
        with nt.assert_raises(Http404):
            view.get_object()
Beispiel #18
0
 def _set_up_registration_with_comment(self):
     self.registration = RegistrationFactory(creator=self.user)
     self.registration_url = '/{}registrations/{}/'.format(
         API_BASE, self.registration._id)
     self.registration_comment = CommentFactory(node=self.registration,
                                                user=self.user)
     self.comment_url = '/{}comments/{}/'.format(
         API_BASE, self.registration_comment._id)
     reply_target = Guid.load(self.registration_comment._id)
     self.registration_comment_reply = CommentFactory(
         node=self.registration, target=reply_target, user=self.user)
     self.replies_url = '/{}registrations/{}/comments/?filter[target]={}'.format(
         API_BASE, self.registration._id, self.registration_comment._id)
Beispiel #19
0
 def _set_up_registration_with_comment(self):
     self.registration = RegistrationFactory(creator=self.user,
                                             comment_level='private')
     self.registration_file = test_utils.create_test_file(
         self.registration, self.user)
     self.registration_comment = CommentFactory(
         node=self.registration,
         target=self.registration_file.get_guid(),
         user=self.user)
     self.comment_url = '/{}comments/{}/'.format(
         API_BASE, self.registration_comment._id)
     reply_target = Guid.load(self.registration_comment._id)
     self.registration_comment_reply = CommentFactory(
         node=self.registration, target=reply_target, user=self.user)
Beispiel #20
0
 def _set_up_registration_with_comment(self):
     self.registration = RegistrationFactory(creator=self.user,
                                             comment_level='private')
     self.registration_wiki = NodeWikiFactory(node=self.registration,
                                              user=self.user)
     self.registration_comment = CommentFactory(
         node=self.registration,
         target=Guid.load(self.registration_wiki._id),
         user=self.user)
     self.comment_url = '/{}comments/{}/'.format(
         API_BASE, self.registration_comment._id)
     reply_target = Guid.load(self.registration_comment._id)
     self.registration_comment_reply = CommentFactory(
         node=self.registration, target=reply_target, user=self.user)
Beispiel #21
0
 def _set_up_public_project_with_comment(self):
     self.public_project = ProjectFactory.create(is_public=True,
                                                 creator=self.user)
     self.public_project.add_contributor(self.contributor, save=True)
     self.public_comment = CommentFactory(node=self.public_project,
                                          user=self.user)
     reply_target = Guid.load(self.public_comment._id)
     self.public_comment_reply = CommentFactory(node=self.public_project,
                                                target=reply_target,
                                                user=self.user)
     self.public_url = '/{}comments/{}/'.format(API_BASE,
                                                self.public_comment._id)
     self.public_comment_payload = self._set_up_payload(
         self.public_comment._id)
 def test_public_node_private_comment_level_non_contributor_cannot_see_reports(self):
     project = ProjectFactory(is_public=True, creator=self.user, comment_level='private')
     comment = CommentFactory(node=project, user=self.user)
     comment.reports = dict()
     comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': datetime.utcnow(),
         'retracted': False,
     }
     comment.save()
     url = '/{}comments/{}/reports/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth, expect_errors=True)
     assert_equal(res.status_code, 403)
     assert_equal(res.json['errors'][0]['detail'], 'You do not have permission to perform this action.')
Beispiel #23
0
 def test_public_node_private_comment_level_non_contributor_cannot_see_reports(self):
     project = ProjectFactory(is_public=True, creator=self.user, comment_level='private')
     comment = CommentFactory(node=project, target=project, user=self.user)
     comment.reports = dict()
     comment.reports[self.user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': datetime.utcnow(),
         'retracted': False,
     }
     comment.save()
     url = '/{}comments/{}/reports/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth, expect_errors=True)
     assert_equal(res.status_code, 403)
     assert_equal(res.json['errors'][0]['detail'], 'You do not have permission to perform this action.')
 def test_public_node_private_comment_level_non_contributor_cannot_see_reports(self):
     project = ProjectFactory(is_public=True, creator=self.user, comment_level="private")
     comment = CommentFactory(node=project, target=project, user=self.user)
     comment.reports = dict()
     comment.reports[self.user._id] = {
         "category": "spam",
         "text": "This is spam",
         "date": datetime.utcnow(),
         "retracted": False,
     }
     comment.save()
     url = "/{}comments/{}/reports/".format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.non_contributor.auth, expect_errors=True)
     assert_equal(res.status_code, 403)
     assert_equal(res.json["errors"][0]["detail"], "You do not have permission to perform this action.")
 def _set_up_public_project_with_comment(self):
     self.public_project = ProjectFactory.build(is_public=True, creator=self.user)
     self.public_project.add_contributor(self.contributor, save=True)
     self.public_comment = CommentFactory(node=self.public_project, target=self.public_project, user=self.user)
     self.public_url = '/{}comments/{}/'.format(API_BASE, self.public_comment._id)
     self.public_comment_payload = {
         'data': {
             'id': self.public_comment._id,
             'type': 'comments',
             'attributes': {
                 'content': 'Updating this comment',
                 'deleted': False
             }
         }
     }
Beispiel #26
0
 def test_private_node_only_logged_in_contributor_commenter_can_undelete_own_reply(
         self):
     self._set_up_private_project_with_comment()
     reply_target = Guid.load(self.comment._id)
     reply = CommentFactory(node=self.private_project,
                            target=reply_target,
                            user=self.user)
     reply_url = '/{}comments/{}/'.format(API_BASE, reply)
     reply.is_deleted = True
     reply.save()
     payload = self._set_up_payload(reply._id, has_content=False)
     res = self.app.patch_json_api(reply_url, payload, auth=self.user.auth)
     assert_equal(res.status_code, 200)
     assert_false(res.json['data']['attributes']['deleted'])
     assert_equal(res.json['data']['attributes']['content'], reply.content)
 def _set_up_public_project_with_public_comment_level(self):
     self.public_project_with_public_comment_level = ProjectFactory(
         is_public=True, creator=self.user, comment_level='public')
     self.public_project_with_public_comment_level.add_contributor(
         self.read_only_contributor, permissions=['read'], save=True)
     comment = CommentFactory(
         node=self.public_project_with_public_comment_level, user=self.user)
     reply = CommentFactory(
         node=self.public_project_with_public_comment_level,
         target=comment,
         user=self.user)
     self.public_project_with_public_comment_level_url = '/{}nodes/{}/comments/'.format(
         API_BASE, self.public_project_with_public_comment_level._id)
     self.public_project_with_public_comment_level_payload = self._set_up_payload(
         reply._id)
 def test_public_node_non_contributor_commenter_can_delete_wiki_comment(self):
     project = ProjectFactory(is_public=True, comment_level='public')
     test_wiki = NodeWikiFactory(node=project, user=self.user)
     comment = CommentFactory(node=project, target=Guid.load(test_wiki), user=self.non_contributor)
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.delete_json_api(url, auth=self.non_contributor.auth)
     assert_equal(res.status_code, 204)
Beispiel #29
0
 def _set_up_public_project_with_file_comment(self):
     self.public_project = ProjectFactory.build(is_public=True, creator=self.user, comment_level='private')
     self.public_project.add_contributor(self.contributor, save=True)
     self.public_file = test_utils.create_test_file(self.public_project, self.user)
     self.public_comment = CommentFactory(node=self.public_project, target=self.public_file, user=self.user)
     self.public_url = '/{}comments/{}/'.format(API_BASE, self.public_comment._id)
     self.public_comment_payload = self._set_up_payload(self.public_comment._id)
 def _set_up_private_project_with_comment(self):
     self.private_project = ProjectFactory.create(is_public=False, creator=self.user, comment_level='private')
     self.private_project.add_contributor(self.contributor, save=True)
     self.wiki = NodeWikiFactory(node=self.private_project, user=self.user)
     self.comment = CommentFactory(node=self.private_project, target=Guid.load(self.wiki._id), user=self.user)
     self.private_url = '/{}comments/{}/'.format(API_BASE, self.comment._id)
     self.payload = self._set_up_payload(self.comment._id)
    def test_update_default_modified_updates_all_targets(self):
        comment = CommentFactory(modified=None)
        targets = get_targets()
        assert_equal(targets.count(), 1)

        do_migration(get_targets())
        assert_equal(targets.count(), 0)
Beispiel #32
0
 def test_private_node_logged_in_contributor_can_report_comment(self):
     self._set_up_private_project_comment_reports()
     comment = CommentFactory(node=self.private_project, user=self.contributor)
     url = '/{}comments/{}/reports/'.format(API_BASE, comment._id)
     res = self.app.post_json_api(url, self.payload, auth=self.user.auth)
     assert_equal(res.status_code, 201)
     assert_equal(res.json['data']['id'], self.user._id)
 def _set_up_public_project_with_comment(self):
     self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level='private')
     self.public_project.add_contributor(self.contributor, save=True)
     self.public_file = test_utils.create_test_file(self.public_project, self.user)
     self.public_comment = CommentFactory(node=self.public_project, target=self.public_file.get_guid(), user=self.user)
     self.public_url = '/{}comments/{}/'.format(API_BASE, self.public_comment._id)
     self.public_comment_payload = self._set_up_payload(self.public_comment._id)
 def test_public_node_non_contributor_commenter_can_delete_file_comment(self):
     project = ProjectFactory(is_public=True, comment_level='public')
     test_file = test_utils.create_test_file(project, project.creator)
     comment = CommentFactory(node=project, target=test_file.get_guid(), user=self.non_contributor)
     url = '/{}comments/{}/'.format(API_BASE, comment._id)
     res = self.app.delete_json_api(url, auth=self.non_contributor.auth)
     assert_equal(res.status_code, 204)
Beispiel #35
0
 def setUp(self):
     super(TestEmailFormView, self).setUp()
     self.comment = CommentFactory()
     self.comment.report_abuse(user=AuthUserFactory(), save=True,
                               category='spam')
     self.request = RequestFactory().post('/fake_path')
     self.request.user = UserFactory()
     self.view = EmailFormView()
     self.form = EmailForm(data={
         'author': 'Nemo',
         'message': 'A message for spammers.',
         'subject': 'stop spamming',
         'email': ('*****@*****.**', '*****@*****.**')
     })
     self.view = setup_form_view(self.view, self.request, self.form,
                                 spam_id=self.comment._id)
 def _set_up_private_project_with_comment(self):
     self.private_project = ProjectFactory(is_public=False,
                                           creator=self.user)
     self.comment = CommentFactory(node=self.private_project,
                                   user=self.user)
     self.private_url = '/{}nodes/{}/comments/'.format(
         API_BASE, self.private_project._id)
Beispiel #37
0
 def test_redirect_to_comment_view(self):
     comment = CommentFactory()
     url = '/{}guids/{}/'.format(API_BASE, comment._id)
     res = self.app.get(url, auth=self.user.auth)
     redirect_url = '{}{}comments/{}/'.format(API_DOMAIN, API_BASE, comment._id)
     assert_equal(res.status_code, 302)
     assert_equal(res.location, redirect_url)
Beispiel #38
0
 def _set_up_public_project_comment_reports(self):
     self.public_project = ProjectFactory.build(is_public=True, creator=self.user)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     self.public_comment = CommentFactory.build(node=self.public_project, target=self.public_project, user=self.contributor)
     self.public_comment.reports = {self.user._id: {'category': 'spam', 'text': 'This is spam'}}
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/{}/'.format(API_BASE, self.public_comment._id, self.user._id)
 def _set_up_public_project_comment_reports(self):
     self.public_project = ProjectFactory.build(is_public=True, creator=self.user)
     self.public_project.add_contributor(contributor=self.contributor, save=True)
     self.public_comment = CommentFactory.build(node=self.public_project, target=self.public_project, user=self.contributor)
     self.public_comment.reports = {self.user._id: {'category': 'spam', 'text': 'This is spam'}}
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/{}/'.format(API_BASE, self.public_comment._id, self.user._id)
 def test_public_node_reporting_contributor_can_delete_detail(self):
     self._set_up_public_project_file_comment_reports()
     comment = CommentFactory.build(node=self.public_project, target=self.public_file, user=self.contributor)
     comment.reports = {self.user._id: {'category': 'spam', 'text': 'This is spam'}}
     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)
Beispiel #41
0
 def test_public_node_reporting_contributor_can_delete_detail(self):
     self._set_up_public_project_comment_reports()
     comment = CommentFactory.build(node=self.public_project, target=self.public_project, user=self.contributor)
     comment.reports = {self.user._id: {'category': 'spam', 'text': 'This is spam'}}
     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_public_node_logged_in_non_contributor_reporter_can_view_report_detail(self):
     project = ProjectFactory(is_public=True, comment_level='public')
     comment = CommentFactory.build(node=project, user=project.creator)
     comment.reports = {self.non_contributor._id: {'category': 'spam', 'text': 'This is spam'}}
     comment.save()
     url = '/{}comments/{}/reports/{}/'.format(API_BASE, comment._id, self.non_contributor._id)
     res = self.app.get(url, auth=self.non_contributor.auth)
     assert_equal(res.status_code, 200)
 def test_cannot_access_withdrawn_comments(self):
     self.public_project = ProjectFactory(is_public=True, creator=self.user)
     self.public_comment = CommentFactory(node=self.public_project,
                                          user=self.user)
     url = '/{}registrations/{}/comments/'.format(API_BASE,
                                                  self.registration._id)
     res = self.app.get(url, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, 403)
Beispiel #44
0
 def test_public_node_logged_in_non_contributor_reporter_can_view_report_detail(self):
     project = ProjectFactory(is_public=True, comment_level='public')
     comment = CommentFactory.build(node=project, user=project.creator)
     comment.reports = {self.non_contributor._id: {'category': 'spam', 'text': 'This is spam'}}
     comment.save()
     url = '/{}comments/{}/reports/{}/'.format(API_BASE, comment._id, self.non_contributor._id)
     res = self.app.get(url, auth=self.non_contributor.auth)
     assert_equal(res.status_code, 200)
 def _set_up_private_project_file_comment_reports(self):
     self.private_project = ProjectFactory.build(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, user=self.contributor)
     self.comment.reports = self.comment.reports or {}
     self.comment.reports[self.user._id] = {'category': 'spam', 'text': 'This is spam'}
     self.comment.save()
     self.private_url = '/{}comments/{}/reports/'.format(API_BASE, self.comment._id)
Beispiel #46
0
    def test_find_unread_includes_edited_comments(self):
        project = ProjectFactory()
        user = AuthUserFactory()
        project.add_contributor(user)
        project.save()
        comment = CommentFactory(node=project, user=project.creator)

        url = project.api_url_for("update_comments_timestamp")
        payload = {"page": "node", "rootId": project._id}
        res = self.app.put_json(url, payload, auth=user.auth)
        user.reload()
        n_unread = Comment.find_n_unread(user=user, node=project, page="node")
        assert_equal(n_unread, 0)

        # Edit previously read comment
        comment.edit(auth=Auth(project.creator), content="edited", save=True)
        n_unread = Comment.find_n_unread(user=user, node=project, page="node")
        assert_equal(n_unread, 1)
Beispiel #47
0
class TestEmailFormView(AdminTestCase):
    def setUp(self):
        super(TestEmailFormView, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True, category="spam")
        self.request = RequestFactory().post("/fake_path")
        self.request.user = UserFactory()
        self.view = EmailFormView()
        self.form = EmailForm(
            data={
                "author": "Nemo",
                "message": "A message for spammers.",
                "subject": "stop spamming",
                "email": ("*****@*****.**", "*****@*****.**"),
            }
        )
        self.view = setup_form_view(self.view, self.request, self.form, spam_id=self.comment._id)

    @mock.patch("admin.spam.views.render")
    def test_get_context_data(self, mock_render):
        res = self.view.get_context_data()
        nt.assert_equal(res["status"], "1")
        nt.assert_equal(res["page_number"], "1")
        nt.assert_is_instance(res["comment"], dict)

    def test_get_context_data_bad_id(self):
        view = setup_view(EmailFormView(), self.request, spam_id="a1")
        with nt.assert_raises(Http404):
            view.get_context_data()

    @mock.patch("admin.spam.views.render")
    def test_get_initial(self, mock_render):
        self.view.get_initial()
        res = self.view.initial
        nt.assert_is_instance(res, dict)
        nt.assert_is_instance(res["email"], list)
        nt.assert_is_instance(res["email"][0], tuple)

    def test_get_initial_bad_id(self):
        view = setup_view(EmailFormView(), self.request, spam_id="a1")
        with nt.assert_raises(Http404):
            view.get_initial()
Beispiel #48
0
class TestEmailFormView(AdminTestCase):
    def setUp(self):
        super(TestEmailFormView, self).setUp()
        self.comment = CommentFactory()
        self.comment.report_abuse(user=AuthUserFactory(), save=True,
                                  category='spam')
        self.request = RequestFactory().post('/fake_path')
        self.request.user = UserFactory()
        self.view = EmailFormView()
        self.form = EmailForm(data={
            'author': 'Nemo',
            'message': 'A message for spammers.',
            'subject': 'stop spamming',
            'email': ('*****@*****.**', '*****@*****.**')
        })
        self.view = setup_form_view(self.view, self.request, self.form,
                                    spam_id=self.comment._id)

    @mock.patch('admin.spam.views.render')
    def test_get_context_data(self, mock_render):
        res = self.view.get_context_data()
        nt.assert_equal(res['status'], '1')
        nt.assert_equal(res['page_number'], '1')
        nt.assert_is_instance(res['comment'], dict)

    def test_get_context_data_bad_id(self):
        view = setup_view(EmailFormView(), self.request, spam_id='a1')
        with nt.assert_raises(Http404):
            view.get_context_data()

    @mock.patch('admin.spam.views.render')
    def test_get_initial(self, mock_render):
        self.view.get_initial()
        res = self.view.initial
        nt.assert_is_instance(res, dict)
        nt.assert_is_instance(res['email'], list)
        nt.assert_is_instance(res['email'][0], tuple)

    def test_get_initial_bad_id(self):
        view = setup_view(EmailFormView(), self.request, spam_id='a1')
        with nt.assert_raises(Http404):
            view.get_initial()
    def setUp(self):
        super(TestCommentFiltering, self).setUp()
        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.comment = CommentFactory(node=self.project, user=self.user)
        self.deleted_comment = CommentFactory(node=self.project, user=self.user, is_deleted=True)
        self.base_url = "/{}nodes/{}/comments/".format(API_BASE, self.project._id)

        self.formatted_date_created = self.comment.date_created.strftime("%Y-%m-%dT%H:%M:%S.%f")
        self.comment.edit("Edited comment", auth=core.Auth(self.user), save=True)
        self.formatted_date_modified = self.comment.date_modified.strftime("%Y-%m-%dT%H:%M:%S.%f")
 def _set_up_private_project_comment_reports(self):
     self.private_project = ProjectFactory.build(is_public=False, creator=self.user)
     self.private_project.add_contributor(contributor=self.contributor, save=True)
     self.comment = CommentFactory.build(node=self.private_project, target=self.private_project, user=self.contributor)
     self.comment.reports = {self.user._id: {
         'category': 'spam',
         'text': 'This is spam',
         'date': datetime.utcnow(),
         'retracted': False,
     }}
     self.comment.save()
     self.private_url = '/{}comments/{}/reports/{}/'.format(API_BASE, self.comment._id, self.user._id)
    def setUp(self):
        super(TestCommentRepliesFiltering, self).setUp()
        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.comment = CommentFactory(node=self.project, user=self.user)
        self.reply = CommentFactory(node=self.project, target=self.comment, user=self.user)
        self.deleted_reply = CommentFactory(node=self.project, target=self.comment, user=self.user, is_deleted=True)
        self.base_url = '/{}comments/{}/replies/'.format(API_BASE, self.comment._id)

        self.formatted_date_created = self.reply.date_created.strftime('%Y-%m-%dT%H:%M:%S.%f')
        self.reply.edit('Edited comment', auth=core.Auth(self.user), save=True)
        self.formatted_date_modified = self.reply.date_modified.strftime('%Y-%m-%dT%H:%M:%S.%f')
Beispiel #52
0
 def setUp(self):
     super(TestUserSpamListView, self).setUp()
     self.project = ProjectFactory(is_public=True)
     self.user_1 = AuthUserFactory()
     self.user_2 = AuthUserFactory()
     self.project.add_contributor(self.user_1)
     self.project.add_contributor(self.user_2)
     self.project.save()
     self.user_2.save()
     self.user_1.save()
     self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_1.report_abuse(user=self.user_2, save=True,
                                 category='spam')
     self.comment_2.report_abuse(user=self.user_2, save=True,
                                 category='spam')
     self.comment_3.report_abuse(user=self.user_2, save=True,
                                 category='spam')
     self.comment_4.report_abuse(user=self.user_2, save=True,
                                 category='spam')
     self.comment_5.report_abuse(user=self.user_1, save=True,
                                 category='spam')
     self.comment_6.report_abuse(user=self.user_1, save=True,
                                 category='spam')
Beispiel #53
0
 def setUp(self):
     super(TestSpamListView, self).setUp()
     Comment.remove()
     self.project = ProjectFactory(is_public=True)
     self.user_1 = AuthUserFactory()
     self.user_2 = AuthUserFactory()
     self.project.add_contributor(self.user_1)
     self.project.add_contributor(self.user_2)
     self.project.save()
     self.user_1.save()
     self.user_2.save()
     date = datetime.utcnow()
     self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_1.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=5))
     self.comment_2.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=4))
     self.comment_3.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=3))
     self.comment_4.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=2))
     self.comment_5.report_abuse(user=self.user_1, save=True, category="spam", date=date - timedelta(seconds=1))
     self.comment_6.report_abuse(user=self.user_1, save=True, category="spam")
     self.request = RequestFactory().get("/fake_path")
     self.view = SpamList()
     self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
Beispiel #54
0
 def setUp(self):
     super(TestUserSpamListView, self).setUp()
     self.project = ProjectFactory(is_public=True)
     self.user_1 = AuthUserFactory()
     self.user_2 = AuthUserFactory()
     self.project.add_contributor(self.user_1)
     self.project.add_contributor(self.user_2)
     self.project.save()
     self.user_1.save()
     self.user_2.save()
     self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_1.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_2.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_3.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_4.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_5.report_abuse(user=self.user_1, save=True, category="spam")
     self.comment_6.report_abuse(user=self.user_1, save=True, category="spam")
     self.request = RequestFactory().get("/fake_path")
     self.view = UserSpamList()
     self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
Beispiel #55
0
 def setUp(self):
     super(TestMigrateSpam, self).setUp()
     self.generic_report = {
         'category': 'spam',
         'text': 'spammer spam',
         'date': datetime.utcnow(),
         'retracted': False
     }
     Comment.remove()
     self.user = AuthUserFactory()
     self.comment_1 = CommentFactory()
     self.comment_1.spam_status = 0
     self.comment_1.reports[self.user._id] = self.generic_report
     self.comment_1.save()
     self.comment_2 = CommentFactory()
     self.comment_2.spam_status = 0
     self.comment_2.reports[self.user._id] = self.generic_report
     self.comment_2.save()
     self.comment_3 = CommentFactory()
     self.comment_3.spam_status = 0
     self.comment_3.save()
     self.comment_4 = CommentFactory()
     self.comment_4.date_last_reported = None
     self.comment_4.spam_status = Comment.FLAGGED
     self.comment_4.reports[self.user._id] = self.generic_report
     self.comment_4.save()
     self.comment_5 = CommentFactory()
     self.comment_5.date_last_reported = None
     self.comment_5.spam_status = Comment.UNKNOWN
     self.comment_5.save()
     self.comment_6 = CommentFactory()
     self.comment_6.date_last_reported = None
     self.comment_6.spam_status = Comment.SPAM
     self.comment_6.reports[self.user._id] = self.generic_report
     self.comment_6.save()
 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': datetime.utcnow(),
         'retracted': False,
     }
     self.public_comment.save()
     self.public_url = '/{}comments/{}/reports/'.format(API_BASE, self.public_comment._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, target=self.private_project, user=self.contributor)
     comment.reports = {self.user._id: {
         'category': 'spam',
         'text': 'This is spam',
         'date': datetime.utcnow(),
         '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)