def testCommentReports(self):
        self.login(u'allie')
        allie_user, natalie_user = self.query_for_users()
        allie_id = allie_user.id

        media_entry = fixture_media_entry(uploader=natalie_user.id,
            state=u'processed')
        mid = media_entry.id
        fixture_add_comment(media_entry=mid,
            author=natalie_user.id)
        comment = MediaComment.query.first()

        comment_uri_slug = '/u/{0}/m/{1}/c/{2}/'.format(natalie_user.username,
                                                media_entry.slug,
                                                comment.id)

        response = self.test_app.get(comment_uri_slug + "report/")
        assert response.status == "200 OK"

        response, context = self.do_post({
            'report_reason':u'Testing Comment Report',
            'reporter_id':unicode(allie_id)},url= comment_uri_slug + "report/")

        assert response.status == "302 FOUND"

        comment_report = CommentReport.query.first()

        allie_user, natalie_user = self.query_for_users()
        assert comment_report is not None
        assert comment_report.report_content == u'Testing Comment Report'
        assert comment_report.reporter_id == allie_id
        assert comment_report.reported_user_id == natalie_user.id
        assert comment_report.created is not None
        assert comment_report.discriminator == 'comment_report'
Example #2
0
    def testCommentReports(self):
        self.login('allie')
        allie_user, natalie_user = self.query_for_users()
        allie_id = allie_user.id

        media_entry = fixture_media_entry(uploader=natalie_user.id,
                                          state='processed')
        mid = media_entry.id
        fixture_add_comment(media_entry=media_entry, author=natalie_user.id)
        comment = TextComment.query.first()

        comment_uri_slug = '/u/{}/m/{}/c/{}/'.format(natalie_user.username,
                                                     media_entry.slug,
                                                     comment.id)

        response = self.test_app.get(comment_uri_slug + "report/")
        assert response.status == "200 OK"

        response, context = self.do_post(
            {
                'report_reason': 'Testing Comment Report',
                'reporter_id': str(allie_id)
            },
            url=comment_uri_slug + "report/")

        assert response.status == "302 FOUND"

        comment_report = Report.query.first()

        allie_user, natalie_user = self.query_for_users()
        assert comment_report is not None
        assert comment_report.report_content == 'Testing Comment Report'
        assert comment_report.reporter_id == allie_id
        assert comment_report.reported_user_id == natalie_user.id
        assert comment_report.created is not None
Example #3
0
    def testArchivingReports(self):
        self.login(u'natalie')
        allie_user, natalie_user = self.query_for_users()
        allie_id, natalie_id = allie_user.id, natalie_user.id

        fixture_add_comment(author=allie_user.id,
                            comment=u'Comment will be removed')
        test_comment = MediaComment.query.filter(
            MediaComment.author == allie_user.id).first()
        fixture_add_comment_report(
            comment=test_comment,
            reported_user=allie_user,
            report_content=u'Testing Archived Reports #1',
            reporter=natalie_user)
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user == allie_user).first()

        assert comment_report.report_content == u'Testing Archived Reports #1'
        response, context = self.do_post(
            {
                'action_to_resolve': [u'userban', u'delete'],
                'targeted_user': allie_user.id,
                'resolution_content': u'This is a test of archiving reports.'
            },
            url='/mod/reports/{0}/'.format(comment_report.id))

        assert response.status == "302 FOUND"
        allie_user, natalie_user = self.query_for_users()

        archived_report = CommentReport.query.filter(
            CommentReport.reported_user == allie_user).first()

        assert CommentReport.query.count() != 0
        assert archived_report is not None
        assert archived_report.report_content == u'Testing Archived Reports #1'
        assert archived_report.reporter_id == natalie_id
        assert archived_report.reported_user_id == allie_id
        assert archived_report.created is not None
        assert archived_report.resolved is not None
        assert archived_report.result == u'''This is a test of archiving reports.
natalie banned user allie indefinitely.
natalie deleted the comment.'''
        assert archived_report.discriminator == 'comment_report'
    def testArchivingReports(self):
        self.login(u'natalie')
        allie_user, natalie_user = self.query_for_users()
        allie_id, natalie_id = allie_user.id, natalie_user.id

        fixture_add_comment(author=allie_user.id,
            comment=u'Comment will be removed')
        test_comment = MediaComment.query.filter(
            MediaComment.author==allie_user.id).first()
        fixture_add_comment_report(comment=test_comment,
            reported_user=allie_user,
            report_content=u'Testing Archived Reports #1',
            reporter=natalie_user)
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==allie_user).first()

        assert comment_report.report_content == u'Testing Archived Reports #1'
        response, context = self.do_post(
            {'action_to_resolve':[u'userban', u'delete'],
            'targeted_user':allie_user.id,
            'resolution_content':u'This is a test of archiving reports.'},
            url='/mod/reports/{0}/'.format(comment_report.id))

        assert response.status == "302 FOUND"
        allie_user, natalie_user = self.query_for_users()

        archived_report = CommentReport.query.filter(
            CommentReport.reported_user==allie_user).first()

        assert CommentReport.query.count() != 0
        assert archived_report is not None
        assert archived_report.report_content == u'Testing Archived Reports #1'
        assert archived_report.reporter_id == natalie_id
        assert archived_report.reported_user_id == allie_id
        assert archived_report.created is not None
        assert archived_report.resolved is not None
        assert archived_report.result == u'''This is a test of archiving reports.
natalie banned user allie indefinitely.
natalie deleted the comment.'''
        assert archived_report.discriminator == 'comment_report'
Example #5
0
    def testArchivingReports(self):
        self.login('natalie')
        allie_user, natalie_user = self.query_for_users()
        allie_id, natalie_id = allie_user.id, natalie_user.id

        fixture_add_comment(author=allie_user.id,
                            comment='Comment will be removed')
        test_comment = TextComment.query.filter(
            TextComment.actor == allie_user.id).first()
        fixture_add_comment_report(
            comment=test_comment,
            reported_user=allie_user,
            report_content='Testing Archived Reports #1',
            reporter=natalie_user)
        comment_report = Report.query.filter(
            Report.reported_user == allie_user).first()

        assert comment_report.report_content == 'Testing Archived Reports #1'
        response, context = self.do_post(
            {
                'action_to_resolve': ['userban', 'delete'],
                'targeted_user': allie_user.id,
                'resolution_content': 'This is a test of archiving reports.'
            },
            url='/mod/reports/{}/'.format(comment_report.id))

        assert response.status == "302 FOUND"
        allie_user, natalie_user = self.query_for_users()

        archived_report = Report.query.filter(
            Report.reported_user == allie_user).first()

        assert Report.query.count() != 0
        assert archived_report is not None
        assert archived_report.report_content == 'Testing Archived Reports #1'
        assert archived_report.reporter_id == natalie_id
        assert archived_report.reported_user_id == allie_id
        assert archived_report.created is not None
        assert archived_report.resolved is not None
        assert archived_report.result == '''This is a test of archiving reports.
    def testReportResolution(self):
        self.login(u'moderator')

        # First, test a moderators taking away a user's privilege in response
        # to a reported comment
        #----------------------------------------------------------------------
        fixture_add_comment_report(reported_user=self.user)
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==self.user).first()

        response = self.test_app.get('/mod/reports/{0}/'.format(
            comment_report.id))
        assert response.status == '200 OK'
        self.query_for_users()
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==self.user).first()

        response, context = self.do_post({'action_to_resolve':[u'takeaway'],
            'take_away_privileges':[u'commenter'],
            'targeted_user':self.user.id},
            url='/mod/reports/{0}/'.format(comment_report.id))

        self.query_for_users()
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==self.user).first()
        assert response.status == '302 FOUND'
        assert not self.user.has_privilege(u'commenter')
        assert comment_report.is_archived_report() is True

        fixture_add_comment_report(reported_user=self.user)
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==self.user).first()

        # Then, test a moderator sending an email to a user in response to a
        # reported comment
        #----------------------------------------------------------------------
        self.query_for_users()

        response, context = self.do_post({'action_to_resolve':[u'sendmessage'],
            'message_to_user':'******',
            'targeted_user':self.user.id},
            url='/mod/reports/{0}/'.format(comment_report.id))

        self.query_for_users()
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==self.user).first()
        assert response.status == '302 FOUND'
        assert mail.EMAIL_TEST_MBOX_INBOX ==  [{'to': [u'*****@*****.**'],
            'message': 'Content-Type: text/plain; charset="utf-8"\n\
MIME-Version: 1.0\nContent-Transfer-Encoding: base64\nSubject: Warning from- \
moderator \nFrom: [email protected]\nTo: [email protected]\n\n\
VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
            'from': '*****@*****.**'}]
        assert comment_report.is_archived_report() is True

        # Then test a moderator banning a user AND a moderator deleting the
        # offending comment. This also serves as a test for taking multiple
        # actions to resolve a report
        #----------------------------------------------------------------------
        self.query_for_users()
        fixture_add_comment(author=self.user.id,
            comment=u'Comment will be removed')
        test_comment = MediaComment.query.filter(
            MediaComment.author==self.user.id).first()
        fixture_add_comment_report(comment=test_comment,
            reported_user=self.user)
        comment_report = CommentReport.query.filter(
            CommentReport.comment==test_comment).filter(
            CommentReport.resolved==None).first()

        response, context = self.do_post(
            {'action_to_resolve':[u'userban', u'delete'],
            'targeted_user':self.user.id,
            'why_user_was_banned':u'',
            'user_banned_until':u''},
            url='/mod/reports/{0}/'.format(comment_report.id))
        assert response.status == '302 FOUND'
        self.query_for_users()
        test_user_ban = UserBan.query.filter(
            UserBan.user_id == self.user.id).first()
        assert test_user_ban is not None
        test_comment = MediaComment.query.filter(
            MediaComment.author==self.user.id).first()
        assert test_comment is None

        # Then, test what happens when a moderator attempts to punish an admin
        # from a reported comment on an admin.
        #----------------------------------------------------------------------
        fixture_add_comment_report(reported_user=self.admin_user)
        comment_report = CommentReport.query.filter(
            CommentReport.reported_user==self.admin_user).filter(
            CommentReport.resolved==None).first()

        response, context = self.do_post({'action_to_resolve':[u'takeaway'],
            'take_away_privileges':[u'active'],
            'targeted_user':self.admin_user.id},
            url='/mod/reports/{0}/'.format(comment_report.id))
        self.query_for_users()

        assert response.status == '200 OK'
        assert self.admin_user.has_privilege(u'active')
Example #7
0
    def testReportResolution(self):
        self.login(u'moderator')

        # First, test a moderators taking away a user's privilege in response
        # to a reported comment
        #----------------------------------------------------------------------
        fixture_add_comment_report(reported_user=self.user)
        comment_report = Report.query.filter(
            Report.reported_user == self.user).first()

        response = self.test_app.get('/mod/reports/{0}/'.format(
            comment_report.id))
        assert response.status == '200 OK'
        self.query_for_users()
        comment_report = Report.query.filter(
            Report.reported_user == self.user).first()

        response, context = self.do_post(
            {
                'action_to_resolve': [u'takeaway'],
                'take_away_privileges': [u'commenter'],
                'targeted_user': self.user.id
            },
            url='/mod/reports/{0}/'.format(comment_report.id))

        self.query_for_users()
        comment_report = Report.query.filter(
            Report.reported_user == self.user).first()
        assert response.status == '302 FOUND'
        assert not self.user.has_privilege(u'commenter')
        assert comment_report.is_archived_report() is True

        fixture_add_comment_report(reported_user=self.user)
        comment_report = Report.query.filter(
            Report.reported_user == self.user).first()

        # Then, test a moderator sending an email to a user in response to a
        # reported comment
        #----------------------------------------------------------------------
        self.query_for_users()

        response, context = self.do_post(
            {
                'action_to_resolve': [u'sendmessage'],
                'message_to_user': '******',
                'targeted_user': self.user.id
            },
            url='/mod/reports/{0}/'.format(comment_report.id))

        self.query_for_users()
        comment_report = Report.query.filter(
            Report.reported_user == self.user).first()
        assert response.status == '302 FOUND'
        assert mail.EMAIL_TEST_MBOX_INBOX == [{
            'to': [u'*****@*****.**'],
            'message':
            'Content-Type: text/plain; charset="utf-8"\n\
MIME-Version: 1.0\nContent-Transfer-Encoding: base64\nSubject: Warning from- \
moderator \nFrom: [email protected]\nTo: [email protected]\n\n\
VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
            'from':
            '*****@*****.**'
        }]
        assert comment_report.is_archived_report() is True

        # Then test a moderator banning a user AND a moderator deleting the
        # offending comment. This also serves as a test for taking multiple
        # actions to resolve a report
        #----------------------------------------------------------------------
        self.query_for_users()
        fixture_add_comment(author=self.user.id,
                            comment=u'Comment will be removed')
        test_comment = TextComment.query.filter(
            TextComment.actor == self.user.id).first()
        fixture_add_comment_report(comment=test_comment,
                                   reported_user=self.user)
        comment_gmr = GenericModelReference.query.filter_by(
            obj_pk=test_comment.id,
            model_type=test_comment.__tablename__).first()
        comment_report = Report.query.filter(
            Report.object_id == comment_gmr.id).filter(
                Report.resolved == None).first()

        response, context = self.do_post(
            {
                'action_to_resolve': [u'userban', u'delete'],
                'targeted_user': self.user.id,
                'why_user_was_banned': u'',
                'user_banned_until': u''
            },
            url='/mod/reports/{0}/'.format(comment_report.id))
        assert response.status == '302 FOUND'
        self.query_for_users()
        test_user_ban = UserBan.query.filter(
            UserBan.user_id == self.user.id).first()
        assert test_user_ban is not None
        test_comment = TextComment.query.filter(
            TextComment.actor == self.user.id).first()
        assert test_comment is None

        # Then, test what happens when a moderator attempts to punish an admin
        # from a reported comment on an admin.
        #----------------------------------------------------------------------
        fixture_add_comment_report(reported_user=self.admin_user)
        comment_report = Report.query.filter(
            Report.reported_user == self.admin_user).filter(
                Report.resolved == None).first()

        response, context = self.do_post(
            {
                'action_to_resolve': [u'takeaway'],
                'take_away_privileges': [u'active'],
                'targeted_user': self.admin_user.id
            },
            url='/mod/reports/{0}/'.format(comment_report.id))
        self.query_for_users()

        assert response.status == '200 OK'
        assert self.admin_user.has_privilege(u'active')