本文整理匯總了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)
#.........這裏部分代碼省略.........