def test_get_comment_status_removed_no_mod_creds(self): removed_comment = MockComment(comment_text='[removed]') removed_comment.author = None self.assertEqual({ 'removed': True, 'deleted': False }, _get_comment_status_mod_fields(removed_comment, has_mod_creds=False))
def test_get_comment_status_deleted_has_mod_creds(self): deleted_comment = MockComment(comment_text='[deleted]') deleted_comment.author = None self.assertEqual({ 'approved': False, 'removed': False, 'deleted': True }, _get_comment_status_mod_fields(deleted_comment, has_mod_creds=True))
def test_get_comment_status_removed_has_mod_creds(self): # If we have mod creds, we don't look at the comment_text to determine if # the comment is removed - we only check the 'removed' field. removed_comment = MockComment(comment_text='[removed]', removed=True) removed_comment.author = None self.assertEqual({ 'approved': False, 'removed': True, 'deleted': False }, _get_comment_status_mod_fields(removed_comment, has_mod_creds=True))
def test_get_comment_status_approved_has_mod_creds(self): approved_comment = MockComment(approved=True) self.assertEqual({ 'approved': True, 'removed': False, 'deleted': False }, _get_comment_status_mod_fields(approved_comment, has_mod_creds=True))
def test_get_comment_status_normal_has_mod_creds(self): normal_comment = MockComment() self.assertEqual( { 'approved': False, 'removed': False, 'deleted': False }, _get_comment_status_mod_fields(normal_comment, has_mod_creds=True))
def test_create_comment_output_record(self): comment = MockComment(comment_text='hello', parent_id='abc', link_id='def') record = log_subreddit_comments.create_comment_output_record(comment) self.assertEqual('hello', record['orig_comment_text']) self.assertEqual('abc', record['parent_id']) self.assertEqual('def', record['link_id']) # Check that record is JSON-serializable. json_record = json.dumps(record) self.assertIn('hello', json_record)
def test_create_mod_comment_output_record_more_rules(self): comment = MockComment('hello') scores = {'TOXICITY': 0.8} hi_tox_rule = Rule('hi_tox', {'TOXICITY': '> 0.9'}, {}, 'report') med_tox_rule = Rule('med_tox', {'TOXICITY': '> 0.5'}, {}, 'report') lo_tox_rule = Rule('lo_tox', {'TOXICITY': '> 0.1'}, {}, 'noop') rules = [hi_tox_rule, med_tox_rule, lo_tox_rule] action_dict = check_rules(comment, rules, scores) record = create_mod_comment_output_record(comment, 'hello', scores, action_dict, rules) self.assertEqual('rule-not-triggered', record['rule:hi_tox']) self.assertEqual('report', record['rule:med_tox']) self.assertEqual('noop', record['rule:lo_tox'])
def test_create_mod_comment_output_record_basic(self): comment = MockComment('hello') scores = {'TOXICITY': 0.8} hi_tox_rule = Rule('hi_tox', {'TOXICITY': '> 0.5'}, {}, 'report') rules = [hi_tox_rule] action_dict = check_rules(comment, rules, scores) record = create_mod_comment_output_record(comment, 'hello', scores, action_dict, rules) self.assertEqual('hello', record['orig_comment_text']) # This field is only present when different from the comment body. self.assertFalse('scored_comment_text' in record) self.assertEqual(0.8, record['score:TOXICITY']) self.assertEqual('report', record['rule:hi_tox'])