コード例 #1
0
ファイル: test_es.py プロジェクト: rootmeb/kitsune
    def test_top_contributors(self):
        # There should be no top contributors since there are no answers.
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))

        # Add an answer, we now have a top conributor.
        a = AnswerFactory()
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        lis = doc('#top-contributors ol li')
        eq_(1, len(lis))
        eq_(Profile.objects.get(user=a.creator).display_name, lis[0].text)

        # Make answer 91 days old. There should no be top contributors.
        a.created = datetime.now() - timedelta(days=91)
        a.save()
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))
コード例 #2
0
ファイル: test_es.py プロジェクト: 1234-/kitsune
    def test_top_contributors(self):
        # There should be no top contributors since there are no answers.
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))

        # Add an answer, we now have a top conributor.
        a = AnswerFactory()
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        lis = doc('#top-contributors ol li')
        eq_(1, len(lis))
        eq_(Profile.objects.get(user=a.creator).display_name, lis[0].text)

        # Make answer 91 days old. There should no be top contributors.
        a.created = datetime.now() - timedelta(days=91)
        a.save()
        self.refresh()
        response = self.client.get(reverse('questions.list', args=['all']))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(0, len(doc('#top-contributors ol li')))
コード例 #3
0
ファイル: test_es.py プロジェクト: 1234-/kitsune
    def test_data_in_index(self):
        """Verify the data we are indexing."""
        p = ProductFactory()
        q = QuestionFactory(locale='pt-BR', product=p)
        a = AnswerFactory(question=q)

        self.refresh()

        eq_(AnswerMetricsMappingType.search().count(), 1)
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['locale'], q.locale)
        eq_(data['product'], [p.slug])
        eq_(data['creator_id'], a.creator_id)
        eq_(data['is_solution'], False)
        eq_(data['by_asker'], False)

        # Mark as solution and verify
        q.solution = a
        q.save()

        self.refresh()
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['is_solution'], True)

        # Make the answer creator to be the question creator and verify.
        a.creator = q.creator
        a.save()

        self.refresh()
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['by_asker'], True)
コード例 #4
0
ファイル: test_es.py プロジェクト: rootmeb/kitsune
    def test_data_in_index(self):
        """Verify the data we are indexing."""
        p = ProductFactory()
        q = QuestionFactory(locale='pt-BR', product=p)
        a = AnswerFactory(question=q)

        self.refresh()

        eq_(AnswerMetricsMappingType.search().count(), 1)
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['locale'], q.locale)
        eq_(data['product'], [p.slug])
        eq_(data['creator_id'], a.creator_id)
        eq_(data['is_solution'], False)
        eq_(data['by_asker'], False)

        # Mark as solution and verify
        q.solution = a
        q.save()

        self.refresh()
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['is_solution'], True)

        # Make the answer creator to be the question creator and verify.
        a.creator = q.creator
        a.save()

        self.refresh()
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['by_asker'], True)
コード例 #5
0
ファイル: test_models.py プロジェクト: rootmeb/kitsune
 def test_update_page_task(self):
     a = AnswerFactory()
     a.page = 4
     a.save()
     a = Answer.objects.get(pk=a.id)
     assert a.page == 4
     update_answer_pages(a.question.id)
     a = Answer.objects.get(pk=a.id)
     assert a.page == 1
コード例 #6
0
ファイル: test_models.py プロジェクト: rootmeb/kitsune
 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
コード例 #7
0
ファイル: test_models.py プロジェクト: 1234-/kitsune
 def test_update_page_task(self):
     a = AnswerFactory()
     a.page = 4
     a.save()
     a = Answer.objects.get(pk=a.id)
     assert a.page == 4
     update_answer_pages(a.question)
     a = Answer.objects.get(pk=a.id)
     assert a.page == 1
コード例 #8
0
ファイル: test_models.py プロジェクト: 1234-/kitsune
 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
コード例 #9
0
ファイル: test_es.py プロジェクト: rootmeb/kitsune
    def test_answer_spam_is_unindexed(self):
        search = QuestionMappingType.search()

        a = AnswerFactory(content='I am spam')
        self.refresh()
        eq_(search.query(question_answer_content__match='spam').count(), 1)

        a.is_spam = True
        a.save()
        self.refresh()
        eq_(search.query(question_answer_content__match='spam').count(), 0)
コード例 #10
0
ファイル: test_es.py プロジェクト: 1234-/kitsune
    def test_answer_spam_is_unindexed(self):
        search = QuestionMappingType.search()

        a = AnswerFactory(content=u'I am spam')
        self.refresh()
        eq_(search.query(question_answer_content__match='spam').count(), 1)

        a.is_spam = True
        a.save()
        self.refresh()
        eq_(search.query(question_answer_content__match='spam').count(), 0)
コード例 #11
0
ファイル: test_models.py プロジェクト: zu83/kitsune
    def test_delete_solution_of_question(self):
        """Deleting the solution of a Question should update the question."""
        # set a solution to the question
        q = AnswerFactory().question
        solution = q.last_answer
        q.solution = solution
        q.save()

        # delete the solution and question.solution should go back to None
        solution.delete()
        q = Question.objects.get(pk=q.id)
        eq_(q.solution, None)
コード例 #12
0
ファイル: test_models.py プロジェクト: 1234-/kitsune
    def test_delete_solution_of_question(self):
        """Deleting the solution of a Question should update the question.
        """
        # set a solution to the question
        q = AnswerFactory().question
        solution = q.last_answer
        q.solution = solution
        q.save()

        # delete the solution and question.solution should go back to None
        solution.delete()
        q = Question.objects.get(pk=q.id)
        eq_(q.solution, None)
コード例 #13
0
ファイル: test_models.py プロジェクト: 1234-/kitsune
    def test_new_answer_updates_question(self):
        """Test saving a new answer updates the corresponding question.
        Specifically, last_post and num_replies should update."""
        q = QuestionFactory(title='Test Question', content='Lorem Ipsum Dolor')
        updated = q.updated

        eq_(0, q.num_answers)
        eq_(None, q.last_answer)

        a = AnswerFactory(question=q, content='Test Answer')
        a.save()

        q = Question.objects.get(pk=q.id)
        eq_(1, q.num_answers)
        eq_(a, q.last_answer)
        self.assertNotEqual(updated, q.updated)
コード例 #14
0
ファイル: test_models.py プロジェクト: rootmeb/kitsune
    def test_new_answer_updates_question(self):
        """Test saving a new answer updates the corresponding question.
        Specifically, last_post and num_replies should update."""
        q = QuestionFactory(title="Test Question", content="Lorem Ipsum Dolor")
        updated = q.updated

        eq_(0, q.num_answers)
        eq_(None, q.last_answer)

        a = AnswerFactory(question=q, content="Test Answer")
        a.save()

        q = Question.objects.get(pk=q.id)
        eq_(1, q.num_answers)
        eq_(a, q.last_answer)
        self.assertNotEqual(updated, q.updated)
コード例 #15
0
class TestMarkingSolved(TestCaseBase):
    def setUp(self):
        u = UserFactory()
        self.client.login(username=u.username, password="******")
        self.question = QuestionFactory(creator=u)
        self.answer = AnswerFactory(question=self.question)

    def test_cannot_mark_spam_answer(self):
        self.answer.is_spam = True
        self.answer.save()

        res = self.client.get(reverse("questions.solve", args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)

    def test_cannot_mark_answers_on_spam_question(self):
        self.question.is_spam = True
        self.question.save()

        res = self.client.get(reverse("questions.solve", args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)
コード例 #16
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
class TestMarkingSolved(TestCaseBase):
    def setUp(self):
        u = UserFactory()
        self.client.login(username=u.username, password='******')
        self.question = QuestionFactory(creator=u)
        self.answer = AnswerFactory(question=self.question)

    def test_cannot_mark_spam_answer(self):
        self.answer.is_spam = True
        self.answer.save()

        res = self.client.get(
            reverse('questions.solve',
                    args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)

    def test_cannot_mark_answers_on_spam_question(self):
        self.question.is_spam = True
        self.question.save()

        res = self.client.get(
            reverse('questions.solve',
                    args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)
コード例 #17
0
ファイル: test_views.py プロジェクト: Andisutra80/kitsune
class TestVoteAnswers(TestCaseBase):
    def setUp(self):
        u = UserFactory()
        self.client.login(username=u.username, password='******')
        self.question = QuestionFactory()
        self.answer = AnswerFactory(question=self.question)

    def test_cannot_vote_for_answers_on_spam_question(self):
        self.question.is_spam = True
        self.question.save()

        res = self.client.post(
            reverse('questions.answer_vote',
                    args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)

    def test_cannot_vote_for_answers_marked_spam(self):
        self.answer.is_spam = True
        self.answer.save()

        res = self.client.post(
            reverse('questions.answer_vote',
                    args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)
コード例 #18
0
ファイル: test_views.py プロジェクト: whitemike889/kitsune
class TestVoteAnswers(TestCaseBase):
    def setUp(self):
        u = UserFactory()
        self.client.login(username=u.username, password="******")
        self.question = QuestionFactory()
        self.answer = AnswerFactory(question=self.question)

    def test_cannot_vote_for_answers_on_spam_question(self):
        self.question.is_spam = True
        self.question.save()

        res = self.client.post(
            reverse("questions.answer_vote",
                    args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)

    def test_cannot_vote_for_answers_marked_spam(self):
        self.answer.is_spam = True
        self.answer.save()

        res = self.client.post(
            reverse("questions.answer_vote",
                    args=[self.question.id, self.answer.id]))
        eq_(res.status_code, 404)
コード例 #19
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, [])