本文整理匯總了Python中badger.models.DeferredAward.grant_to方法的典型用法代碼示例。如果您正苦於以下問題:Python DeferredAward.grant_to方法的具體用法?Python DeferredAward.grant_to怎麽用?Python DeferredAward.grant_to使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類badger.models.DeferredAward
的用法示例。
在下文中一共展示了DeferredAward.grant_to方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_granted_claim
# 需要導入模塊: from badger.models import DeferredAward [as 別名]
# 或者: from badger.models.DeferredAward import grant_to [as 別名]
def test_granted_claim(self):
"""Reusable deferred award can be granted to someone by email"""
# Assemble the characters involved...
creator = self._get_user()
random_guy = self._get_user(username='random_guy',
email='[email protected]',
is_superuser=False)
staff_person = self._get_user(username='staff_person',
email='[email protected]',
is_staff=True)
grantee_email = '[email protected]'
grantee = self._get_user(username='winner1',
email=grantee_email)
# Create a consumable award claim
badge1 = self._get_badge(title="Test A", creator=creator)
original_email = '[email protected]'
da = DeferredAward(badge=badge1, creator=creator, email=original_email)
claim_code = da.claim_code
da.save()
# Grant the deferred award, ensure the existing one is modified.
new_da = da.grant_to(email=grantee_email, granter=staff_person)
ok_(claim_code != new_da.claim_code)
ok_(da.email != original_email)
eq_(da.pk, new_da.pk)
eq_(new_da.email, grantee_email)
# Claim the deferred award, assert that the appropriate deferred award
# was destroyed
eq_(1, DeferredAward.objects.filter(pk=da.pk).count())
eq_(1, DeferredAward.objects.filter(pk=new_da.pk).count())
DeferredAward.objects.claim_by_email(grantee)
eq_(0, DeferredAward.objects.filter(pk=da.pk).count())
eq_(0, DeferredAward.objects.filter(pk=new_da.pk).count())
# Finally, assert the award condition
ok_(badge1.is_awarded_to(grantee))
# Create a reusable award claim
badge2 = self._get_badge(title="Test B", creator=creator)
da = DeferredAward(badge=badge2, creator=creator, reusable=True)
claim_code = da.claim_code
da.save()
# Grant the deferred award, ensure a new deferred award is generated.
new_da = da.grant_to(email=grantee_email, granter=staff_person)
ok_(claim_code != new_da.claim_code)
ok_(da.pk != new_da.pk)
eq_(new_da.email, grantee_email)
# Claim the deferred award, assert that the appropriate deferred award
# was destroyed
eq_(1, DeferredAward.objects.filter(pk=da.pk).count())
eq_(1, DeferredAward.objects.filter(pk=new_da.pk).count())
DeferredAward.objects.claim_by_email(grantee)
eq_(1, DeferredAward.objects.filter(pk=da.pk).count())
eq_(0, DeferredAward.objects.filter(pk=new_da.pk).count())
# Finally, assert the award condition
ok_(badge2.is_awarded_to(grantee))
# Create one more award claim
badge3 = self._get_badge(title="Test C", creator=creator)
da = DeferredAward(badge=badge3, creator=creator)
claim_code = da.claim_code
da.save()
# Grant the deferred award, ensure a new deferred award is generated.
try:
new_da = da.grant_to(email=grantee_email, granter=random_guy)
is_ok = False
except Exception, e:
ok_(type(e) is DeferredAwardGrantNotAllowedException)
is_ok = True