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


Python models.DeferredAward类代码示例

本文整理汇总了Python中badger.models.DeferredAward的典型用法代码示例。如果您正苦于以下问题:Python DeferredAward类的具体用法?Python DeferredAward怎么用?Python DeferredAward使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DeferredAward类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_grant_deferred_award

    def test_grant_deferred_award(self):
        """Deferred award for a badge can be granted to an email address."""
        deferred_email = "[email protected]"
        user1 = self._get_user(username="creator", email="[email protected]")
        b1 = Badge.objects.create(creator=user1, title="Badge to defer")
        
        da = DeferredAward(badge=b1, creator=user1, email='[email protected]')
        da.save()
        url = da.get_claim_url()

        self.client.login(username="creator", password="trustno1")
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)

        doc = pq(r.content)
        form = doc('form#grant_award')
        eq_(1, form.length)
        eq_(1, form.find('*[name=email]').length)
        eq_(1, form.find('input.submit,button.submit').length)

        r = self.client.post(url, dict(
            is_grant=1, email=deferred_email,
        ), follow=False)

        user2 = self._get_user(username="awardee", email=deferred_email)
        self.client.login(username="awardee", password="trustno1")
        r = self.client.get(reverse('badger.views.detail',
            args=(b1.slug,)), follow=True)
        ok_(b1.is_awarded_to(user2))
开发者ID:askvictor,项目名称:django-badger,代码行数:29,代码来源:test_views.py

示例2: test_deferred_award_immediate_claim

    def test_deferred_award_immediate_claim(self):
        """Ensure that a deferred award can be immediately claimed rather than
        viewing detail"""
        deferred_email = "[email protected]"
        user1 = self._get_user(username="creator", email="[email protected]")
        b1 = Badge.objects.create(creator=user1, title="Badge to defer")
        
        da = DeferredAward(badge=b1, creator=user1)
        da.save()
        url = da.get_claim_url()

        # Just viewing the claim URL shouldn't require login.
        r = self.client.get(url, follow=False)
        eq_(200, r.status_code)

        # But, attempting to claim the award should require login
        r = self.client.post(reverse('badger.views.claim_deferred_award'), dict(
            code=da.claim_code,
        ), follow=False)
        eq_(302, r.status_code)
        ok_('login' in r['Location'])

        # So, try logging in and fetch the immediate-claim URL
        user2 = self._get_user(username="awardee", email=deferred_email)
        self.client.login(username="awardee", password="trustno1")
        r = self.client.post(reverse('badger.views.claim_deferred_award'), dict(
            code=da.claim_code,
        ), follow=False)
        eq_(302, r.status_code)
        ok_('awards' in r['Location'])

        ok_(b1.is_awarded_to(user2))
开发者ID:askvictor,项目名称:django-badger,代码行数:32,代码来源:test_views.py

示例3: test_claim_code_shows_awards_after_claim

    def test_claim_code_shows_awards_after_claim(self):
        """Claim code URL should lead to award detail or list after claim"""
        user1 = self._get_user(username="creator",
                               email="[email protected]")
        user2 = self._get_user(username="awardee",
                               email="[email protected]")
        b1 = Badge.objects.create(creator=user1, unique=False,
                                  title="Badge for claim viewing")
        da = DeferredAward(badge=b1, creator=user1)
        da.save()

        url = da.get_claim_url()

        # Before claim, code URL leads to claim page. 
        r = self.client.get(url, follow=False)
        eq_(200, r.status_code)
        doc = pq(r.content)
        form = doc('form#claim_award')

        # After claim, code URL leads to a single award detail page.
        award = da.claim(user2)
        r = self.client.get(url, follow=False)
        eq_(302, r.status_code)
        award_url = reverse('badger.views.award_detail',
                            args=(award.badge.slug, award.pk))
        ok_(award_url in r['Location'])
开发者ID:askvictor,项目名称:django-badger,代码行数:26,代码来源:test_views.py

示例4: test_claim_code_shows_awards_after_claim

    def test_claim_code_shows_awards_after_claim(self):
        """Claim code URL should lead to award detail or list after claim"""
        user1 = self._get_user(username="creator",
                               email="[email protected]")
        user2 = self._get_user(username="awardee",
                               email="[email protected]")
        b1 = Badge.objects.create(creator=user1, unique=False,
                                  title="Badge for claim viewing")
        da = DeferredAward(badge=b1, creator=user1, reusable=True)
        da.save()

        url = reverse('badger.views.claim_deferred_award',
                      args=(da.claim_code,))

        # First claim leads to a single award detail page.
        award = da.claim(user2)
        r = self.client.get(url, follow=False)
        eq_(302, r.status_code)
        award_url = reverse('badger.views.award_detail',
                            args=(award.badge.slug, award.pk))
        ok_(award_url in r['Location'])

        # Second claim leads to a list of awards.
        award = da.claim(user2)
        r = self.client.get(url, follow=False)
        eq_(302, r.status_code)
        list_url = reverse('badger.views.awards_list',
                            args=(award.badge.slug,))
        ok_(list_url in r['Location'])
开发者ID:cheekybastard,项目名称:django-badger,代码行数:29,代码来源:test_views.py

示例5: test_claim_by_code

    def test_claim_by_code(self):
        """Can claim a deferred award by claim code"""
        user = self._get_user()
        awardee = self._get_user(username='winner1',
                                 email='[email protected]')

        badge1 = self._get_badge(title="Test A", creator=user)

        ok_(not badge1.is_awarded_to(awardee))

        da = DeferredAward(badge=badge1)
        da.save()
        code = da.claim_code

        eq_(1, DeferredAward.objects.filter(claim_code=code).count())
        DeferredAward.objects.claim_by_code(awardee, code)
        eq_(0, DeferredAward.objects.filter(claim_code=code).count())

        ok_(badge1.is_awarded_to(awardee))
开发者ID:afterfate,项目名称:django-badger,代码行数:19,代码来源:test_models.py

示例6: test_reusable_claim

    def test_reusable_claim(self):
        """Can repeatedly claim a reusable deferred award"""
        user = self._get_user()
        awardee = self._get_user(username='winner1',
                                 email='[email protected]')

        badge1 = self._get_badge(title="Test A", creator=user, unique=False)

        ok_(not badge1.is_awarded_to(awardee))

        da = DeferredAward(badge=badge1, reusable=True)
        da.save()
        code = da.claim_code

        for i in range(0, 5):
            eq_(1, DeferredAward.objects.filter(claim_code=code).count())
            DeferredAward.objects.claim_by_code(awardee, code)

        ok_(badge1.is_awarded_to(awardee))
        eq_(5, Award.objects.filter(badge=badge1, user=awardee).count())
开发者ID:AlexRiina,项目名称:django-badger,代码行数:20,代码来源:test_models.py

示例7: test_disallowed_claim

    def test_disallowed_claim(self):
        """Deferred award created by someone not allowed to award a badge
        cannot be claimed"""
        user = self._get_user()
        random_guy = self._get_user(username='random_guy',
                                    is_superuser=False)
        awardee = self._get_user(username='winner1',
                                 email='[email protected]')

        badge1 = self._get_badge(title="Test A", creator=user)

        ok_(not badge1.is_awarded_to(awardee))

        da = DeferredAward(badge=badge1, creator=random_guy)
        da.save()
        code = da.claim_code

        eq_(1, DeferredAward.objects.filter(claim_code=code).count())
        result = DeferredAward.objects.claim_by_code(awardee, code)
        eq_(0, DeferredAward.objects.filter(claim_code=code).count())

        ok_(not badge1.is_awarded_to(awardee))
开发者ID:AlexRiina,项目名称:django-badger,代码行数:22,代码来源:test_models.py

示例8: test_granted_claim

    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,代码行数:76,代码来源:test_models.py


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