Ejemplo n.º 1
0
    def test_grant_deferred_award(self):
        """Deferred award for a badge can be granted to an email address."""
        deferred_email = "*****@*****.**"
        user1 = self._get_user(username="******", email="*****@*****.**")
        b1 = Badge.objects.create(creator=user1, title="Badge to defer")
        
        da = DeferredAward(badge=b1, creator=user1, email='*****@*****.**')
        da.save()
        url = da.get_claim_url()

        self.client.login(username="******", password="******")
        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="******", email=deferred_email)
        self.client.login(username="******", password="******")
        r = self.client.get(reverse('badger.views.detail',
            args=(b1.slug,)), follow=True)
        ok_(b1.is_awarded_to(user2))
Ejemplo n.º 2
0
    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="******",
                               email="*****@*****.**")
        user2 = self._get_user(username="******",
                               email="*****@*****.**")
        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'])
Ejemplo n.º 3
0
    def test_deferred_award_immediate_claim(self):
        """Ensure that a deferred award can be immediately claimed rather than
        viewing detail"""
        deferred_email = "*****@*****.**"
        user1 = self._get_user(username="******", email="*****@*****.**")
        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="******", email=deferred_email)
        self.client.login(username="******", password="******")
        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))
Ejemplo n.º 4
0
    def test_grant_deferred_award(self):
        """Deferred award for a badge can be granted to an email address."""
        deferred_email = "*****@*****.**"
        user1 = self._get_user(username="******", email="*****@*****.**")
        b1 = Badge.objects.create(creator=user1, title="Badge to defer")

        da = DeferredAward(badge=b1, creator=user1, email='*****@*****.**')
        da.save()
        url = da.get_claim_url()

        self.client.login(username="******", password="******")
        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="******", email=deferred_email)
        self.client.login(username="******", password="******")
        r = self.client.get(reverse('badger.views.detail',
            args=(b1.slug,)), follow=True)
        ok_(b1.is_awarded_to(user2))
Ejemplo n.º 5
0
    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="******",
                               email="*****@*****.**")
        user2 = self._get_user(username="******",
                               email="*****@*****.**")
        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'])
Ejemplo n.º 6
0
    def test_deferred_award_immediate_claim(self):
        """Ensure that a deferred award can be immediately claimed rather than
        viewing detail"""
        deferred_email = "*****@*****.**"
        user1 = self._get_user(username="******", email="*****@*****.**")
        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="******", email=deferred_email)
        self.client.login(username="******", password="******")
        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))