def test_asker_replies_arent_a_contribution(self): """Verify that replies posted by the question creator aren't counted. If a user has 10 replies to their own question, they aren't counted as a contributor. """ # A user with 10 answers to own question. q = QuestionFactory() u = q.creator AnswerFactory.create_batch(10, creator=u, question=q) # Create metric kinds and update metrics for tomorrow (today's # activity shows up tomorrow). self._make_contributor_metric_kinds() call_command('update_contributor_metrics', str(date.today() + timedelta(days=1))) r = self._get_api_result('api.kpi.contributors') eq_(r['objects'][0]['support_forum'], 0) # Change the question creator, now we should have 1 contributor. q.creator = UserFactory() q.save() cache.clear() # We need to clear the cache for new results. Metric.objects.all().delete() call_command('update_contributor_metrics', str(date.today() + timedelta(days=1))) r = self._get_api_result('api.kpi.contributors') eq_(r['objects'][0]['support_forum'], 1)
def test_asker_replies_arent_a_contribution(self): """Verify that replies posted by the question creator aren't counted. If a user has 10 replies to their own question, they aren't counted as a contributor. """ # A user with 10 answers to own question. q = QuestionFactory() u = q.creator AnswerFactory.create_batch(10, creator=u, question=q) # Create metric kinds and update metrics for tomorrow (today's # activity shows up tomorrow). self._make_contributor_metric_kinds() update_contributor_metrics(day=date.today() + timedelta(days=1)) r = self._get_api_result('api.kpi.contributors') eq_(r['objects'][0]['support_forum'], 0) # Change the question creator, now we should have 1 contributor. q.creator = UserFactory() q.save() cache.clear() # We need to clear the cache for new results. Metric.objects.all().delete() update_contributor_metrics(day=date.today() + timedelta(days=1)) r = self._get_api_result('api.kpi.contributors') eq_(r['objects'][0]['support_forum'], 1)
def setUp(self): today = datetime.today() self.start_of_first_week = today - timedelta(days=today.weekday(), weeks=12) revisions = ApprovedRevisionFactory.create_batch(3, created=self.start_of_first_week) reviewer = UserFactory() ApprovedRevisionFactory(reviewer=reviewer, created=self.start_of_first_week) ApprovedRevisionFactory(creator=revisions[1].creator, reviewer=reviewer, created=self.start_of_first_week + timedelta(weeks=1, days=2)) ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(weeks=1, days=1)) for r in revisions: lr = ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(days=1), document__locale='es') ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(weeks=2, days=1), creator=lr.creator, document__locale='es') answers = AnswerFactory.create_batch( 7, created=self.start_of_first_week + timedelta(weeks=1, days=2)) AnswerFactory(question=answers[2].question, creator=answers[2].question.creator, created=self.start_of_first_week + timedelta(weeks=1, days=2)) for a in answers[:2]: AnswerFactory(creator=a.creator, created=self.start_of_first_week + timedelta(weeks=2, days=5)) replies = ReplyFactory.create_batch(2, created=self.start_of_first_week) for r in replies: ReplyFactory(user=r.user, created=self.start_of_first_week + timedelta(weeks=2)) call_command('cohort_analysis')
def test_answer_vote_limit(self): """Test that an anonymous user's votes are ignored after 10 answer votes.""" q = QuestionFactory() answers = AnswerFactory.create_batch(11, question=q) # The rate limit is 10 per day. So make 10 requests. (0 through 9) for i in range(10): self._check_answer_vote(q, answers[i], False) # Now make another, it should fail. self._check_answer_vote(q, answers[10], True)
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_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_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)