本文整理汇总了Python中moderation.moderator.GenericModerator.is_auto_reject方法的典型用法代码示例。如果您正苦于以下问题:Python GenericModerator.is_auto_reject方法的具体用法?Python GenericModerator.is_auto_reject怎么用?Python GenericModerator.is_auto_reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moderation.moderator.GenericModerator
的用法示例。
在下文中一共展示了GenericModerator.is_auto_reject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AutoModerateModeratorTestCase
# 需要导入模块: from moderation.moderator import GenericModerator [as 别名]
# 或者: from moderation.moderator.GenericModerator import is_auto_reject [as 别名]
class AutoModerateModeratorTestCase(TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.user = User.objects.get(username='admin')
self.moderator = GenericModerator(UserProfile)
self.obj = object
def test_is_auto_approve_user_superuser(self):
self.moderator.auto_approve_for_superusers = True
self.user.is_superuser = True
reason = self.moderator.is_auto_approve(self.obj, self.user)
self.assertTrue(reason)
self.assertEqual(reason, 'Auto-approved: Superuser')
def test_is_auto_approve_user_is_staff(self):
self.moderator.auto_approve_for_staff = True
self.user.is_superuser = False
reason = self.moderator.is_auto_approve(self.obj, self.user)
self.assertTrue(reason)
self.assertEqual(reason, 'Auto-approved: Staff')
def test_is_auto_approve_not_user_superuser(self):
self.moderator.auto_approve_for_superusers = True
self.moderator.auto_approve_for_staff = True
self.user.is_superuser = False
self.user.is_staff = False
self.assertFalse(self.moderator.is_auto_approve(self.obj, self.user))
def test_is_auto_approve_not_user_is_staff(self):
self.moderator.auto_approve_for_staff = True
self.user.is_staff = False
self.user.is_superuser = False
self.assertFalse(self.moderator.is_auto_approve(self.obj, self.user))
def test_auto_approve_for_groups_user_in_group(self):
self.moderator.auto_approve_for_superusers = False
self.moderator.auto_approve_for_staff = False
self.moderator.auto_approve_for_groups = ['moderators']
group = Group(name='moderators')
group.save()
self.user.groups.add(group)
self.user.save()
reason = self.moderator.is_auto_approve(self.obj, self.user)
self.assertTrue(reason)
self.assertEqual(reason, 'Auto-approved: User in allowed group')
def test_auto_approve_for_groups_user_not_in_group(self):
self.moderator.auto_approve_for_superusers = False
self.moderator.auto_approve_for_staff = False
self.moderator.auto_approve_for_groups = ['banned']
self.assertFalse(self.moderator.is_auto_approve(self.obj, self.user))
def test_is_auto_reject_user_is_anonymous(self):
from mock import Mock
self.user.is_anonymous = Mock()
self.user.is_anonymous.return_value = True
reason = self.moderator.is_auto_reject(self.obj, self.user)
self.assertTrue(reason)
self.assertEqual(reason, u'Auto-rejected: Anonymous User')
def test_is_auto_reject_user_is_not_anonymous(self):
from mock import Mock
self.user.is_anonymous = Mock()
self.user.is_anonymous.return_value = False
self.assertFalse(self.moderator.is_auto_reject(self.obj, self.user))
def test_auto_reject_for_groups_user_in_group(self):
self.moderator.auto_reject_for_groups = ['banned']
group = Group(name='banned')
group.save()
self.user.groups.add(group)
self.user.save()
reason = self.moderator.is_auto_reject(self.obj, self.user)
self.assertTrue(reason)
self.assertEqual(reason, 'Auto-rejected: User in disallowed group')
def test_auto_reject_for_groups_user_not_in_group(self):
self.moderator.auto_reject_for_groups = ['banned']
self.assertFalse(self.moderator.is_auto_reject(self.obj, self.user))
def test_overwrite_automoderation_method(self):
def akismet_spam_check(obj):
return True
class UserProfileModerator(GenericModerator):
# Inside MyModelModerator, which is registered with MyModel
def is_auto_reject(self, obj, user):
# Auto reject spam
if akismet_spam_check(obj): # Check body of object for spam
# Body of object is spam, moderate
return self.reason('Auto rejected: SPAM')
super(UserProfile, self).is_auto_reject(obj, user)
moderator = UserProfileModerator(UserProfile)
reason = moderator.is_auto_reject(self.obj, self.user)
#.........这里部分代码省略.........