def test_l10n_badge(self): """Verify the L10n Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES['l10n-badge']['slug'].format(year=year), title=WIKI_BADGES['l10n-badge']['title'].format(year=year), description=WIKI_BADGES['l10n-badge']['description'].format( year=year)) # Create 9 approved es revisions. d = DocumentFactory(locale='es') ApprovedRevisionFactory.create_batch(settings.BADGE_LIMIT_L10N_KB - 1, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved es revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_l10n_badge(self): """Verify the L10n Badge is awarded properly.""" # Create the user and badge. year = date.today().year user = UserFactory() b = BadgeFactory( slug=WIKI_BADGES["l10n-badge"]["slug"].format(year=year), title=WIKI_BADGES["l10n-badge"]["title"].format(year=year), description=WIKI_BADGES["l10n-badge"]["description"].format( year=year), ) # Create 9 approved es revisions. doc = DocumentFactory(locale="es") ApprovedRevisionFactory.create_batch(settings.BADGE_LIMIT_L10N_KB - 1, creator=user, document=doc) # User should NOT have the badge yet assert not b.is_awarded_to(user) # Create 1 more approved es revision. RevisionFactory(creator=user, document=doc, is_approved=True) # User should have the badge now assert b.is_awarded_to(user)
def test_kb_badge(self): """Verify the KB Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES["kb-badge"]["slug"].format(year=year), title=WIKI_BADGES["kb-badge"]["title"].format(year=year), description=WIKI_BADGES["kb-badge"]["description"].format( year=year), ) # Create 9 approved en-US revisions. d = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE) ApprovedRevisionFactory.create_batch(settings.BADGE_LIMIT_L10N_KB - 1, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved en-US revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_badges_listed(self): """Verify that awarded badges appear on the profile page.""" badge_title = 'awesomesauce badge' b = BadgeFactory(title=badge_title) u = UserFactory() AwardFactory(user=u, badge=b) r = self.client.get(reverse('users.profile', args=[u.username])) assert badge_title in r.content
def test_answer_badge(self): """Verify the Support Forum Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() badge_template = QUESTIONS_BADGES['answer-badge'] b = BadgeFactory( slug=badge_template['slug'].format(year=year), title=badge_template['title'].format(year=year), description=badge_template['description'].format(year=year)) # Create one less answer than reqiured to earn badge AnswerFactory.create_batch(settings.BADGE_LIMIT_SUPPORT_FORUM - 1, creator=u) # User should NOT have the badge yet. assert not b.is_awarded_to(u) # Create 1 more answer. AnswerFactory(creator=u) # User should have the badge now. assert b.is_awarded_to(u)
def test_l10n_badge(self): """Verify the L10n Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES['l10n-badge']['slug'].format(year=year), title=WIKI_BADGES['l10n-badge']['title'].format(year=year), description=WIKI_BADGES['l10n-badge']['description'].format(year=year)) # Create 9 approved es revisions. d = DocumentFactory(locale='es') ApprovedRevisionFactory.create_batch(9, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved es revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_answer_badge(self): """Verify the Support Forum Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() badge_template = QUESTIONS_BADGES['answer-badge'] b = BadgeFactory( slug=badge_template['slug'].format(year=year), title=badge_template['title'].format(year=year), description=badge_template['description'].format(year=year)) # Create 29 answers. AnswerFactory.create_batch(29, creator=u) # User should NOT have the badge yet. assert not b.is_awarded_to(u) # Create 1 more answer. AnswerFactory(creator=u) # User should have the badge now. assert b.is_awarded_to(u)
def test_list_with_awards(self): b = BadgeFactory() a1 = AwardFactory(description=u'A1 AWARD', badge=b) a2 = AwardFactory(description=u'A2 AWARD', badge=b) a3 = AwardFactory(description=u'A3 AWARD', badge=b) resp = self.client.get(reverse('kbadge.awards_list'), follow=True) eq_(200, resp.status_code) self.assertContains(resp, a1.user.username) self.assertContains(resp, a1.get_absolute_url()) self.assertContains(resp, a2.user.username) self.assertContains(resp, a2.get_absolute_url()) self.assertContains(resp, a3.user.username) self.assertContains(resp, a3.get_absolute_url())
def test_aoa_badge(self): """Verify the KB Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=AOA_BADGE['slug'].format(year=year), title=AOA_BADGE['title'].format(year=year), description=AOA_BADGE['description'].format(year=year)) # Create 49 replies. # FIXME: Do this as a batch for _ in range(49): ReplyFactory(user=u) # User should NOT have the badge yet. assert not b.is_awarded_to(u) # Create 1 more reply. ReplyFactory(user=u) # User should have the badge now. assert b.is_awarded_to(u)
def test_kb_badge(self): """Verify the KB Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES['kb-badge']['slug'].format(year=year), title=WIKI_BADGES['kb-badge']['title'].format(year=year), description=WIKI_BADGES['kb-badge']['description'].format(year=year)) # Create 9 approved en-US revisions. d = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE) ApprovedRevisionFactory.create_batch(settings.BADGE_LIMIT_L10N_KB - 1, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved en-US revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_answer_badge(self): """Verify the Support Forum Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() badge_template = QUESTIONS_BADGES["answer-badge"] b = BadgeFactory( slug=badge_template["slug"].format(year=year), title=badge_template["title"].format(year=year), description=badge_template["description"].format(year=year), ) # Create one less answer than reqiured to earn badge AnswerFactory.create_batch(settings.BADGE_LIMIT_SUPPORT_FORUM - 1, creator=u) # User should NOT have the badge yet. assert not b.is_awarded_to(u) # Create 1 more answer. AnswerFactory(creator=u) # User should have the badge now. assert b.is_awarded_to(u)
def test_notification(self): # Note: Need to do this import here so the # notify_award_recipient function handles the # badge_was_awarded signal. This works fine in production # because badges gets loaded by kitsune.kbadge in startup. from kitsune.kbadge import badges # noqa new_badge = BadgeFactory() # Check the mail queue first. eq_(0, len(mail.outbox)) # Create an award and save it. This triggers the notification. AwardFactory(description="yay!", badge=new_badge) eq_(1, len(mail.outbox))