当前位置: 首页>>代码示例>>Python>>正文


Python DeferredAward.grant_to方法代码示例

本文整理汇总了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
开发者ID:AlexRiina,项目名称:django-badger,代码行数:78,代码来源:test_models.py


注:本文中的badger.models.DeferredAward.grant_to方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。