本文整理汇总了Python中jmbo.models.ModelBase.can_vote方法的典型用法代码示例。如果您正苦于以下问题:Python ModelBase.can_vote方法的具体用法?Python ModelBase.can_vote怎么用?Python ModelBase.can_vote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jmbo.models.ModelBase
的用法示例。
在下文中一共展示了ModelBase.can_vote方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_vote
# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import can_vote [as 别名]
def test_can_vote(self):
# create dummy request object
request = type('Request', (object,), {})
class User():
def is_authenticated(self):
return False
request.user = User()
request.secretballot_token = 'test_token'
# return false when liking is closed
obj = ModelBase(
likes_enabled=True,
likes_closed=True,
anonymous_likes=True
)
obj.save()
self.failIf(obj.can_vote(request)[0])
# return false when liking is disabled
obj = ModelBase(
likes_enabled=False,
likes_closed=False,
anonymous_likes=True
)
obj.save()
self.failIf(obj.can_vote(request)[0])
# return false if anonymous and anonymous liking is disabled
obj = ModelBase(
likes_enabled=True,
likes_closed=False,
anonymous_likes=False
)
obj.save()
self.failIf(obj.can_vote(request)[0])
# return true if anonymous and anonymous liking is enabled
obj = ModelBase(
likes_enabled=True,
likes_closed=False,
anonymous_likes=True
)
obj.save()
self.failUnless(obj.can_vote(request))
# return false if vote already exist
content_type = ContentType.objects.get(
app_label="jmbo",
model="modelbase"
)
Vote.objects.create(
object_id=obj.id,
token='test_token',
content_type=content_type, vote=1
)
self.failIf(obj.can_vote(request)[0])