def test_get_max_nr_answers_with_3_questions(self): q = QuestionnaireFactory() page = PageFactory(questionnaire=q) question1 = QuestionFactory(page=page) question2 = QuestionFactory(page=page) question3 = QuestionFactory(page=page) for _ in range(3): AnswerFactory(question=question1) for _ in range(4): AnswerFactory(question=question2) for _ in range(2): AnswerFactory(question=question3) self.assertEqual(q.get_max_nr_answers(), 4)
def test_fetching_answer_users(self, *args, **kwargs): group = GroupFactory.create(remote_id=GROUP_ID) post = PostFactory.create(remote_id=POST_ID, wall_owner=group) poll = PollFactory.create(remote_id=POLL_ID, owner=group, post=post) answer = AnswerFactory.create(pk=266067661, poll=poll) answer.fetch_voters() self.assertEqual(answer.voters.count(), answer.votes_count) self.assertTrue(answer.voters.count() > 110) self.assertTrue(answer.rate > 0)
def test_fetching_answer_users_by_api(self, *args, **kwargs): def calc_percentage(poll, answer_votes): pp = Poll.remote.fetch(poll.pk, poll.post) if pp and pp.votes_count: return answer_votes * 100. / pp.votes_count return 0 group = GroupFactory.create(remote_id=GROUP_ID) post = PostFactory.create(remote_id=POST_ID, wall_owner=group) poll = PollFactory.create(remote_id=POLL_ID, owner=group, post=post) answer = AnswerFactory.create(pk=266067661, poll=poll) answer.fetch_voters_by_api() self.assertEqual(answer.voters.count(), answer.votes_count) self.assertTrue(answer.voters.count() > 110) self.assertTrue(answer.rate > 0) percentage = calc_percentage(poll, answer.votes_count) self.assertEqual(answer.rate, percentage)
def test_get_max_nr_answers_with_1_question(self): q = QuestionnaireFactory() page = PageFactory(questionnaire=q) question = QuestionFactory(page=page) AnswerFactory(question=question) self.assertEqual(q.get_max_nr_answers(), 1)