Ejemplo n.º 1
0
    def test_filter_by_doctype(self):
        desktop = ProductFactory(slug=u'desktop')
        ques = QuestionFactory(title=u'audio', product=desktop)
        ans = AnswerFactory(question=ques, content=u'volume')
        AnswerVoteFactory(answer=ans, helpful=True)

        doc = DocumentFactory(title=u'audio', locale=u'en-US', category=10, products=[desktop])
        RevisionFactory(document=doc, is_approved=True)

        doc = DocumentFactory(title=u'audio too', locale=u'en-US', category=10, products=[desktop])
        RevisionFactory(document=doc, is_approved=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)
Ejemplo n.º 2
0
    def test_product_delete(self):
        profile = self.user.profile
        product = ProductFactory()
        profile.products.add(product)
        product.delete()

        self.assertEqual(self.get_doc().product_ids, [])
Ejemplo n.º 3
0
    def test_include_wiki(self):
        """This tests whether doing a simple search returns wiki document
        results.

        Bug #709202.

        """
        doc = DocumentFactory(title=u'audio', locale=u'en-US', category=10)
        doc.products.add(ProductFactory(title=u'firefox', slug=u'desktop'))
        RevisionFactory(document=doc, is_approved=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)
Ejemplo n.º 4
0
 def setUp(self):
     super(MobileDocumentTests, self).setUp()
     rev = ApprovedRevisionFactory()
     self.doc = rev.document
     p = ProductFactory()
     self.doc.products.add(p)
     self.doc.save()
Ejemplo n.º 5
0
    def test_data_in_index(self):
        """Verify the data we are indexing."""
        p = ProductFactory()
        q = QuestionFactory(locale='pt-BR', product=p)
        a = AnswerFactory(question=q)

        self.refresh()

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

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

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

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

        self.refresh()
        data = AnswerMetricsMappingType.search()[0]
        eq_(data['by_asker'], True)
Ejemplo n.º 6
0
    def test_status(self, _out):
        p = ProductFactory(title='firefox', slug='desktop')
        doc = DocumentFactory(title='cupcakes rock', locale='en-US', category=10, products=[p])
        RevisionFactory(document=doc, is_approved=True)

        self.refresh()

        call_command('esstatus')
Ejemplo n.º 7
0
 def test_firefox_product_landing(self):
     """Verify that there are no firefox button at header in the firefox landing page"""
     p = ProductFactory(slug="firefox")
     url = reverse("products.product", args=[p.slug])
     r = self.client.get(url, follow=True)
     eq_(200, r.status_code)
     doc = pq(r.content)
     eq_(False, doc(".firefox-download-button").length)
Ejemplo n.º 8
0
    def test_kb_vote(self):
        """Test vote API call."""
        r1 = RevisionFactory(document__locale="en-US")
        r2 = RevisionFactory(document__locale="es")
        r3 = RevisionFactory(document__locale="es")
        for r in [r1, r2, r3]:
            HelpfulVoteFactory(revision=r)
            HelpfulVoteFactory(revision=r)
            HelpfulVoteFactory(revision=r, helpful=True)

        # Assign 2 documents to Firefox OS and 1 to Firefox
        firefox_os = ProductFactory(slug="firefox-os")
        firefox = ProductFactory(slug="firefox")
        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)
Ejemplo n.º 9
0
    def test_products_change(self):
        product = ProductFactory()
        self.document.products.add(product)

        self.assertIn(product.id, self.get_doc().product_ids)

        self.document.products.remove(product)

        self.assertEqual(None, self.get_doc().product_ids)
Ejemplo n.º 10
0
 def test_absolute_url_subtopic(self):
     p = ProductFactory()
     t1 = TopicFactory(product=p)
     t2 = TopicFactory(parent=t1, product=p)
     expected = "/products/{p}/{t1}/{t2}".format(p=p.slug,
                                                 t1=t1.slug,
                                                 t2=t2.slug)
     actual = t2.get_absolute_url()
     eq_(actual, expected)
Ejemplo n.º 11
0
    def test_search_multiple_products(self):
        p1 = ProductFactory(title=u'Product One', slug='product-one', display_order=1)
        p2 = ProductFactory(title=u'Product Two', slug='product-two', display_order=2)
        doc1 = DocumentFactory(title=u'cookies', locale='en-US', category=10, products=[p1, p2])
        RevisionFactory(document=doc1, is_approved=True)

        self.refresh()

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

        eq_(200, response.status_code)
        assert "We couldn't find any results for" not in response.content
        assert 'Product One, Product Two' in response.content
Ejemplo n.º 12
0
    def test_all_versions(self):
        """Test that products with visible=False are in the showfor data."""
        prod = ProductFactory()
        VersionFactory(visible=True, product=prod)
        VersionFactory(visible=False, product=prod)

        data = showfor_data([prod])

        eq_(len(data['versions'][prod.slug]), 2)
Ejemplo n.º 13
0
    def test_filter_by_product(self):
        u1 = UserFactory()
        u2 = UserFactory()

        p1 = ProductFactory()
        p2 = ProductFactory()

        RevisionFactory(document__products=[p1], creator=u1)
        RevisionFactory(document__products=[p2], creator=u1)
        RevisionFactory(document__products=[p2], creator=u2)

        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)
Ejemplo n.º 14
0
 def test_topic_disambiguation(self):
     # First make another product, and a colliding topic.
     # It has the same slug, but a different product.
     new_product = ProductFactory()
     TopicFactory(product=new_product, slug=self.topic.slug)
     serializer = api.QuestionSerializer(
         context=self.context, data=self.data)
     serializer.is_valid(raise_exception=True)
     obj = serializer.save()
     eq_(obj.topic, self.topic)
Ejemplo n.º 15
0
    def test_path(self):
        """Verify that the path property works."""
        p = ProductFactory(slug="p")
        t1 = TopicFactory(product=p, slug="t1")
        t2 = TopicFactory(product=p, slug="t2", parent=t1)
        t3 = TopicFactory(product=p, slug="t3", parent=t2)

        eq_(t1.path, [t1.slug])
        eq_(t2.path, [t1.slug, t2.slug])
        eq_(t3.path, [t1.slug, t2.slug, t3.slug])
Ejemplo n.º 16
0
    def test_products_change(self):
        RevisionFactory(document=self.document, is_approved=True)
        product = ProductFactory()
        self.document.products.add(product)

        self.assertIn(product.id, self.get_doc().product_ids)

        self.document.products.remove(product)

        self.assertEqual(None, self.get_doc().product_ids)
Ejemplo n.º 17
0
    def test_filter_by_product(self):
        u1 = UserFactory()
        u2 = UserFactory()

        p1 = ProductFactory()
        p2 = ProductFactory()

        AnswerFactory(question__product=p1, creator=u1)
        AnswerFactory(question__product=p2, creator=u1)
        AnswerFactory(question__product=p2, creator=u2)

        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]['answer_count'], 1)
Ejemplo n.º 18
0
    def test_filter_by_product(self):
        u1 = UserFactory()
        u2 = UserFactory()

        p1 = ProductFactory()
        p2 = ProductFactory()

        RevisionFactory(document__products=[p1], creator=u1)
        RevisionFactory(document__products=[p2], creator=u1)
        RevisionFactory(document__products=[p2], creator=u2)

        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)
Ejemplo n.º 19
0
    def test_product_specific_ready(self):
        """Verify product-specific ready for review notifications."""
        # Add an all products in 'es' watcher and a Firefox OS in 'es'
        # watcher.
        ApproveRevisionInLocaleEvent.notify(UserFactory(), locale='es')
        ApproveRevisionInLocaleEvent.notify(UserFactory(),
                                            product='firefox-os',
                                            locale='es')

        # Create an 'es' document for Firefox
        parent = DocumentFactory()
        doc = DocumentFactory(parent=parent, locale='es')
        parent.products.add(ProductFactory(slug='firefox'))

        # Review a revision. There should be 3 new emails:
        # 1 to the creator, 1 to the reviewer and 1 to the 'es' watcher.
        self._review_revision(document=doc,
                              is_ready=True,
                              significance=MEDIUM_SIGNIFICANCE)
        eq_(3, len(mail.outbox))
        _assert_approved_mail(mail.outbox[0])
        _assert_creator_mail(mail.outbox[1])

        # Add firefox-os to the document's products and review a new revision.
        # There should be 4 new emails now (the same 3 from before plus one
        # for the firefox-os watcher).
        parent.products.add(ProductFactory(slug='firefox-os'))
        self._review_revision(document=doc,
                              is_ready=True,
                              significance=MEDIUM_SIGNIFICANCE)
        eq_(7, len(mail.outbox))
        _assert_approved_mail(mail.outbox[3])
        _assert_approved_mail(mail.outbox[4])
        _assert_creator_mail(mail.outbox[5])

        # Add a Firefox watcher. This time there should be 5 new emails.
        ApproveRevisionInLocaleEvent.notify(UserFactory(),
                                            product='firefox',
                                            locale='es')
        self._review_revision(document=doc,
                              is_ready=True,
                              significance=MEDIUM_SIGNIFICANCE)
        eq_(12, len(mail.outbox))
Ejemplo n.º 20
0
    def test_user_products_change(self):
        profile = self.user.profile
        product = ProductFactory()
        profile.products.add(product)

        self.assertIn(product.id, self.get_doc().product_ids)

        profile.products.remove(product)

        self.assertNotIn(product.id, self.get_doc().product_ids)
Ejemplo n.º 21
0
    def test_filter_by_product(self):
        u1 = UserFactory()
        u2 = UserFactory()

        p1 = ProductFactory()
        p2 = ProductFactory()

        AnswerFactory(question__product=p1, creator=u1)
        AnswerFactory(question__product=p2, creator=u1)
        AnswerFactory(question__product=p2, creator=u2)

        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]["answer_count"], 1)
Ejemplo n.º 22
0
    def facets_setUp(self):
        # Create products
        self.desktop = ProductFactory(slug='firefox')
        self.mobile = ProductFactory(slug='mobile')

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

        # Set up documents.
        doc1 = DocumentFactory(products=[self.desktop], topics=[self.general_d, self.bookmarks_d])
        ApprovedRevisionFactory(document=doc1)

        doc2 = DocumentFactory(
            products=[self.desktop, self.mobile],
            topics=[self.bookmarks_d, self.bookmarks_m, self.sync_d, self.sync_m])
        ApprovedRevisionFactory(document=doc2)

        # An archived article shouldn't show up
        doc3 = DocumentFactory(
            is_archived=True,
            products=[self.desktop],
            topics=[self.general_d, self.bookmarks_d])
        ApprovedRevisionFactory(document=doc3)

        # A template article shouldn't show up either
        doc4 = TemplateDocumentFactory(
            products=[self.desktop],
            topics=[self.general_d, self.bookmarks_d])
        ApprovedRevisionFactory(document=doc4)

        # An article without current revision should be "invisible"
        # to everything.
        doc5 = DocumentFactory(
            products=[self.desktop, self.mobile],
            topics=[self.general_d, self.bookmarks_d, self.sync_d,
                    self.general_m, self.bookmarks_m, self.sync_m])
        RevisionFactory(is_approved=False, document=doc5)
Ejemplo n.º 23
0
 def _new_question(self, post_it=False):
     """Post a new question and return the response."""
     p = ProductFactory(slug='mobile')
     l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE)
     p.questions_locales.add(l)
     t = TopicFactory(slug='fix-problems', product=p)
     url = urlparams(reverse('questions.aaq_step5', args=[p.slug, t.slug]),
                     search='A test question')
     if post_it:
         return self.client.post(url, self.data, follow=True)
     return self.client.get(url, follow=True)
Ejemplo n.º 24
0
    def test_status(self, _out):
        p = ProductFactory(title="firefox", slug="desktop")
        doc = DocumentFactory(title="cupcakes rock",
                              locale="en-US",
                              category=10,
                              products=[p])
        RevisionFactory(document=doc, is_approved=True)

        self.refresh()

        call_command("esstatus")
Ejemplo n.º 25
0
    def test_search(self, _out):
        """Test that es_search command doesn't fail"""
        call_command('essearch', 'cupcakes')

        p = ProductFactory(title='firefox', slug='desktop')
        doc = DocumentFactory(title='cupcakes rock', locale='en-US', category=10, products=[p])
        RevisionFactory(document=doc, is_approved=True)

        self.refresh()

        call_command('essearch', 'cupcakes')
Ejemplo n.º 26
0
    def test_questions_by_product(self):
        """Test product filtering of questions API call."""
        firefox_os = ProductFactory(slug='firefox-os')
        firefox = ProductFactory(slug='firefox')

        # A Firefox OS question with a solution:
        q = QuestionFactory(product=firefox_os)
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()

        # A Firefox OS question with an answer:
        q = QuestionFactory(product=firefox_os)
        AnswerFactory(question=q)

        # A Firefox OS question without answers:
        q = QuestionFactory(product=firefox_os)

        # A Firefox question without answers:
        q = QuestionFactory(product=firefox, locale='pt-BR')

        # Verify no product filtering:
        r = self._get_api_result('api.kpi.questions')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 4)

        # Verify product=firefox-os
        r = self._get_api_result('api.kpi.questions', product='firefox-os')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 3)

        # Verify product=firefox
        r = self._get_api_result('api.kpi.questions', product='firefox')
        eq_(r['objects'][0]['questions'], 1)
        assert 'solved' not in r['objects'][0]
        assert 'responded_24' not in r['objects'][0]
        assert 'responded_72' not in r['objects'][0]
Ejemplo n.º 27
0
    def test_questions_by_product(self):
        """Test product filtering of questions API call."""
        firefox_os = ProductFactory(slug="firefox-os")
        firefox = ProductFactory(slug="firefox")

        # A Firefox OS question with a solution:
        q = QuestionFactory(product=firefox_os)
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()

        # A Firefox OS question with an answer:
        q = QuestionFactory(product=firefox_os)
        AnswerFactory(question=q)

        # A Firefox OS question without answers:
        q = QuestionFactory(product=firefox_os)

        # A Firefox question without answers:
        q = QuestionFactory(product=firefox, locale="pt-BR")

        # Verify no product filtering:
        r = self._get_api_result("api.kpi.questions")
        eq_(r["objects"][0]["solved"], 1)
        eq_(r["objects"][0]["responded_24"], 2)
        eq_(r["objects"][0]["responded_72"], 2)
        eq_(r["objects"][0]["questions"], 4)

        # Verify product=firefox-os
        r = self._get_api_result("api.kpi.questions", product="firefox-os")
        eq_(r["objects"][0]["solved"], 1)
        eq_(r["objects"][0]["responded_24"], 2)
        eq_(r["objects"][0]["responded_72"], 2)
        eq_(r["objects"][0]["questions"], 3)

        # Verify product=firefox
        r = self._get_api_result("api.kpi.questions", product="firefox")
        eq_(r["objects"][0]["questions"], 1)
        assert "solved" not in r["objects"][0]
        assert "responded_24" not in r["objects"][0]
        assert "responded_72" not in r["objects"][0]
Ejemplo n.º 28
0
    def test_by_product(self):
        """Test the product filtering of the readout."""
        p = ProductFactory(title='Firefox', slug='firefox')
        d = TemplateDocumentFactory()
        ApprovedRevisionFactory(document=d, is_ready_for_localization=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_(self.row(product=p)['title'], d.title)
Ejemplo n.º 29
0
    def test_by_product(self):
        """Test the product filtering of the readout."""
        p = ProductFactory(title='Firefox', slug='firefox')
        r = TranslatedRevisionFactory(document__locale='de', is_approved=True)
        d = r.document

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

        # Add the product to the parent document, and verify it shows up.
        d.parent.products.add(p)
        eq_(self.row(product=p)['title'], d.title)
Ejemplo n.º 30
0
    def test_by_product(self):
        """Test the product filtering of the overview."""
        p = ProductFactory(title='Firefox', slug='firefox')
        t = TranslatedRevisionFactory(is_approved=True, document__locale='de')

        eq_(0, l10n_overview_rows('de', product=p)['all']['numerator'])
        eq_(0, l10n_overview_rows('de', product=p)['all']['denominator'])

        t.document.parent.products.add(p)

        eq_(1, l10n_overview_rows('de', product=p)['all']['numerator'])
        eq_(1, l10n_overview_rows('de', product=p)['all']['denominator'])