示例#1
0
    def test_unhelpful_survey(self):
        """The unhelpful survey is stored as vote metadata"""
        vote = helpful_vote(save=True)
        url = reverse('wiki.unhelpful_survey')
        data = {'vote_id': vote.id,
                'button': 'Submit',
                'confusing': 1,
                'too-long': 1,
                'comment': 'lorem ipsum dolor'}
        response = self.client.post(url, data)
        eq_(200, response.status_code)
        eq_('{"message": "Thanks for making us better!"}',
            response.content)

        vote_meta = vote.metadata.all()
        eq_(1, len(vote_meta))
        eq_('survey', vote_meta[0].key)

        survey = json.loads(vote_meta[0].value)
        eq_(3, len(survey.keys()))
        assert 'confusing' in survey
        assert 'too-long' in survey
        eq_('lorem ipsum dolor', survey['comment'])

        # Posting the survey again shouldn't add a new survey result.
        self.client.post(url, data)
        eq_(1, vote.metadata.filter(key='survey').count())
示例#2
0
    def test_unhelpful_survey(self):
        """The unhelpful survey is stored as vote metadata"""
        vote = helpful_vote(save=True)
        url = reverse('wiki.unhelpful_survey')
        data = {
            'vote_id': vote.id,
            'button': 'Submit',
            'confusing': 1,
            'too-long': 1,
            'comment': 'lorem ipsum dolor'
        }
        response = self.client.post(url, data)
        eq_(200, response.status_code)
        eq_('{"message": "Thanks for making us better!"}', response.content)

        vote_meta = vote.metadata.all()
        eq_(1, len(vote_meta))
        eq_('survey', vote_meta[0].key)

        survey = json.loads(vote_meta[0].value)
        eq_(3, len(survey.keys()))
        assert 'confusing' in survey
        assert 'too-long' in survey
        eq_('lorem ipsum dolor', survey['comment'])

        # Posting the survey again shouldn't add a new survey result.
        self.client.post(url, data)
        eq_(1, vote.metadata.filter(key='survey').count())
示例#3
0
 def test_unhelpful_survey_on_helpful_vote(self):
     """Verify a survey doesn't get saved on helpful votes."""
     vote = helpful_vote(helpful=True, save=True)
     url = reverse('wiki.unhelpful_survey')
     data = {'vote_id': vote.id,
             'button': 'Submit',
             'confusing': 1,
             'too-long': 1,
             'comment': 'lorem ipsum dolor'}
     self.client.post(url, data)
     eq_(0, vote.metadata.count())
示例#4
0
    def test_advanced_search_sortby_documents_helpful(self):
        """Tests advanced search with a sortby_documents by helpful"""
        r1 = revision(is_approved=True, save=True)
        r2 = revision(is_approved=True, save=True)
        helpful_vote(revision=r2, helpful=True, save=True)

        # Note: We have to wipe and rebuild the index because new
        # helpful_votes don't update the index data.
        self.setup_indexes()
        self.reindex_and_refresh()

        # r2.document should come first with 1 vote.
        response = self.client.get(reverse('search'), {
            'w': '1', 'a': '1', 'sortby_documents': 'helpful',
            'format': 'json'})
        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(r2.document.title, content['results'][0]['title'])

        # Vote twice on r1, now it should come first.
        helpful_vote(revision=r1, helpful=True, save=True)
        helpful_vote(revision=r1, helpful=True, save=True)

        self.setup_indexes()
        self.reindex_and_refresh()

        response = self.client.get(reverse('search'), {
            'w': '1', 'a': '1', 'sortby_documents': 'helpful',
            'format': 'json'})
        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(r1.document.title, content['results'][0]['title'])
示例#5
0
    def test_vote(self):
        """Test vote API call."""
        u = user(save=True)
        add_permission(u, Profile, 'view_kpi_dashboard')

        r = revision(save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, helpful=True, save=True)

        a = answer(save=True)
        answer_vote(answer=a, save=True)
        answer_vote(answer=a, helpful=True, save=True)
        answer_vote(answer=a, helpful=True, save=True)

        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_vote',
                              'api_name': 'v1'})
        self.client.login(username=u.username, password='******')
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
        eq_(r['objects'][0]['ans_helpful'], 2)
        eq_(r['objects'][0]['ans_votes'], 3)
示例#6
0
    def test_recent_helpful_votes(self):
        """Recent helpful votes are indexed properly."""
        # Create a document and verify it doesn't show up in a
        # query for recent_helpful_votes__gt=0.
        r = revision(is_approved=True, save=True)
        self.refresh()
        eq_(Document.search().filter(
            document_recent_helpful_votes__gt=0).count(), 0)

        # Add an unhelpful vote, it still shouldn't show up.
        helpful_vote(revision=r, helpful=False, save=True)
        r.document.save()  # Votes don't trigger a reindex.
        self.refresh()
        eq_(Document.search().filter(
            document_recent_helpful_votes__gt=0).count(), 0)

        # Add an helpful vote created 31 days ago, it still shouldn't show up.
        created = datetime.now() - timedelta(days=31)
        helpful_vote(revision=r, helpful=True, created=created, save=True)
        r.document.save()  # Votes don't trigger a reindex.
        self.refresh()
        eq_(Document.search().filter(
            document_recent_helpful_votes__gt=0).count(), 0)

        # Add an helpful vote created 29 days ago, it should show up now.
        created = datetime.now() - timedelta(days=29)
        helpful_vote(revision=r, helpful=True, created=created, save=True)
        r.document.save()  # Votes don't trigger a reindex.
        self.refresh()
        eq_(Document.search().filter(
            document_recent_helpful_votes__gt=0).count(), 1)
示例#7
0
    def test_advanced_search_sortby_documents_helpful(self):
        """Tests advanced search with a sortby_documents by helpful"""
        r1 = revision(is_approved=True, save=True)
        r2 = revision(is_approved=True, save=True)
        helpful_vote(revision=r2, helpful=True, save=True)

        # Note: We have to wipe and rebuild the index because new
        # helpful_votes don't update the index data.
        self.setup_indexes()
        self.reindex_and_refresh()

        # r2.document should come first with 1 vote.
        response = self.client.get(reverse('search'), {
            'w': '1', 'a': '1', 'sortby_documents': 'helpful',
            'format': 'json'})
        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(r2.document.title, content['results'][0]['title'])

        # Vote twice on r1, now it should come first.
        helpful_vote(revision=r1, helpful=True, save=True)
        helpful_vote(revision=r1, helpful=True, save=True)

        self.setup_indexes()
        self.reindex_and_refresh()

        response = self.client.get(reverse('search'), {
            'w': '1', 'a': '1', 'sortby_documents': 'helpful',
            'format': 'json'})
        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(r1.document.title, content['results'][0]['title'])
示例#8
0
文件: test_es.py 项目: ibai/kitsune
    def test_recent_helpful_votes(self):
        """Recent helpful votes are indexed properly."""
        # Create a document and verify it doesn't show up in a
        # query for recent_helpful_votes__gt=0.
        r = revision(is_approved=True, save=True)
        self.refresh()
        eq_(
            Document.search().filter(
                document_recent_helpful_votes__gt=0).count(), 0)

        # Add an unhelpful vote, it still shouldn't show up.
        helpful_vote(revision=r, helpful=False, save=True)
        r.document.save()  # Votes don't trigger a reindex.
        self.refresh()
        eq_(
            Document.search().filter(
                document_recent_helpful_votes__gt=0).count(), 0)

        # Add an helpful vote created 31 days ago, it still shouldn't show up.
        created = datetime.now() - timedelta(days=31)
        helpful_vote(revision=r, helpful=True, created=created, save=True)
        r.document.save()  # Votes don't trigger a reindex.
        self.refresh()
        eq_(
            Document.search().filter(
                document_recent_helpful_votes__gt=0).count(), 0)

        # Add an helpful vote created 29 days ago, it should show up now.
        created = datetime.now() - timedelta(days=29)
        helpful_vote(revision=r, helpful=True, created=created, save=True)
        r.document.save()  # Votes don't trigger a reindex.
        self.refresh()
        eq_(
            Document.search().filter(
                document_recent_helpful_votes__gt=0).count(), 1)
示例#9
0
 def test_unhelpful_survey_on_helpful_vote(self):
     """Verify a survey doesn't get saved on helpful votes."""
     vote = helpful_vote(helpful=True, save=True)
     url = reverse('wiki.unhelpful_survey')
     data = {
         'vote_id': vote.id,
         'button': 'Submit',
         'confusing': 1,
         'too-long': 1,
         'comment': 'lorem ipsum dolor'
     }
     self.client.post(url, data)
     eq_(0, vote.metadata.count())
示例#10
0
    def test_unhelpful_truncation(self):
        """Give helpful_vote a survey that is too long.

        It should be truncated safely, instead of generating bad JSON.
        """
        vote = helpful_vote(save=True)
        too_long_comment = ("lorem ipsum" * 100) + "bad data"
        self.client.post(
            reverse("wiki.unhelpful_survey"), {"vote_id": vote.id, "button": "Submit", "comment": too_long_comment}
        )
        vote_meta = vote.metadata.all()[0]
        # Will fail if it is not proper json, ie: bad truncation happened.
        survey = json.loads(vote_meta.value)
        # Make sure the right value was truncated.
        assert "bad data" not in survey["comment"]
示例#11
0
    def test_unhelpful_truncation(self):
        """Give helpful_vote a survey that is too long.

        It should be truncated safely, instead of generating bad JSON.
        """
        vote = helpful_vote(save=True)
        too_long_comment = ('lorem ipsum' * 100) + 'bad data'
        self.client.post(reverse('wiki.unhelpful_survey'),
                         {'vote_id': vote.id,
                          'button': 'Submit',
                          'comment': too_long_comment})
        vote_meta = vote.metadata.all()[0]
        # Will fail if it is not proper json, ie: bad truncation happened.
        survey = json.loads(vote_meta.value)
        # Make sure the right value was truncated.
        assert 'bad data' not in survey['comment']
示例#12
0
    def test_unhelpful_truncation(self):
        """Give helpful_vote a survey that is too long.

        It should be truncated safely, instead of generating bad JSON.
        """
        vote = helpful_vote(save=True)
        too_long_comment = ('lorem ipsum' * 100) + 'bad data'
        self.client.post(reverse('wiki.unhelpful_survey'), {
            'vote_id': vote.id,
            'button': 'Submit',
            'comment': too_long_comment
        })
        vote_meta = vote.metadata.all()[0]
        # Will fail if it is not proper json, ie: bad truncation happened.
        survey = json.loads(vote_meta.value)
        # Make sure the right value was truncated.
        assert 'bad data' not in survey['comment']
示例#13
0
    def test_unhelpful_survey(self):
        """The unhelpful survey is stored as vote metadata"""
        vote = helpful_vote(save=True)
        response = self.client.post(
            reverse("wiki.unhelpful_survey"),
            {"vote_id": vote.id, "button": "Submit", "confusing": 1, "too-long": 1, "comment": "lorem ipsum dolor"},
        )
        eq_(200, response.status_code)
        eq_('{"message": "Thanks for making us better!"}', response.content)

        vote_meta = vote.metadata.all()[0]
        eq_("survey", vote_meta.key)

        survey = json.loads(vote_meta.value)
        eq_(3, len(survey.keys()))
        assert "confusing" in survey
        assert "too-long" in survey
        eq_("lorem ipsum dolor", survey["comment"])
示例#14
0
    def test_kb_vote(self):
        """Test vote API call."""
        r1 = revision(document=document(locale='en-US', save=True), save=True)
        r2 = revision(document=document(locale='es', save=True), save=True)
        for r in [r1, r2]:
            helpful_vote(revision=r, save=True)
            helpful_vote(revision=r, save=True)
            helpful_vote(revision=r, helpful=True, save=True)

        # Only the votes for r1 (locale=en-US) should be counted.
        r = self._get_api_result('kpi_kb_vote')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
示例#15
0
    def test_unhelpful_survey(self):
        """The unhelpful survey is stored as vote metadata"""
        vote = helpful_vote(save=True)
        response = self.client.post(reverse('wiki.unhelpful_survey'),
                                    {'vote_id': vote.id,
                                     'button': 'Submit',
                                     'confusing': 1,
                                     'too-long': 1,
                                     'comment': 'lorem ipsum dolor'})
        eq_(200, response.status_code)
        eq_('{"message": "Thanks for making us better!"}',
            response.content)

        vote_meta = vote.metadata.all()[0]
        eq_('survey', vote_meta.key)

        survey = json.loads(vote_meta.value)
        eq_(3, len(survey.keys()))
        assert 'confusing' in survey
        assert 'too-long' in survey
        eq_('lorem ipsum dolor', survey['comment'])
示例#16
0
    def test_unhelpful_survey(self):
        """The unhelpful survey is stored as vote metadata"""
        vote = helpful_vote(save=True)
        response = self.client.post(
            reverse('wiki.unhelpful_survey'), {
                'vote_id': vote.id,
                'button': 'Submit',
                'confusing': 1,
                'too-long': 1,
                'comment': 'lorem ipsum dolor'
            })
        eq_(200, response.status_code)
        eq_('{"message": "Thanks for making us better!"}', response.content)

        vote_meta = vote.metadata.all()[0]
        eq_('survey', vote_meta.key)

        survey = json.loads(vote_meta.value)
        eq_(3, len(survey.keys()))
        assert 'confusing' in survey
        assert 'too-long' in survey
        eq_('lorem ipsum dolor', survey['comment'])
示例#17
0
    def test_vote(self):
        """Test vote API call."""
        r = revision(save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, helpful=True, save=True)

        a = answer(save=True)
        answervote(answer=a, save=True)
        answervote(answer=a, helpful=True, save=True)
        answervote(answer=a, helpful=True, save=True)

        r = self._get_api_result('kpi_vote')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
        eq_(r['objects'][0]['ans_helpful'], 2)
        eq_(r['objects'][0]['ans_votes'], 3)
示例#18
0
文件: test_api.py 项目: ibai/kitsune
    def test_vote(self):
        """Test vote API call."""
        r = revision(save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, helpful=True, save=True)

        a = answer(save=True)
        answervote(answer=a, save=True)
        answervote(answer=a, helpful=True, save=True)
        answervote(answer=a, helpful=True, save=True)

        r = self._get_api_result('kpi_vote')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
        eq_(r['objects'][0]['ans_helpful'], 2)
        eq_(r['objects'][0]['ans_votes'], 3)
示例#19
0
    def test_vote(self):
        """Test vote API call."""
        r = revision(save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, save=True)
        helpful_vote(revision=r, helpful=True, save=True)

        a = answer(save=True)
        answer_vote(answer=a, save=True)
        answer_vote(answer=a, helpful=True, save=True)
        answer_vote(answer=a, helpful=True, save=True)

        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_vote',
                              'api_name': 'v1'})
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
        eq_(r['objects'][0]['ans_helpful'], 2)
        eq_(r['objects'][0]['ans_votes'], 3)
示例#20
0
    def test_kb_vote(self):
        """Test vote API call."""
        r1 = revision(document=document(locale='en-US', save=True), save=True)
        r2 = revision(document=document(locale='es', save=True), save=True)
        r3 = revision(document=document(locale='es', save=True), save=True)
        for r in [r1, r2, r3]:
            helpful_vote(revision=r, save=True)
            helpful_vote(revision=r, save=True)
            helpful_vote(revision=r, helpful=True, save=True)

        # All votes should be counted if we don't specify a locale
        r = self._get_api_result('kpi_kb_vote')
        eq_(r['objects'][0]['kb_helpful'], 3)
        eq_(r['objects'][0]['kb_votes'], 9)

        # Only en-US votes:
        r = self._get_api_result('kpi_kb_vote', locale='en-US')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)

        # Only es votes:
        r = self._get_api_result('kpi_kb_vote', locale='es')
        eq_(r['objects'][0]['kb_helpful'], 2)
        eq_(r['objects'][0]['kb_votes'], 6)
示例#21
0
    def test_document_listing_order(self, flag_is_active):
        """Verify documents are listed in order of helpful votes."""
        flag_is_active.return_value = True

        # Create topic, product and documents.
        t = topic(save=True)
        p = product(save=True)
        docs = []
        for i in range(3):
            doc = revision(is_approved=True, save=True).document
            doc.topics.add(t)
            doc.products.add(p)
            docs.append(doc)

        # Add a helpful vote to the second document. It should be first now.
        rev = docs[1].current_revision
        helpful_vote(revision=rev, helpful=True, save=True)
        docs[1].save()  # Votes don't trigger a reindex.
        self.refresh()
        url = reverse('products.documents', args=[p.slug, t.slug])
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(doc('#document-list li:first').text(), docs[1].title)

        # Add 2 helpful votes the third document. It should be first now.
        rev = docs[2].current_revision
        helpful_vote(revision=rev, helpful=True, save=True)
        helpful_vote(revision=rev, helpful=True, save=True)
        docs[2].save()  # Votes don't trigger a reindex.
        self.refresh()
        cache.clear()  # documents_for() is cached
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(doc('#document-list li:first').text(), docs[2].title)
示例#22
0
文件: test_api.py 项目: timmi/kitsune
    def test_kb_vote(self):
        """Test vote API call."""
        r1 = revision(document=document(locale='en-US', save=True), save=True)
        r2 = revision(document=document(locale='es', save=True), save=True)
        r3 = revision(document=document(locale='es', save=True), save=True)
        for r in [r1, r2, r3]:
            helpful_vote(revision=r, save=True)
            helpful_vote(revision=r, save=True)
            helpful_vote(revision=r, helpful=True, save=True)

        # All votes should be counted if we don't specify a locale
        r = self._get_api_result('kpi_kb_vote')
        eq_(r['objects'][0]['kb_helpful'], 3)
        eq_(r['objects'][0]['kb_votes'], 9)

        # Only en-US votes:
        r = self._get_api_result('kpi_kb_vote', locale='en-US')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)

        # Only es votes:
        r = self._get_api_result('kpi_kb_vote', locale='es')
        eq_(r['objects'][0]['kb_helpful'], 2)
        eq_(r['objects'][0]['kb_votes'], 6)