def test_creator_num_answers(self): question = Question.objects.all()[0] answer = Answer(question=question, creator_id=47963, content="Test Answer") answer.save() eq_(answer.creator_num_answers, 2)
def test_top_contributors(self): # There should be no top contributors since there are no solutions. cache_top_contributors() response = get(self.client, "questions.questions") doc = pq(response.content) eq_(0, len(doc("#top-contributors ol li"))) # Solve a question and verify we now have a top conributor. answer = Answer.objects.all()[0] answer.created = datetime.now() answer.save() answer.question.solution = answer answer.question.save() cache_top_contributors() response = get(self.client, "questions.questions") doc = pq(response.content) lis = doc("#top-contributors ol li") eq_(1, len(lis)) eq_("pcraciunoiu", lis[0].text) # Make answer 8 days old. There should no be top contributors. answer.created = datetime.now() - timedelta(days=8) answer.save() cache_top_contributors() response = get(self.client, "questions.questions") doc = pq(response.content) eq_(0, len(doc("#top-contributors ol li")))
def test_update_page_task(self): answer = Answer.objects.get(pk=1) answer.page = 4 answer.save() answer = Answer.objects.get(pk=1) assert answer.page == 4 update_answer_pages(answer.question) a = Answer.objects.get(pk=1) assert a.page == 1
def test_delete_answer_removes_flag(self): """Deleting an answer also removes the flags on that answer.""" question = Question(title='Test Question', content='Lorem Ipsum Dolor', creator_id=118533) question.save() answer = Answer(question=question, creator_id=47963, content="Test Answer") answer.save() FlaggedObject.objects.create( status=0, content_object=answer, reason='language', creator_id=118533) eq_(1, FlaggedObject.objects.count()) answer.delete() eq_(0, FlaggedObject.objects.count())
def test_delete_last_answer_of_question(self): """Deleting the last_answer of a Question should update the question. """ question = Question.objects.get(pk=1) last_answer = question.last_answer # add a new answer and verify last_answer updated answer = Answer(question=question, creator_id=47963, content="Test Answer") answer.save() question = Question.objects.get(pk=question.id) eq_(question.last_answer.id, answer.id) # delete the answer and last_answer should go back to previous value answer.delete() question = Question.objects.get(pk=question.id) eq_(question.last_answer.id, last_answer.id) eq_(Answer.objects.filter(pk=answer.id).count(), 0)
def test_new_answer_updates_question(self): """Test saving a new answer updates the corresponding question. Specifically, last_post and num_replies should update.""" question = Question(title='Test Question', content='Lorem Ipsum Dolor', creator_id=118533) question.save() eq_(0, question.num_answers) eq_(None, question.last_answer) answer = Answer(question=question, creator_id=47963, content="Test Answer") answer.save() question = Question.objects.get(pk=question.id) eq_(1, question.num_answers) eq_(answer, question.last_answer) question.delete()
def test_new_answer_updates_question(self): """Test saving a new answer updates the corresponding question. Specifically, last_post and num_replies should update.""" question = Question(title='Test Question', content='Lorem Ipsum Dolor', creator_id=118533) question.save() updated = question.updated eq_(0, question.num_answers) eq_(None, question.last_answer) answer = Answer(question=question, creator_id=47963, content="Test Answer") answer.save() question = Question.objects.get(pk=question.id) eq_(1, question.num_answers) eq_(answer, question.last_answer) self.assertNotEqual(updated, question.updated) question.delete()