Beispiel #1
0
    def test_awards_by_user(self):
        """Can view awards by user"""
        user = self._get_user()
        user2 = self._get_user(username='******')

        b1, created = Badge.objects.get_or_create(creator=user,
                                                  title="Code Badge #1")
        b2, created = Badge.objects.get_or_create(creator=user,
                                                  title="Code Badge #2")
        b3, created = Badge.objects.get_or_create(creator=user,
                                                  title="Code Badge #3")

        b1.award_to(user2)
        award_badge(b2.slug, user2)
        Award.objects.create(badge=b3, user=user2)

        url = reverse('badger.views.awards_by_user', args=(user2.username, ))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        eq_('badge_awards_by_user', doc.find('body').attr('id'))
        eq_(3, doc.find('.award').length)
        for b in (b1, b2, b3):
            eq_(
                1,
                doc.find('.award .badge .title:contains("%s")' %
                         b.title).length)
    def test_metabadge_awarded(self):
        """Upon completing collection of badges, award a meta-badge"""
        user = self._get_user()

        # Cover a few bases on award creation...
        award_badge('test-1', user)
        award_badge('test-2', user)
        a = Award(badge=get_badge('button-clicker'), user=user)
        a.save()
        Award.objects.create(badge=get_badge('awesomeness'), user=user)

        ok_(get_badge('master-badger').is_awarded_to(user))

        get_badge('awesomeness').award_to(user)
        eq_(1, Award.objects.filter(badge=get_badge("master-badger"),
                                    user=user).count())
Beispiel #3
0
    def test_metabadge_awarded(self):
        """Upon completing collection of badges, award a meta-badge"""
        user = self._get_user()

        ok_(not get_badge('master-badger').is_awarded_to(user))

        # Cover a few bases on award creation...
        award_badge('test-1', user)
        award_badge('test-2', user)
        a = Award(badge=get_badge('button-clicker'), user=user)
        a.save()

        get_badge('awesomeness').award_to(user)
        eq_(1, Award.objects.filter(badge=get_badge("master-badger"),
                                    user=user).count())
        
        ok_(get_badge('master-badger').is_awarded_to(user))
Beispiel #4
0
def on_guestbook_post(sender, **kwargs):
    o = kwargs['instance']
    created = kwargs['created']

    if created:
        award_badge('first-post', o.creator)

    # Increment progress counter and track the completion condition ourselves.
    b = get_badge('250-words')
    p = b.progress_for(o.creator).increment_by(o.word_count)
    if p.counter >= 250:
        b.award_to(o.creator)

    # Update percentage from total word count, and Progress will award on 100%
    total_word_count = (GuestbookEntry.objects.filter(
        creator=o.creator).aggregate(s=Sum('word_count'))['s'])
    (get_progress("250-words-by-percent",
                  o.creator).update_percent(total_word_count, 250))
Beispiel #5
0
def on_guestbook_post(sender, **kwargs):
    o = kwargs['instance']
    created = kwargs['created']

    if created:
        award_badge('first-post', o.creator)

    # Increment progress counter and track the completion condition ourselves.
    b = get_badge('250-words')
    p = b.progress_for(o.creator).increment_by(o.word_count)
    if p.counter >= 250:
        b.award_to(o.creator)

    # Update percentage from total word count, and Progress will award on 100%
    total_word_count = (GuestbookEntry.objects.filter(creator=o.creator)
                        .aggregate(s=Sum('word_count'))['s'])
    (get_progress("250-words-by-percent", o.creator)
           .update_percent(total_word_count, 250))
Beispiel #6
0
    def test_awards_by_user(self):
        """Can view awards by user"""
        user = self._get_user()
        user2 = self._get_user(username='******')

        b1, created = Badge.objects.get_or_create(creator=user, title="Code Badge #1")
        b2, created = Badge.objects.get_or_create(creator=user, title="Code Badge #2")
        b3, created = Badge.objects.get_or_create(creator=user, title="Code Badge #3")

        b1.award_to(user2)
        award_badge(b2.slug, user2)
        Award.objects.create(badge=b3, user=user2)

        url = reverse('badger.views.awards_by_user', args=(user2.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        eq_('badge_awards_by_user', doc.find('body').attr('id'))
        eq_(3, doc.find('.badge').length)
        for b in (b1, b2, b3):
            eq_(1, doc.find('.badge .title:contains("%s")' % b.title).length)