def test_delete_updates_pages(self): a1 = AnswerFactory() a2 = AnswerFactory(question=a1.question) AnswerFactory(question=a1.question) a1.page = 7 a1.save() a2.delete() a3 = Answer.objects.filter(question=a1.question)[0] assert a3.page == 1, "Page was %s" % a3.page
def test_add_and_delete(self): """Adding an answer should add it to the index. Deleting should delete it. """ a = AnswerFactory() self.refresh() eq_(AnswerMetricsMappingType.search().count(), 1) a.delete() self.refresh() eq_(AnswerMetricsMappingType.search().count(), 0)
def test_delete_answer_removes_flag(self): """Deleting an answer also removes the flags on that answer.""" q = QuestionFactory(title='Test Question', content='Lorem Ipsum Dolor') a = AnswerFactory(question=q, content='Test Answer') u = UserFactory() FlaggedObject.objects.create( status=0, content_object=a, reason='language', creator_id=u.id) eq_(1, FlaggedObject.objects.count()) a.delete() eq_(0, FlaggedObject.objects.count())
def test_delete_answer_removes_flag(self): """Deleting an answer also removes the flags on that answer.""" q = QuestionFactory(title="Test Question", content="Lorem Ipsum Dolor") a = AnswerFactory(question=q, content="Test Answer") u = UserFactory() FlaggedObject.objects.create( status=0, content_object=a, reason="language", creator_id=u.id ) eq_(1, FlaggedObject.objects.count()) a.delete() eq_(0, FlaggedObject.objects.count())
def test_num_answers(self): u = UserFactory() q = QuestionFactory() eq_(num_answers(u), 0) a1 = AnswerFactory(creator=u, question=q) eq_(num_answers(u), 1) a2 = AnswerFactory(creator=u, question=q) eq_(num_answers(u), 2) a1.delete() eq_(num_answers(u), 1) a2.delete() eq_(num_answers(u), 0)
def test_delete_last_answer_of_question(self): """Deleting the last_answer of a Question should update the question.""" yesterday = datetime.now() - timedelta(days=1) q = AnswerFactory(created=yesterday).question last_answer = q.last_answer # add a new answer and verify last_answer updated a = AnswerFactory(question=q, content="Test Answer") q = Question.objects.get(pk=q.id) eq_(q.last_answer.id, a.id) # delete the answer and last_answer should go back to previous value a.delete() q = Question.objects.get(pk=q.id) eq_(q.last_answer.id, last_answer.id) eq_(Answer.objects.filter(pk=a.id).count(), 0)
def test_delete_last_answer_of_question(self): """Deleting the last_answer of a Question should update the question. """ yesterday = datetime.now() - timedelta(days=1) q = AnswerFactory(created=yesterday).question last_answer = q.last_answer # add a new answer and verify last_answer updated a = AnswerFactory(question=q, content='Test Answer') q = Question.objects.get(pk=q.id) eq_(q.last_answer.id, a.id) # delete the answer and last_answer should go back to previous value a.delete() q = Question.objects.get(pk=q.id) eq_(q.last_answer.id, last_answer.id) eq_(Answer.objects.filter(pk=a.id).count(), 0)
def test_question_one_answer_deleted(self): search = QuestionMappingType.search() q = QuestionFactory(title='are model makers the new pink?') a = AnswerFactory(content='yes.', question=q) self.refresh() # Question and its answers are a single document--so the index count should be only 1. eq_(search.query(question_title__match='pink').count(), 1) # After deleting the answer, the question document should remain. a.delete() self.refresh() eq_(search.query(question_title__match='pink').count(), 1) # Delete the question and it should be removed from the index. q.delete() self.refresh() eq_(search.query(question_title__match='pink').count(), 0)
def test_question_one_answer_deleted(self): search = QuestionMappingType.search() q = QuestionFactory(title=u'are model makers the new pink?') a = AnswerFactory(content=u'yes.', question=q) self.refresh() # Question and its answers are a single document--so the index count should be only 1. eq_(search.query(question_title__match='pink').count(), 1) # After deleting the answer, the question document should remain. a.delete() self.refresh() eq_(search.query(question_title__match='pink').count(), 1) # Delete the question and it should be removed from the index. q.delete() self.refresh() eq_(search.query(question_title__match='pink').count(), 0)
def test_num_solutions(self): u = UserFactory() q1 = QuestionFactory() q2 = QuestionFactory() a1 = AnswerFactory(creator=u, question=q1) a2 = AnswerFactory(creator=u, question=q2) eq_(num_solutions(u), 0) q1.solution = a1 q1.save() eq_(num_solutions(u), 1) q2.solution = a2 q2.save() eq_(num_solutions(u), 2) q1.solution = None q1.save() eq_(num_solutions(u), 1) a2.delete() eq_(num_solutions(u), 0)
class AnswerDocumentSignalsTests(Elastic7TestCase): def setUp(self): self.answer = AnswerFactory() self.answer_id = self.answer.id def get_doc(self): return AnswerDocument.get(self.answer_id) def test_answer_save(self): self.answer.content = "foobar" self.answer.save() self.assertEqual(self.get_doc().content["en-US"], "foobar") def test_vote_save(self): AnswerVoteFactory(answer=self.answer, helpful=True) self.assertEqual(self.get_doc().num_helpful_votes, 1) def test_question_save(self): question = self.answer.question question.title = "barfoo" question.save() self.assertEqual(self.get_doc().question_title["en-US"], "barfoo") def test_question_vote_save(self): QuestionVoteFactory(question=self.answer.question) self.assertEqual(self.get_doc().question_num_votes, 1) def test_question_tags_change(self): question = self.answer.question tag = TagFactory() question.tags.add(tag) self.assertIn(tag.id, self.get_doc().question_tag_ids) question.tags.remove(tag) self.assertNotIn(tag.id, self.get_doc().question_tag_ids) def test_answer_delete(self): self.answer.delete() with self.assertRaises(NotFoundError): self.get_doc() def test_vote_delete(self): vote = AnswerVoteFactory(answer=self.answer, helpful=True) vote.delete() self.assertEqual(self.get_doc().num_helpful_votes, 0) def test_question_delete(self): self.answer.question.delete() with self.assertRaises(NotFoundError): self.get_doc() def test_question_vote_delete(self): vote = QuestionVoteFactory(question=self.answer.question) vote.delete() self.assertEqual(self.get_doc().question_num_votes, 0) def test_question_tag_delete(self): tag = TagFactory() self.answer.question.tags.add(tag) tag.delete() self.assertEqual(self.get_doc().question_tag_ids, [])
def test_answer_delete(self): answer = AnswerFactory(question=self.question, content="foobar") answer.delete() self.assertNotIn("en-US", self.get_doc().answer_content)