Exemplo n.º 1
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())
Exemplo n.º 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())
Exemplo n.º 3
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())
Exemplo n.º 4
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())
Exemplo n.º 5
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())
Exemplo n.º 6
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'])
Exemplo n.º 7
0
    def test_document_listing_order(self):
        """Verify documents are listed in order of helpful votes."""
        # Create topic, product and documents.
        p = product(save=True)
        t = topic(product=p, 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 > ul > li:first-child > a').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 > ul > li:first-child > a').text(), docs[2].title)
Exemplo n.º 8
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_(
            DocumentMappingType.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_(
            DocumentMappingType.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_(
            DocumentMappingType.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_(
            DocumentMappingType.search().filter(
                document_recent_helpful_votes__gt=0).count(), 1)
Exemplo n.º 9
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_(DocumentMappingType.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_(DocumentMappingType.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_(DocumentMappingType.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_(DocumentMappingType.search().filter(
            document_recent_helpful_votes__gt=0).count(), 1)
Exemplo n.º 10
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'])
Exemplo n.º 11
0
    def test_document_listing_order(self):
        """Verify documents are listed in order of helpful votes."""
        # Create topic, product and documents.
        p = product(save=True)
        t = topic(product=p, 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 > ul > li:first-child > a').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 > ul > li:first-child > a').text(), docs[2].title)
Exemplo n.º 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"]
Exemplo n.º 13
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']
Exemplo n.º 14
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']
Exemplo n.º 15
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)

        # Assign 2 documents to Firefox OS and 1 to Firefox
        firefox_os = product(slug='firefox-os', save=True)
        firefox = product(slug='firefox', save=True)
        r1.document.products.add(firefox_os)
        r2.document.products.add(firefox_os)
        r3.document.products.add(firefox)

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

        # Only en-US votes:
        r = self._get_api_result('api.kpi.kb-votes', 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('api.kpi.kb-votes', locale='es')
        eq_(r['objects'][0]['kb_helpful'], 2)
        eq_(r['objects'][0]['kb_votes'], 6)

        # Only Firefox OS votes:
        r = self._get_api_result('api.kpi.kb-votes', product='firefox-os')
        eq_(r['objects'][0]['kb_helpful'], 2)
        eq_(r['objects'][0]['kb_votes'], 6)

        # Only Firefox votes:
        r = self._get_api_result('api.kpi.kb-votes', product='firefox')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)

        # Only Firefox OS + es votes:
        r = self._get_api_result('api.kpi.kb-votes',
                                 product='firefox-os',
                                 locale='es')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
Exemplo n.º 16
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)

        # Assign 2 documents to Firefox OS and 1 to Firefox
        firefox_os = product(slug='firefox-os', save=True)
        firefox = product(slug='firefox', save=True)
        r1.document.products.add(firefox_os)
        r2.document.products.add(firefox_os)
        r3.document.products.add(firefox)

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

        # Only en-US votes:
        r = self._get_api_result('api.kpi.kb-votes', 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('api.kpi.kb-votes', locale='es')
        eq_(r['objects'][0]['kb_helpful'], 2)
        eq_(r['objects'][0]['kb_votes'], 6)

        # Only Firefox OS votes:
        r = self._get_api_result('api.kpi.kb-votes', product='firefox-os')
        eq_(r['objects'][0]['kb_helpful'], 2)
        eq_(r['objects'][0]['kb_votes'], 6)

        # Only Firefox votes:
        r = self._get_api_result('api.kpi.kb-votes', product='firefox')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)

        # Only Firefox OS + es votes:
        r = self._get_api_result(
            'api.kpi.kb-votes', product='firefox-os', locale='es')
        eq_(r['objects'][0]['kb_helpful'], 1)
        eq_(r['objects'][0]['kb_votes'], 3)
Exemplo n.º 17
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())
Exemplo n.º 18
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)
Exemplo n.º 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)
        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)
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
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)
Exemplo n.º 23
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)