Exemple #1
0
    def test_product_facets(self):
        """Verify the facet counts on the results page."""
        # Create products, questions and documents.
        p1 = product(title='Firefox', slug='firefox', save=True)
        p2 = product(title='Firefox for mobile', slug='mobile', save=True)

        ques = question(title=u'audio', save=True)
        ques.products.add(p1)
        ans = answer(question=ques, content=u'volume', save=True)
        answervote(answer=ans, helpful=True, save=True)

        doc = document(title=u'audio', locale=u'en-US', category=10, save=True)
        doc.products.add(p1)
        doc.products.add(p2)
        revision(document=doc, is_approved=True, save=True)

        self.refresh()

        # There should be 2 total results, 2 "firefox" results and
        # 1 "mobile" result.
        response = self.client.get(reverse('search'), {'q': 'audio'})
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_('Found 2 results for audio in English', doc('h2').text())
        facet_text = doc('#product-filter').text()
        assert 'Firefox (2)' in facet_text
        assert 'Firefox for mobile (1)' in facet_text
Exemple #2
0
    def test_question_products(self):
        """Search questions for products."""
        p1 = product(slug='b2g', save=True)
        p2 = product(slug='mobile', save=True)
        p3 = product(slug='desktop', save=True)

        q = question(save=True)
        q.products.add(p2)
        q = question(save=True)
        q.products.add(p2)
        q.products.add(p3)

        self.refresh()

        product_vals = (
            (p1.slug, 0),
            (p2.slug, 2),
            (p3.slug, 1),
            ([p2.slug, p3.slug], 1),
        )

        qs = {'a': 1, 'w': 2, 'format': 'json'}
        for products, number in product_vals:
            qs.update({'product': products})
            response = self.client.get(reverse('search'), qs)
            eq_(number, json.loads(response.content)['total'])
    def test_product_specific_ready(self):
        """Verify product-specific ready for l10n notifications."""
        # Add a Firefox OS watcher.
        ReadyRevisionEvent.notify(user(save=True), product='firefox-os')

        # Create a document for Firefox
        doc = document(save=True)
        doc.products.add(product(slug='firefox', save=True))

        # Mark a revision a ready for L10n. There should be only one email
        # to the watcher created in setUp.
        self._mark_as_ready_revision(doc=doc)
        eq_(1, len(mail.outbox))
        _assert_ready_mail(mail.outbox[0])

        # Add firefox-os to the document's products. Mark as ready for l10n,
        # and there should be two new emails.
        doc.products.add(product(slug='firefox-os', save=True))
        self._mark_as_ready_revision(doc=doc)
        eq_(3, len(mail.outbox))
        _assert_ready_mail(mail.outbox[1])
        _assert_ready_mail(mail.outbox[2])

        # Add a Firefox watcher, mark as ready for l10n, and there should
        # be three new emails.
        ReadyRevisionEvent.notify(user(save=True), product='firefox')
        self._mark_as_ready_revision(doc=doc)
        eq_(6, len(mail.outbox))
Exemple #4
0
    def test_filter_by_product(self):
        desktop = product(slug=u'desktop', save=True)
        mobile = product(slug=u'mobile', save=True)
        ques = question(title=u'audio', product=desktop, save=True)
        ans = answer(question=ques, content=u'volume', save=True)
        answervote(answer=ans, helpful=True, save=True)

        doc = document(title=u'audio', locale=u'en-US', category=10, save=True)
        doc.products.add(desktop)
        doc.products.add(mobile)
        revision(document=doc, is_approved=True, save=True)

        self.refresh()

        # There should be 2 results for desktop and 1 for mobile.
        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json', 'product': 'desktop'})
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['total'], 2)

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json', 'product': 'mobile'})
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['total'], 1)
Exemple #5
0
    def test_top_contributors_questions(self):
        firefox = product(slug='firefox', save=True)
        fxos = product(slug='firefox-os', save=True)
        a1 = answer(save=True)
        a1.question.products.add(firefox)
        a1.question.products.add(fxos)
        a2 = answer(creator=a1.creator, save=True)
        a3 = answer(save=True)
        a3.question.products.add(fxos)
        a4 = answer(created=datetime.now()-timedelta(days=91),
                    save=True)
        answer(creator=a4.question.creator, question=a4.question, save=True)

        for u in User.objects.all():
            profile(user=u)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top = top_contributors_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u['term'] for u in top]
        eq_(a1.creator_id, top[0]['term'])

        # Verify, filtering of Firefox questions only.
        top = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]['term'])
        top = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Exemple #6
0
    def test_filter_by_product(self):
        u1 = profile().user
        u2 = profile().user

        p1 = product(save=True)
        p2 = product(save=True)

        d1 = document(save=True)
        d1.products.add(p1)
        revision(document=d1, creator=u1, save=True)

        d2 = document(save=True)
        d2.products.add(p2)
        revision(document=d2, creator=u1, save=True)

        d3 = document(save=True)
        d3.products.add(p2)
        revision(document=d3, creator=u2, save=True)

        self.refresh()

        req = self.factory.get('/', {'product': p1.slug})
        data = self.api.get_data(req)

        eq_(data['count'], 1)
        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['revision_count'], 1)
Exemple #7
0
    def test_product_facets(self):
        """Verify the facet counts on the results page."""
        # Create products, questions and documents.
        p1 = product(title="Firefox", slug="firefox", save=True)
        p2 = product(title="Firefox for mobile", slug="mobile", save=True)

        ques = question(title=u"audio", save=True)
        ques.products.add(p1)
        ans = answer(question=ques, content=u"volume", save=True)
        answervote(answer=ans, helpful=True, save=True)

        doc = document(title=u"audio", locale=u"en-US", category=10, save=True)
        doc.products.add(p1)
        doc.products.add(p2)
        revision(document=doc, is_approved=True, save=True)

        self.refresh()

        # There should be 2 total results, 2 "firefox" results and
        # 1 "mobile" result.
        response = self.client.get(reverse("search"), {"q": "audio"})
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_("Found 2 results for audio in English", doc("h2").text())
        facet_text = doc("#product-filter").text()
        assert "Firefox (2)" in facet_text
        assert "Firefox for mobile (1)" in facet_text
Exemple #8
0
    def facets_setUp(self):
        # Create products
        self.desktop = product(slug='firefox', save=True)
        self.mobile = product(slug='mobile', save=True)

        # Create topics
        self.general_d = topic(
            product=self.desktop, slug='general', save=True)
        self.bookmarks_d = topic(
            product=self.desktop, slug='bookmarks', save=True)
        self.sync_d = topic(product=self.desktop, slug='sync', save=True)
        self.general_m = topic(
            product=self.mobile, slug='general', save=True)
        self.bookmarks_m = topic(
            product=self.mobile, slug='bookmarks', save=True)
        self.sync_m = topic(product=self.mobile, slug='sync', save=True)

        # Set up documents.
        doc1 = revision(is_approved=True, save=True).document
        doc1.topics.add(self.general_d)
        doc1.topics.add(self.bookmarks_d)
        doc1.products.add(self.desktop)

        doc2 = revision(is_approved=True, save=True).document
        doc2.topics.add(self.bookmarks_d)
        doc2.topics.add(self.bookmarks_m)
        doc2.topics.add(self.sync_d)
        doc2.topics.add(self.sync_m)
        doc2.products.add(self.desktop)
        doc2.products.add(self.mobile)

        # An archived article shouldn't show up
        doc3 = revision(is_approved=True, save=True).document
        doc3.is_archived = True
        doc3.save()
        doc3.topics.add(self.general_d)
        doc3.topics.add(self.bookmarks_d)
        doc3.products.add(self.desktop)

        # A template article shouldn't show up either
        doc4 = revision(is_approved=True, save=True).document
        doc4.category = 60
        doc4.title = 'Template: Test'
        doc4.save()
        doc4.topics.add(self.general_d)
        doc4.topics.add(self.bookmarks_d)
        doc4.products.add(self.desktop)

        # An article without current revision should be "invisible"
        # to everything.
        doc5 = revision(is_approved=False, save=True).document
        doc5.topics.add(self.general_d)
        doc5.topics.add(self.general_m)
        doc5.topics.add(self.bookmarks_d)
        doc5.topics.add(self.bookmarks_m)
        doc5.topics.add(self.sync_d)
        doc5.topics.add(self.sync_m)
        doc5.products.add(self.desktop)
        doc5.products.add(self.mobile)
Exemple #9
0
    def test_product_filter_works(self):
        p1 = product(save=True)
        p2 = product(save=True)
        q1 = self._make_question(product=p1)
        self._make_question(product=p2)
        self.refresh()

        req = self.client.get(reverse('search.suggest'), {'q': 'emails', 'product': p1.slug})
        eq_([q['id'] for q in req.data['questions']], [q1.id])
Exemple #10
0
    def test_filter_product_with_slug(self):
        p1 = product(save=True)
        p2 = product(save=True)
        q1 = question(product=p1, save=True)
        question(product=p2, save=True)

        querystring = '?product={0}'.format(p1.slug)
        res = self.client.get(reverse('question-list') + querystring)
        eq_(len(res.data['results']), 1)
        eq_(res.data['results'][0]['id'], q1.id)
Exemple #11
0
    def test_products(self):
        """Verify that /products page renders products."""
        # Create some products.
        for i in range(3):
            product(questions_enabled=True, save=True)

        # GET the products page and verify the content.
        r = self.client.get(reverse("products"), follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(3, len(doc("#products-and-services li")))
Exemple #12
0
    def test_products(self):
        """Verify that /products page renders products."""
        # Create some products.
        for i in range(3):
            product(save=True)

        # GET the products page and verify the content.
        r = self.client.get(reverse('products'), follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(4, len(doc('#products-and-services li')))
Exemple #13
0
    def test_get_products(self):
        """Test the get_products() method."""
        en_us = document(save=True)
        en_us.products.add(product(save=True))
        en_us.products.add(product(save=True))

        eq_(2, len(en_us.get_products()))

        # Localized document inherits parent's topics.
        document(parent=en_us, save=True)
        eq_(2, len(en_us.get_products()))
    def test_home(self):
        """Verify that home page renders products."""

        # Create some topics and products
        for i in range(4):
            product(save=True)

        # GET the home page and verify the content
        r = self.client.get(reverse('home'), follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(4, len(doc('#products-and-services li')))
Exemple #15
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)
Exemple #16
0
    def test_data_in_index(self):
        """Verify the data we are indexing."""
        p = product(save=True)
        q = question(locale='pt-BR', product=p, save=True)
        a = answer(question=q, save=True)

        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)
Exemple #17
0
    def setUp(self):
        super(ActiveContributorsTestCase, self).setUp()

        start_date = date.today() - timedelta(days=10)
        self.start_date = start_date
        before_start = start_date - timedelta(days=1)

        # Create some revisions to test with.

        # 3 'en-US' contributors:
        d = document(locale='en-US', save=True)
        u = user(save=True)
        self.user = u
        revision(document=d, is_approved=True, reviewer=u, save=True)
        revision(document=d, creator=u, save=True)

        self.product = product(save=True)
        r = revision(created=start_date, save=True)
        r.document.products.add(self.product)

        # Add one that shouldn't count:
        self.en_us_old = revision(document=d, created=before_start, save=True)

        # 4 'es' contributors:
        d = document(locale='es', save=True)
        revision(document=d, is_approved=True, reviewer=u, save=True)
        revision(document=d, creator=u, reviewer=user(save=True), save=True)
        revision(document=d, created=start_date, save=True)
        revision(document=d, save=True)
        # Add one that shouldn't count:
        self.es_old = revision(document=d, created=before_start, save=True)
Exemple #18
0
    def test_filter_by_doctype(self):
        desktop = product(slug=u"desktop", save=True)
        ques = question(title=u"audio", product=desktop, save=True)
        ans = answer(question=ques, content=u"volume", save=True)
        answervote(answer=ans, helpful=True, save=True)

        doc = document(title=u"audio", locale=u"en-US", category=10, save=True)
        doc.products.add(desktop)
        revision(document=doc, is_approved=True, save=True)

        doc = document(title=u"audio too", locale=u"en-US", category=10, save=True)
        doc.products.add(desktop)
        revision(document=doc, is_approved=True, save=True)

        self.refresh()

        # There should be 2 results for kb (w=1) and 1 for questions (w=2).
        response = self.client.get(reverse("search"), {"q": "audio", "format": "json", "w": "1"})
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content["total"], 2)

        response = self.client.get(reverse("search"), {"q": "audio", "format": "json", "w": "2"})
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content["total"], 1)
Exemple #19
0
    def test_default_search_for_wiki(self):
        """This tests whether doing a default search returns wiki document
        results.

        Bug #709202.

        """
        doc = document(title=u'audio', locale=u'en-US', category=10, save=True)
        doc.products.add(product(title=u'firefox', slug=u'desktop', save=True))
        revision(document=doc, is_approved=True, save=True)

        self.refresh()

        # This is the search that you get when you start on the sumo
        # homepage and do a search from the box with two differences:
        # first, we do it in json since it's easier to deal with
        # testing-wise and second, we search for 'audio' since we have
        # data for that.
        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json'})

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 1)
Exemple #20
0
    def test_locale_filter(self):
        """Only questions for the current locale should be shown on the
        questions front page for AAQ locales."""

        eq_(Question.objects.count(), 0)
        p = product(slug=u"firefox", save=True)
        topic(title="Fix problems", slug="fix-problems", product=p, save=True)

        q1 = question(title="question cupcakes?", save=True, locale="en-US")
        q1.products.add(p)
        q2 = question(title="question donuts?", save=True, locale="en-US")
        q2.products.add(p)
        q3 = question(title="question pies?", save=True, locale="pt-BR")
        q3.products.add(p)
        q4 = question(title="question pastries?", save=True, locale="de")
        q4.products.add(p)

        def sub_test(locale, *titles):
            url = urlparams(reverse("questions.questions", locale=locale))
            response = self.client.get(url, follow=True)
            doc = pq(response.content)
            eq_msg(len(doc("section[id^=question]")), len(titles), "Wrong number of results for {0}".format(locale))
            for substr in titles:
                assert substr in doc(".questions section .content h2 a").text()

        # en-US and pt-BR are both in AAQ_LANGUAGES, so should be filtered.
        sub_test("en-US", "cupcakes?", "donuts?")
        sub_test("pt-BR", "pies?")
        # de is not in AAQ_LANGUAGES, so should show en-US, but not pt-BR
        sub_test("de", "cupcakes?", "donuts?", "pastries?")
Exemple #21
0
    def test_default_only_shows_wiki_and_questions(self):
        """Tests that the default search doesn't show forums

        This verifies that we're only showing documents of the type
        that should be shown and that the filters on model are working
        correctly.

        Bug #767394

        """
        p = product(slug=u'desktop', save=True)
        ques = question(title=u'audio', save=True)
        ques.products.add(p)
        ans = answer(question=ques, content=u'volume', save=True)
        answervote(answer=ans, helpful=True, save=True)

        doc = document(title=u'audio', locale=u'en-US', category=10, save=True)
        doc.products.add(p)
        revision(document=doc, is_approved=True, save=True)

        thread1 = thread(title=u'audio', save=True)
        post(thread=thread1, save=True)

        self.refresh()

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json'})

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 2)
Exemple #22
0
    def test_product_landing(self):
        """Verify that /products/<slug> page renders topics."""
        # Create a product.
        p = product(save=True)

        # Create some topics.
        topic(slug=HOT_TOPIC_SLUG, product=p, save=True)
        topics = []
        for i in range(11):
            topics.append(topic(product=p, save=True))

        # Create a document and assign the product and 10 topics.
        doc = revision(is_approved=True, save=True).document
        doc.products.add(p)
        for i in range(10):
            doc.topics.add(topics[i])

        self.refresh()

        # GET the product landing page and verify the content.
        url = reverse('products.product', args=[p.slug])
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(11, len(doc('#help-topics li')))
        eq_(p.slug, doc('#support-search input[name=product]').attr['value'])
Exemple #23
0
    def test_search_suggestion_questions_locale(self):
        """Verifies the right languages show up in search suggestions."""
        topic(title='Fix problems', slug='fix-problems', save=True)
        p = product(slug=u'firefox', save=True)

        q1 = question(title='question cupcakes?', save=True, locale='en-US')
        q1.products.add(p)
        q2 = question(title='question donuts?', save=True, locale='en-US')
        q2.products.add(p)
        q3 = question(title='question pies?', save=True, locale='pt-BR')
        q3.products.add(p)
        q4 = question(title='question pastries?', save=True, locale='de')
        q4.products.add(p)

        self.refresh()

        def sub_test(locale, *titles):
            url = urlparams(reverse('questions.aaq_step4',
                                    args=['desktop', 'fix-problems'],
                                    locale=locale),
                            search='question')
            response = self.client.get(url, follow=True)
            doc = pq(response.content)
            eq_msg(len(doc('.result.question')), len(titles),
                   'Wrong number of results for {0}'.format(locale))
            for substr in titles:
                assert substr in doc('.result.question h3 a').text()

        sub_test('en-US', 'cupcakes?', 'donuts?')
        sub_test('pt-BR', 'cupcakes?', 'donuts?', 'pies?')
        sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
Exemple #24
0
    def test_search_suggestions_archived_articles(self):
        """Verifies that archived articles aren't shown."""
        topic(title='Fix problems', slug='fix-problems', save=True)
        p = product(slug=u'firefox', save=True)

        d1 = document(title=u'document donut', category=10, save=True)
        d1.products.add(p)
        revision(document=d1, is_approved=True, save=True)

        d2 = document(title=u'document cupcake', category=10, is_archived=True,
                      save=True)
        d2.products.add(p)
        revision(document=d1, is_approved=True, save=True)

        self.refresh()

        url = urlparams(
            reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
            search='document')

        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)

        doc = pq(response.content)
        eq_(len(doc('.result.document')), 1)
        assert 'donut' in doc('.result.document h3 a').text()
        assert 'cupcake' not in doc('.result.document h3 a').text()
Exemple #25
0
    def test_question_topics(self):
        """Search questions for topics."""
        p = product(save=True)
        t1 = topic(slug='doesnotexist', product=p, save=True)
        t2 = topic(slug='cookies', product=p, save=True)
        t3 = topic(slug='sync', product=p, save=True)

        q = question(save=True)
        q.topics.add(t2)
        q = question(save=True)
        q.topics.add(t2)
        q.topics.add(t3)

        self.refresh()

        topic_vals = (
            (t1.slug, 0),
            (t2.slug, 2),
            (t3.slug, 1),
            ([t2.slug, t3.slug], 1),
        )

        qs = {'a': 1, 'w': 2, 'format': 'json'}
        for topics, number in topic_vals:
            qs.update({'topics': topics})
            response = self.client.get(reverse('search'), qs)
            eq_(number, json.loads(response.content)['total'])
Exemple #26
0
    def test_search_suggestion_questions_locale(self):
        """Verifies the right languages show up in search suggestions."""
        p = product(slug=u"firefox", save=True)
        topic(title="Fix problems", slug="fix-problems", product=p, save=True)

        q1 = question(title="question cupcakes?", save=True, locale="en-US")
        q1.products.add(p)
        q2 = question(title="question donuts?", save=True, locale="en-US")
        q2.products.add(p)
        q3 = question(title="question pies?", save=True, locale="pt-BR")
        q3.products.add(p)
        q4 = question(title="question pastries?", save=True, locale="de")
        q4.products.add(p)

        self.refresh()

        def sub_test(locale, *titles):
            url = urlparams(
                reverse("questions.aaq_step4", args=["desktop", "fix-problems"], locale=locale), search="question"
            )
            response = self.client.get(url, follow=True)
            doc = pq(response.content)
            eq_msg(len(doc(".result.question")), len(titles), "Wrong number of results for {0}".format(locale))
            for substr in titles:
                assert substr in doc(".result.question h3 a").text()

        sub_test("en-US", "cupcakes?", "donuts?")
        sub_test("pt-BR", "cupcakes?", "donuts?", "pies?")
        sub_test("de", "cupcakes?", "donuts?", "pastries?")
Exemple #27
0
    def test_ratelimit(self):
        """Make sure posting new questions is ratelimited"""
        data = {'title': 'A test question',
                'content': 'I have this question that I hope...',
                'sites_affected': 'http://example.com',
                'ff_version': '3.6.6',
                'os': 'Intel Mac OS X 10.6',
                'plugins': '* Shockwave Flash 10.1 r53',
                'useragent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X '
                             '10.6; en-US; rv:1.9.2.6) Gecko/20100625 '
                             'Firefox/3.6.6'}
        p = product(slug='firefox', save=True)
        l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE)
        p.questions_locales.add(l)
        topic(slug='fix-problems', product=p, save=True)
        url = urlparams(
            reverse('questions.aaq_step5', args=['desktop', 'fix-problems']),
            search='A test question')

        u = user(save=True)
        self.client.login(username=u.username, password='******')

        for i in range(0, 5):
            self.client.post(url, data, follow=True)

        response = self.client.post(url, data, follow=True)
        eq_(403, response.status_code)
Exemple #28
0
    def test_locale_filter(self):
        """Only questions for the current locale should be shown on the
        questions front page for AAQ locales."""

        eq_(Question.objects.count(), 0)
        p = product(slug=u'firefox', save=True)
        topic(title='Fix problems', slug='fix-problems', product=p, save=True)

        question(
            title='question cupcakes?', product=p, save=True, locale='en-US')
        question(
            title='question donuts?', product=p, save=True, locale='en-US')
        question(
            title='question pies?', product=p, save=True, locale='pt-BR')
        question(
            title='question pastries?', product=p, save=True, locale='de')

        def sub_test(locale, *titles):
            url = urlparams(reverse(
                'questions.list', args=['all'], locale=locale))
            response = self.client.get(url, follow=True)
            doc = pq(response.content)
            eq_msg(len(doc('section[id^=question]')), len(titles),
                   'Wrong number of results for {0}'.format(locale))
            for substr in titles:
                assert substr in doc('.questions section .content h2 a').text()

        # en-US and pt-BR are both in AAQ_LANGUAGES, so should be filtered.
        sub_test('en-US', 'cupcakes?', 'donuts?')
        sub_test('pt-BR', 'pies?')
        # de is not in AAQ_LANGUAGES, so should show en-US, but not pt-BR
        sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
Exemple #29
0
    def test_ratelimit(self):
        """Make sure posting new questions is ratelimited"""
        data = {
            "title": "A test question",
            "content": "I have this question that I hope...",
            "sites_affected": "http://example.com",
            "ff_version": "3.6.6",
            "os": "Intel Mac OS X 10.6",
            "plugins": "* Shockwave Flash 10.1 r53",
            "useragent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X "
            "10.6; en-US; rv:1.9.2.6) Gecko/20100625 "
            "Firefox/3.6.6",
        }
        p = product(slug="firefox", save=True)
        t = topic(slug="fix-problems", product=p, save=True)
        url = urlparams(reverse("questions.aaq_step5", args=["desktop", "fix-problems"]), search="A test question")

        u = user(save=True)
        self.client.login(username=u.username, password="******")

        for i in range(0, 5):
            self.client.post(url, data, follow=True)

        response = self.client.post(url, data, follow=True)
        eq_(403, response.status_code)
Exemple #30
0
    def test_search_suggestion_question_age(self):
        """Verifies the view doesn't return old questions."""
        topic(title='Fix problems', slug='fix-problems', save=True)
        p = product(slug=u'firefox', save=True)

        q1 = question(title='Fresh Cupcakes', save=True)
        q1.products.add(p)

        max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
        too_old = datetime.now() - timedelta(seconds=max_age * 2)
        q2 = question(title='Stale Cupcakes', created=too_old, updated=too_old,
                      save=True)
        q2.products.add(p)

        self.refresh()

        url = urlparams(
            reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
                    search='cupcakes')

        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)

        self.assertContains(response, q1.title)
        self.assertNotContains(response, q2.title)
Exemple #31
0
 def setUp(self):
     self.profile = profile()
     self.product = product(save=True)
     self.topic = topic(product=self.product, save=True)
     self.request = mock.Mock()
     self.request.user = self.profile.user
     self.context = {
         'request': self.request,
     }
     self.data = {
         'creator': self.profile,
         'title': 'How do I test programs?',
         'content': "Help, I don't know what to do.",
         'product': self.product.slug,
         'topic': self.topic.slug,
     }
Exemple #32
0
    def setUp(self):
        u = user(save=True)
        add_permission(u, Question, 'change_question')
        self.user = u

        p = product(save=True)
        t = topic(product=p, save=True)

        q = question(save=True)
        q.products.add(p)
        q.topics.add(t)
        q.save()

        self.product = p
        self.topic = t
        self.question = q
Exemple #33
0
    def test_data_in_index(self):
        """Verify the data we are indexing."""
        p = product(save=True)
        base_doc = document(locale='en-US', save=True)
        base_doc.products.add(p)
        d = document(locale='es', parent=base_doc, save=True)
        r = revision(document=d, is_approved=True, save=True)

        self.refresh()

        eq_(RevisionMetricsMappingType.search().count(), 1)
        data = RevisionMetricsMappingType.search().values_dict()[0]
        eq_(data['is_approved'], r.is_approved)
        eq_(data['locale'], d.locale)
        eq_(data['product'], [p.slug])
        eq_(data['creator_id'], r.creator_id)
Exemple #34
0
    def test_bogus_articles_in_bundle(self):
        p = product(title='firefox', save=True)
        topic(title='topic1', product=p, save=True)

        # Document with no revision should be fun
        doc = document(title='test2', locale='en-US', save=True)

        bundle = utils.bundle_for_product(p, 'en-US')
        eq_(0, len(bundle['docs']))
        eq_(0, len(bundle['topics']))

        # article with no html.
        revision(document=doc, content='', save=True)
        bundle = utils.bundle_for_product(p, 'en-US')
        eq_(0, len(bundle['docs']))
        eq_(0, len(bundle['topics']))
Exemple #35
0
    def test_wiki_products_inherit(self):
        """Translations inherit products from their parents."""
        doc = document(locale=u'en-US', category=10, save=True)
        p = product(title=u'Firefox', slug=u'desktop', save=True)
        doc.products.add(p)
        revision(document=doc, is_approved=True, save=True)

        translated = document(locale=u'fr', parent=doc, category=10,
                              save=True)
        revision(document=translated, is_approved=True, save=True)

        self.refresh()

        qs = {'a': 1, 'w': 1, 'format': 'json', 'product': p.slug}
        response = self.client.get(reverse('search', locale='fr'), qs)
        eq_(1, json.loads(response.content)['total'])
Exemple #36
0
    def test_question_feed_with_product_and_topic(self):
        """Test that questions feeds with products and topics work."""
        p = product(save=True)
        t = topic(product=p, save=True)
        url = urlparams(reverse('questions.questions'),
                        product=p.slug,
                        topic=t.slug)
        res = self.client.get(url)
        doc = pq(res.content)

        feed_links = doc('link[type="application/atom+xml"]')
        feed = feed_links[0]
        eq_(1, len(feed_links))
        eq_('Recently updated questions', feed.attrib['title'])
        eq_(urlparams('/en-US/questions/feed', product=p.slug, topic=t.slug),
            feed.attrib['href'])
Exemple #37
0
def _create_product_bundle(prefix='moo'):
    p = product(title=prefix + 'firefox', save=True)
    t1 = topic(title=prefix + 'topic1', product=p, save=True)
    t2 = topic(title=prefix + 'topic2', product=p, save=True)

    doc1, expected_doc1 = _create_doc(title=prefix + 'doc1',
                                      product=p,
                                      topic=t1)
    doc2, expected_doc2 = _create_doc(title=prefix + 'doc2',
                                      product=p,
                                      topic=t2)

    expected_locale_doc = {
        'key': u'en-US',
        'name': u'English',
        'products': [{
            'slug': p.slug,
            'name': p.title
        }]
    }

    expected_topic1 = {
        'key': 'en-US~' + p.slug + '~' + t1.slug,
        'name': t1.title,
        'docs': [doc1.slug],
        'product': p.slug,
        'slug': t1.slug,
        'children': []
    }

    expected_topic2 = {
        'key': 'en-US~' + p.slug + '~' + t2.slug,
        'name': t2.title,
        'docs': [doc2.slug],
        'product': p.slug,
        'slug': t2.slug,
        'children': []
    }

    return p, {
        'doc1': expected_doc1,
        'doc2': expected_doc2,
        'locale': expected_locale_doc,
        'topic1': expected_topic1,
        'topic2': expected_topic2
    }
    def test_search_products(self):
        p = product(title=u'Product One', slug='product', save=True)
        doc1 = document(title=u'cookies', locale='en-US', category=10,
                        save=True)
        revision(document=doc1, is_approved=True, save=True)
        doc1.products.add(p)
        doc1.save()

        self.refresh()

        response = self.client.get(
            reverse('search.advanced'),
            {'a': '1', 'product': 'product', 'q': 'cookies', 'w': '1'})

        assert "We couldn't find any results for" not in response.content
        eq_(200, response.status_code)
        assert 'Product One' in response.content
Exemple #39
0
    def test_only_templates(self):
        """Test that only templates are shown"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        p = product(title='Firefox', slug='firefox', save=True)

        d = document(save=True)
        t = document(title='Template:test', save=True)

        revision(document=d, is_approved=True, save=True)
        revision(document=t, is_approved=True, save=True)

        d.products.add(p)
        t.products.add(p)

        eq_(1, len(self.rows(locale=locale, product=p)))
        eq_(t.title, self.row(locale=locale, product=p)['title'])
        eq_(u'', self.row(locale=locale, product=p)['status'])
Exemple #40
0
    def test_by_product(self):
        """Test the product filtering of the readout."""
        p = product(title='Firefox', slug='firefox', save=True)
        d = document(title='Foo', category=CANNED_RESPONSES_CATEGORY,
                     save=True)
        revision(is_approved=True,
                 is_ready_for_localization=True,
                 document=d,
                 save=True)

        # There shouldn't be any rows yet.
        eq_(0, len(self.rows(product=p)))

        # Add the product to the document, and verify it shows up.
        d.products.add(p)
        eq_(1, len(self.rows(product=p)))
        eq_(self.row(product=p)['title'], d.title)
Exemple #41
0
    def test_bad_data(self):
        """Test for bad data"""
        data = {
            'product': product(save=True).id,
            'topic': topic(save=True).id,
            'locale': self.question.locale
        }
        response = self._request(data=data)
        eq_(400, response.status_code)

        data = {
            'product': self.product.id,
            'topic': self.topic.id,
            'locale': 'zu'
        }
        response = self._request(data=data)
        eq_(400, response.status_code)
Exemple #42
0
    def test_default_search_for_questions(self):
        """This tests whether doing a default search returns
        question results.

        Bug #709202.

        """
        # Create a question with an answer with an answervote that
        # marks the answer as helpful.  The question should have the
        # "desktop" tag.
        p = product(title=u'firefox', slug=u'desktop', save=True)
        ques = question(title=u'audio', save=True)
        ques.products.add(p)
        ans = answer(question=ques, content=u'volume', save=True)
        answervote(answer=ans, helpful=True, save=True)

        self.refresh()

        # This is the search that you get when you start on the sumo
        # homepage and do a search from the box with two differences:
        # first, we do it in json since it's easier to deal with
        # testing-wise and second, we search for 'audio' since we have
        # data for that.
        response = self.client.get(reverse('search'), {
            'q': 'audio',
            'format': 'json'
        })

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 1)

        # This is another search that picks up results based on the
        # answer_content.  answer_content is in a string array, so
        # this makes sure that works.
        response = self.client.get(reverse('search'), {
            'q': 'volume',
            'format': 'json'
        })

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 1)
Exemple #43
0
    def test_search_suggestion_questions_locale(self):
        """Verifies the right languages show up in search suggestions."""
        questionlocale(locale='de', save=True)

        p = product(slug=u'firefox', save=True)

        for l in QuestionLocale.objects.all():
            p.questions_locales.add(l)

        topic(title='Fix problems', slug='fix-problems', product=p, save=True)

        q1 = question(title='question cupcakes?',
                      product=p,
                      save=True,
                      locale='en-US')
        q2 = question(title='question donuts?',
                      product=p,
                      save=True,
                      locale='en-US')
        q3 = question(title='question pies?',
                      product=p,
                      save=True,
                      locale='pt-BR')
        q4 = question(title='question pastries?',
                      product=p,
                      save=True,
                      locale='de')

        self.refresh()

        def sub_test(locale, *titles):
            url = urlparams(reverse('questions.aaq_step4',
                                    args=['desktop', 'fix-problems'],
                                    locale=locale),
                            search='question')
            response = self.client.get(url, follow=True)
            doc = pq(response.content)
            eq_msg(len(doc('.result.question')), len(titles),
                   'Wrong number of results for {0}'.format(locale))
            for substr in titles:
                assert substr in doc('.result.question h3 a').text()

        sub_test('en-US', 'cupcakes?', 'donuts?')
        sub_test('pt-BR', 'cupcakes?', 'donuts?', 'pies?')
        sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
Exemple #44
0
    def test_archived_articles_in_bundle(self):
        p = product(title='firefox', save=True)
        t1 = topic(title='topic1', product=p, save=True)

        doc = document(title='test',
                       is_archived=True,
                       locale='en-US',
                       save=True)
        revision(is_approved=True, document=doc, save=True)
        doc.products.add(p)
        doc.topics.add(t1)

        bundle = utils.bundle_for_product(p, 'en-US')
        eq_(1, len(bundle['docs']))
        doc = bundle['docs'].values()[0]
        eq_(True, doc['archived'])
        assert 'html' not in doc
        eq_(1, len(bundle['topics']))
Exemple #45
0
    def test_by_product(self):
        """Test the product filtering of the readout."""
        p = product(title='Firefox', slug='firefox', save=True)
        ready = revision(is_approved=True,
                         is_ready_for_localization=True,
                         save=True)
        revision(document=ready.document,
                 is_approved=True,
                 is_ready_for_localization=False,
                 significance=MEDIUM_SIGNIFICANCE,
                 save=True)

        # There shouldn't be any rows yet.
        eq_(0, len(self.rows(product=p)))

        # Add the product to the document, and verify it shows up.
        ready.document.products.add(p)
        eq_(self.row(product=p)['title'], ready.document.title)
Exemple #46
0
    def test_only_how_to_contribute(self):
        """Test that only Administration articles are shown"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        p = product(title='Firefox', slug='firefox', save=True)

        d1 = document(save=True)
        d2 = document(title='Admin', category=ADMINISTRATION_CATEGORY,
                      save=True)

        revision(document=d1, is_approved=True, save=True)
        revision(document=d2, is_approved=True, save=True)

        d1.products.add(p)
        d2.products.add(p)

        eq_(1, len(self.rows(locale=locale, product=p)))
        eq_(d2.title, self.row(locale=locale, product=p)['title'])
        eq_(u'', self.row(locale=locale, product=p)['status'])
Exemple #47
0
 def test_create(self):
     u = profile().user
     p = product(save=True)
     t = topic(product=p, save=True)
     self.client.force_authenticate(user=u)
     data = {
         'title': 'How do I start Firefox?',
         'content': 'Seriously, what do I do?',
         'product': p.slug,
         'topic': t.slug,
     }
     eq_(Question.objects.count(), 0)
     res = self.client.post(reverse('question-list'), data)
     eq_(res.status_code, 201)
     eq_(Question.objects.count(), 1)
     q = Question.objects.all()[0]
     eq_(q.title, data['title'])
     eq_(q.content, data['content'])
Exemple #48
0
    def test_stats(self):
        """Tests questions/dashboard/metrics view"""
        p = product(save=True)
        t = topic(title='Websites', slug='websites', product=p, save=True)

        question(title=u'cupcakes',
                 content=u'Cupcakes rock!',
                 created=datetime.now() - timedelta(days=1),
                 topic=t,
                 save=True)

        self.refresh()

        response = self.client.get(reverse('questions.metrics'))
        eq_(200, response.status_code)

        # If there's histogram data, this is probably good enough to
        # denote its existence.
        assert ' data-graph="[' in response.content
Exemple #49
0
    def test_ga_zero_results_event(self):
        """If there are no results, verify ga-push data attr on body."""
        doc = document(title=u'audio', locale=u'en-US', category=10, save=True)
        doc.products.add(product(title=u'firefox', slug=u'desktop', save=True))
        revision(document=doc, is_approved=True, save=True)

        self.refresh()

        # If there are results, data-ga-push should be an empty list.
        response = self.client.get(reverse('search'), {'q': 'audio'})
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_('[]', doc('body').attr('data-ga-push'))

        # If there are no results, then Zero Search Results event is there.
        response = self.client.get(reverse('search'), {'q': 'piranha'})
        eq_(200, response.status_code)
        doc = pq(response.content)
        assert '"Zero Search Results"' in doc('body').attr('data-ga-push')
Exemple #50
0
    def test_redirect_locale_not_enabled(self):
        """AAQ should redirect for products with questions disabled for the
        current locale"""
        url_fi = reverse('questions.aaq_step1', locale='fi')
        res = self.client.get(url_fi)
        eq_(200, res.status_code)

        p = product(slug='firefox', save=True)

        url_fi = reverse('questions.aaq_step2', locale='fi', args=['desktop'])
        url_en = reverse('questions.aaq_step2', locale='en-US',
                         args=['desktop'])
        res = self.client.get(url_fi)
        eq_(302, res.status_code)
        assert res['location'].endswith(url_en)

        l = QuestionLocale.objects.get(locale='fi')
        p.questions_locales.add(l)
        res = self.client.get(url_fi)
        eq_(200, res.status_code)
Exemple #51
0
    def test_question_products(self):
        """Make sure that adding products to a Question causes it to
        refresh the index.

        """
        p = product(slug=u'desktop', save=True)
        eq_(QuestionMappingType.search().filter(product=p.slug).count(), 0)
        q = question(save=True)
        self.refresh()
        eq_(QuestionMappingType.search().filter(product=p.slug).count(), 0)
        q.products.add(p)
        self.refresh()
        eq_(QuestionMappingType.search().filter(product=p.slug).count(), 1)
        q.products.remove(p)
        self.refresh()

        # Make sure the question itself is still there and that we didn't
        # accidentally delete it through screwed up signal handling:
        eq_(QuestionMappingType.search().filter().count(), 1)

        eq_(QuestionMappingType.search().filter(product=p.slug).count(), 0)
Exemple #52
0
    def test_other_languages(self):
        p = product(title='firefox', save=True)
        t1 = topic(title='topic1', product=p, save=True)

        doc = document(title='test', locale='en-US', save=True)
        revision(is_approved=True, document=doc, save=True)

        doc.products.add(p)
        doc.topics.add(t1)

        translated_doc = document(title=u'测试',
                                  locale='zh-CN',
                                  parent=doc,
                                  save=True)
        revision(is_approved=True, document=translated_doc, save=True)

        bundle = utils.bundle_for_product(p, 'zh-CN')
        eq_(1, len(bundle['docs']))

        doc = bundle['docs'].values()[0]
        eq_(u'测试', doc['title'])
Exemple #53
0
    def test_locale_filter(self):
        """Only questions for the current locale should be shown on the
        questions front page for AAQ locales."""

        eq_(Question.objects.count(), 0)
        p = product(slug=u'firefox', save=True)
        topic(title='Fix problems', slug='fix-problems', product=p, save=True)

        q1 = question(title='question cupcakes?',
                      product=p,
                      save=True,
                      locale='en-US')
        q2 = question(title='question donuts?',
                      product=p,
                      save=True,
                      locale='en-US')
        q3 = question(title='question pies?',
                      product=p,
                      save=True,
                      locale='pt-BR')
        q4 = question(title='question pastries?',
                      product=p,
                      save=True,
                      locale='de')

        def sub_test(locale, *titles):
            url = urlparams(
                reverse('questions.list', args=['all'], locale=locale))
            response = self.client.get(url, follow=True)
            doc = pq(response.content)
            eq_msg(len(doc('section[id^=question]')), len(titles),
                   'Wrong number of results for {0}'.format(locale))
            for substr in titles:
                assert substr in doc('.questions section .content h2 a').text()

        # en-US and pt-BR are both in AAQ_LANGUAGES, so should be filtered.
        sub_test('en-US', 'cupcakes?', 'donuts?')
        sub_test('pt-BR', 'pies?')
        # de is not in AAQ_LANGUAGES, so should show en-US, but not pt-BR
        sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
Exemple #54
0
    def test_question_topics(self):
        """Make sure that adding topics to a Question causes it to
        refresh the index.

        """
        p = product(save=True)
        t = topic(slug=u'hiphop', product=p, save=True)
        eq_(QuestionMappingType.search().filter(topic=t.slug).count(), 0)
        q = question(save=True)
        self.refresh()
        eq_(QuestionMappingType.search().filter(topic=t.slug).count(), 0)
        q.topics.add(t)
        self.refresh()
        eq_(QuestionMappingType.search().filter(topic=t.slug).count(), 1)
        q.topics.clear()
        self.refresh()

        # Make sure the question itself is still there and that we didn't
        # accidentally delete it through screwed up signal handling:
        eq_(QuestionMappingType.search().filter().count(), 1)

        eq_(QuestionMappingType.search().filter(topic=t.slug).count(), 0)
Exemple #55
0
    def test_translations_get_parent_tags(self):
        doc1 = document(title=u'Audio too loud')
        doc1.save()
        revision(document=doc1, is_approved=True, save=True)
        doc1.topics.add(topic(slug='cookies', save=True))
        doc1.topics.add(topic(slug='general', save=True))
        doc1.products.add(product(slug='desktop', save=True))

        doc2 = document(title=u'Audio too loud bork bork', parent=doc1)
        doc2.save()
        revision(document=doc2, is_approved=True, save=True)
        doc2.tags.add(u'badtag')

        # Verify the parent has the right tags.
        doc_dict = DocumentMappingType.extract_document(doc1.id)
        eq_(doc_dict['topic'], [u'cookies', u'general'])
        eq_(doc_dict['product'], [u'desktop'])

        # Verify the translation has the parent's tags.
        doc_dict = DocumentMappingType.extract_document(doc2.id)
        eq_(doc_dict['topic'], [u'cookies', u'general'])
        eq_(doc_dict['product'], [u'desktop'])
Exemple #56
0
    def test_wiki_products(self):
        """Make sure that adding products to a Document causes it to
        refresh the index.

        """
        p = product(slug=u'desktop', save=True)
        eq_(DocumentMappingType.search().filter(product=p.slug).count(), 0)
        doc = document(save=True)
        revision(document=doc, is_approved=True, save=True)
        self.refresh()
        eq_(DocumentMappingType.search().filter(product=p.slug).count(), 0)
        doc.products.add(p)
        self.refresh()
        eq_(DocumentMappingType.search().filter(product=p.slug).count(), 1)
        doc.products.remove(p)
        self.refresh()

        # Make sure the document itself is still there and that we didn't
        # accidentally delete it through screwed up signal handling:
        eq_(DocumentMappingType.search().filter().count(), 1)

        eq_(DocumentMappingType.search().filter(product=p.slug).count(), 0)
Exemple #57
0
    def test_search_suggestions_questions(self):
        """Verifies the view doesn't kick up an HTTP 500"""
        p = product(slug=u'firefox', save=True)
        l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE)
        p.questions_locales.add(l)
        topic(title='Fix problems', slug='fix-problems', product=p, save=True)
        q = question(product=p, title=u'CupcakesQuestion cupcakes', save=True)

        d = document(title=u'CupcakesKB cupcakes', category=10, save=True)
        d.products.add(p)

        revision(document=d, is_approved=True, save=True)

        self.refresh()

        url = urlparams(
            reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
            search='cupcakes')

        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)

        assert 'CupcakesQuestion' in response.content
        assert 'CupcakesKB' in response.content

        # Verify that archived articles and questions aren't shown...
        # Archive both and they shouldn't appear anymore.
        q.is_archived = True
        q.save()
        d.is_archived = True
        d.save()

        self.refresh()

        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)

        assert 'CupcakesQuestion' not in response.content
        assert 'CupcakesKB' not in response.content
Exemple #58
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)
Exemple #59
0
    def _create_bundle(self, prod, locale=settings.WIKI_DEFAULT_LANGUAGE):
        p = product(title=prod, save=True)
        t = topic(title='topic1', product=p, save=True)

        if locale == settings.WIKI_DEFAULT_LANGUAGE:
            parent = lambda i: None
        else:

            def parent(i):
                d = document(title='test {0} {1}'.format(locale, i),
                             locale=settings.WIKI_DEFAULT_LANGUAGE,
                             save=True)

                d.products.add(p)
                d.topics.add(t)
                d.save()

                revision(summary='test article {0}'.format(i),
                         document=d,
                         is_approved=True,
                         save=True)
                return d

        for i in xrange(5):
            d = document(title='test {0} {1}'.format(locale, i),
                         locale=locale,
                         save=True)
            revision(summary='test article {0}'.format(i),
                     document=d,
                     is_approved=True,
                     save=True)

            d.products.add(p)
            d.topics.add(t)
            d.parent = parent(i)
            d.save()

        build_kb_bundles((prod, ))
Exemple #60
0
    def test_document_listing(self):
        """Verify /products/<product slug>/<topic slug> renders articles."""
        # Create a topic and product.
        p = product(save=True)
        t1 = topic(product=p, save=True)

        # Create 3 documents with the topic and product and one without.
        for i in range(3):
            doc = revision(is_approved=True, save=True).document
            doc.topics.add(t1)
            doc.products.add(p)

        doc = revision(is_approved=True, save=True).document

        self.refresh()

        # GET the page and verify the content.
        url = reverse('products.documents', args=[p.slug, t1.slug])
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(3, len(doc('#document-list > ul > li')))
        eq_(p.slug, doc('#support-search input[name=product]').attr['value'])