def public_comment(self, user, contributor, public_project):
     public_comment = CommentFactory(node=public_project, user=contributor)
     public_comment.reports = {user._id: {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }}
     public_comment.save()
     return public_comment
 def comment(self, user, contributor, private_project, wiki):
     comment = CommentFactory(node=private_project, target=Guid.load(wiki._id), user=contributor)
     comment.reports = {user._id: {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }}
     comment.save()
     return comment
 def public_comment(self, user, contributor, public_project, public_wiki):
     public_comment = CommentFactory(node=public_project, target=Guid.load(public_wiki._id), user=contributor)
     public_comment.reports = {user._id: {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }}
     public_comment.save()
     return public_comment
Exemplo n.º 4
0
 def comment(self, user, contributor, private_project, file):
     comment = CommentFactory(node=private_project, target=file.get_guid(), user=contributor)
     comment.reports = comment.reports or {}
     comment.reports[user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     comment.save()
     return comment
Exemplo n.º 5
0
 def public_comment(self, user, contributor, public_project, public_file):
     public_comment = CommentFactory(node=public_project, target=public_file.get_guid(), user=contributor)
     public_comment.reports = public_comment.reports or {}
     public_comment.reports[user._id] = {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }
     public_comment.save()
     return public_comment
 def comment(self, user, contributor, private_project, file):
     comment = CommentFactory(
         node=private_project,
         target=file.get_guid(),
         user=contributor)
     comment.reports = {user._id: {
         'category': 'spam',
         'text': 'This is spam',
         'date': timezone.now(),
         'retracted': False,
     }}
     comment.save()
     return comment
Exemplo n.º 7
0
 def test_private_node_only_logged_in_contributor_commenter_can_undelete_own_reply(
         self, app, user, private_project, comment, set_up_payload):
     reply_target = Guid.load(comment._id)
     reply = CommentFactory(node=private_project,
                            target=reply_target,
                            user=user)
     reply_url = '/{}comments/{}/'.format(API_BASE, reply._id)
     reply.is_deleted = True
     reply.save()
     payload = set_up_payload(reply._id, has_content=False)
     res = app.patch_json_api(reply_url, payload, auth=user.auth)
     assert res.status_code == 200
     assert not res.json['data']['attributes']['deleted']
     assert res.json['data']['attributes']['content'] == reply.content
Exemplo n.º 8
0
 def test_private_node_only_logged_in_contributor_commenter_can_undelete_own_reply(
         self, app, user, private_project, comment, set_up_payload):
     reply_target = Guid.load(comment._id)
     reply = CommentFactory(
         node=private_project,
         target=reply_target, user=user
     )
     reply_url = '/{}comments/{}/'.format(API_BASE, reply._id)
     reply.is_deleted = True
     reply.save()
     payload = set_up_payload(reply._id, has_content=False)
     res = app.patch_json_api(reply_url, payload, auth=user.auth)
     assert res.status_code == 200
     assert not res.json['data']['attributes']['deleted']
     assert res.json['data']['attributes']['content'] == reply.content
Exemplo n.º 9
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._id)
     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)
Exemplo n.º 10
0
    def test_populate_with_modified(self):
        statement = migrate_deleted_date.UPDATE_DELETED_WITH_MODIFIED
        table = 'osf_comment'
        user = UserFactory()
        project = ProjectFactory(creator=user)
        comment = CommentFactory(user=user, node=project)

        comment.delete(Auth(user), save=True)
        comment.reload()
        assert(comment.deleted)

        comment.deleted = None
        comment.save()
        migrate_deleted_date.run_statements(statement, 1000, table)
        comment.reload()
        assert(comment.deleted)
        assert(comment.deleted == comment.modified)
Exemplo n.º 11
0
class TestSpamMixin(OsfTestCase):

    def setUp(self):
        super(TestSpamMixin, self).setUp()
        self.comment = CommentFactory()
        self.auth = Auth(user=self.comment.user)

    def test_report_abuse(self):
        user = UserFactory()
        time = timezone.now()
        self.comment.report_abuse(
                user, date=time, category='spam', text='ads', save=True)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        equivalent = dict(
            date=time,
            category='spam',
            text='ads',
            retracted=False
        )
        assert_in(user._id, self.comment.reports)
        assert_equal(self.comment.reports[user._id], equivalent)

    def test_report_abuse_own_comment(self):
        with assert_raises(ValueError):
            self.comment.report_abuse(
                self.comment.user,
                category='spam', text='ads',
                save=True
            )
        assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)

    def test_retract_report(self):
        user = UserFactory()
        time = timezone.now()
        self.comment.report_abuse(
                user, date=time, category='spam', text='ads', save=True
        )
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        self.comment.retract_report(user, save=True)
        assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
        equivalent = {
            'date': time,
            'category': 'spam',
            'text': 'ads',
            'retracted': True
        }
        assert_in(user._id, self.comment.reports)
        assert_equal(self.comment.reports[user._id], equivalent)

    def test_retract_report_not_reporter(self):
        reporter = UserFactory()
        non_reporter = UserFactory()
        self.comment.report_abuse(
                reporter, category='spam', text='ads', save=True
        )
        with assert_raises(ValueError):
            self.comment.retract_report(non_reporter, save=True)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_retract_one_report_of_many(self):
        user_1 = UserFactory()
        user_2 = UserFactory()
        time = timezone.now()
        self.comment.report_abuse(
                user_1, date=time, category='spam', text='ads', save=True
        )
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        self.comment.report_abuse(
                user_2, date=time, category='spam', text='all', save=True
        )
        self.comment.retract_report(user_1, save=True)
        equivalent = {
            'date': time,
            'category': 'spam',
            'text': 'ads',
            'retracted': True
        }
        assert_in(user_1._id, self.comment.reports)
        assert_equal(self.comment.reports[user_1._id], equivalent)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_flag_spam(self):
        self.comment.flag_spam()
        self.comment.save()
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_cannot_remove_flag_not_retracted(self):
        user = UserFactory()
        self.comment.report_abuse(
                user, category='spam', text='ads', save=True
        )
        self.comment.remove_flag(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_remove_flag(self):
        self.comment.flag_spam()
        self.comment.save()
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        self.comment.remove_flag(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)

    def test_confirm_ham(self):
        self.comment.confirm_ham(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.HAM)

    def test_confirm_spam(self):
        self.comment.confirm_spam(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.SPAM)

    def test_validate_reports_bad_key(self):
        self.comment.reports[None] = {'category': 'spam', 'text': 'ads'}
        with assert_raises(ValidationError):
            self.comment.save()

    def test_validate_reports_bad_type(self):
        self.comment.reports[self.comment.user._id] = 'not a dict'
        with assert_raises(ValidationError):
            self.comment.save()

    def test_validate_reports_bad_value(self):
        self.comment.reports[self.comment.user._id] = {'foo': 'bar'}
        with assert_raises(ValidationError):
            self.comment.save()
Exemplo n.º 12
0
class TestSpamMixin(OsfTestCase):

    def setUp(self):
        super(TestSpamMixin, self).setUp()
        self.comment = CommentFactory()
        self.auth = Auth(user=self.comment.user)

    def test_report_abuse(self):
        user = UserFactory()
        time = timezone.now()
        self.comment.report_abuse(
            user, date=time, category='spam', text='ads', save=True)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        equivalent = dict(
            date=time,
            category='spam',
            text='ads',
            retracted=False
        )
        assert_in(user._id, self.comment.reports)
        assert_equal(self.comment.reports[user._id], equivalent)

    def test_report_abuse_own_comment(self):
        with assert_raises(ValueError):
            self.comment.report_abuse(
                self.comment.user,
                category='spam', text='ads',
                save=True
            )
        assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)

    def test_retract_report(self):
        user = UserFactory()
        time = timezone.now()
        self.comment.report_abuse(
            user, date=time, category='spam', text='ads', save=True
        )
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        self.comment.retract_report(user, save=True)
        assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)
        equivalent = {
            'date': time,
            'category': 'spam',
            'text': 'ads',
            'retracted': True
        }
        assert_in(user._id, self.comment.reports)
        assert_equal(self.comment.reports[user._id], equivalent)

    def test_retract_report_not_reporter(self):
        reporter = UserFactory()
        non_reporter = UserFactory()
        self.comment.report_abuse(
            reporter, category='spam', text='ads', save=True
        )
        with assert_raises(ValueError):
            self.comment.retract_report(non_reporter, save=True)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_retract_one_report_of_many(self):
        user_1 = UserFactory()
        user_2 = UserFactory()
        time = timezone.now()
        self.comment.report_abuse(
            user_1, date=time, category='spam', text='ads', save=True
        )
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        self.comment.report_abuse(
            user_2, date=time, category='spam', text='all', save=True
        )
        self.comment.retract_report(user_1, save=True)
        equivalent = {
            'date': time,
            'category': 'spam',
            'text': 'ads',
            'retracted': True
        }
        assert_in(user_1._id, self.comment.reports)
        assert_equal(self.comment.reports[user_1._id], equivalent)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_flag_spam(self):
        self.comment.flag_spam()
        self.comment.save()
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_cannot_remove_flag_not_retracted(self):
        user = UserFactory()
        self.comment.report_abuse(
            user, category='spam', text='ads', save=True
        )
        self.comment.remove_flag(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)

    def test_remove_flag(self):
        self.comment.flag_spam()
        self.comment.save()
        assert_equal(self.comment.spam_status, SpamStatus.FLAGGED)
        self.comment.remove_flag(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.UNKNOWN)

    def test_confirm_ham(self):
        self.comment.confirm_ham(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.HAM)

    def test_confirm_spam(self):
        self.comment.confirm_spam(save=True)
        assert_equal(self.comment.spam_status, SpamStatus.SPAM)

    def test_validate_reports_bad_key(self):
        self.comment.reports[None] = {'category': 'spam', 'text': 'ads'}
        with assert_raises(ValidationError):
            self.comment.save()

    def test_validate_reports_bad_type(self):
        self.comment.reports[self.comment.user._id] = 'not a dict'
        with assert_raises(ValidationError):
            self.comment.save()

    def test_validate_reports_bad_value(self):
        self.comment.reports[self.comment.user._id] = {'foo': 'bar'}
        with assert_raises(ValidationError):
            self.comment.save()