コード例 #1
0
    def test_changing_products(self):
        """Changing products works as expected."""
        r = ApprovedRevisionFactory()
        d = r.document
        prod_desktop = ProductFactory(title=u'desktop')
        prod_mobile = ProductFactory(title=u'mobile')

        data = new_document_data()
        data.update({
            'products': [prod_desktop.id, prod_mobile.id],
            'title': d.title,
            'slug': d.slug,
            'form': 'doc'
        })
        self.client.post(reverse('wiki.edit_document', args=[d.slug]), data)

        eq_(
            sorted(
                Document.objects.get(id=d.id).products.values_list('id',
                                                                   flat=True)),
            sorted([prod.id for prod in [prod_desktop, prod_mobile]]))

        data.update({'products': [prod_desktop.id], 'form': 'doc'})
        self.client.post(reverse('wiki.edit_document', args=[data['slug']]),
                         data)
        eq_(
            sorted(
                Document.objects.get(id=d.id).products.values_list('id',
                                                                   flat=True)),
            sorted([prod.id for prod in [prod_desktop]]))
コード例 #2
0
    def test_trans_lock_workflow(self):
        """End to end test of locking on a translated document."""
        rev = ApprovedRevisionFactory()
        doc = rev.document
        u = UserFactory(password='******')

        # Create a new translation of doc() using the translation view
        self.client.login(username=u.username, password='******')
        trans_url = reverse('wiki.translate', locale='es', args=[doc.slug])
        data = {
            'title': 'Un Test Articulo',
            'slug': 'un-test-articulo',
            'keywords': 'keyUno, keyDos, keyTres',
            'summary': 'lipsumo',
            'content': 'loremo ipsumo doloro sito ameto'
        }
        r = self.client.post(trans_url, data)
        eq_(r.status_code, 302)

        # Now run the test.
        edit_url = reverse('wiki.edit_document',
                           locale='es',
                           args=[data['slug']])
        es_doc = Document.objects.get(slug=data['slug'])
        eq_(es_doc.locale, 'es')
        self._lock_workflow(es_doc, edit_url)
コード例 #3
0
 def setUp(self):
     super(MobileDocumentTests, self).setUp()
     rev = ApprovedRevisionFactory()
     self.doc = rev.document
     p = ProductFactory()
     self.doc.products.add(p)
     self.doc.save()
コード例 #4
0
ファイル: test_parser.py プロジェクト: zu83/kitsune
    def test_redirect_translations_only(self):
        """Make sure get_object_fallback doesn't follow redirects when working
        purely in the default language.

        That would make it hard to navigate to redirects (to edit them, for
        example).

        """
        ApprovedRevisionFactory(document__title="target", content="O hai.")
        redirect_rev = ApprovedRevisionFactory(document__title="redirect",
                                               content="REDIRECT [[target]]")
        eq_(
            redirect_rev.document,
            get_object_fallback(Document, "redirect",
                                redirect_rev.document.locale),
        )
コード例 #5
0
ファイル: test_parser.py プロジェクト: zu83/kitsune
    def test_translated(self):
        """If a localization of the English fallback exists, use it."""

        en_d = DocumentFactory(title="A doc")
        ApprovedRevisionFactory(document=en_d)

        fr_d = DocumentFactory(parent=en_d, title="Une doc", locale="fr")

        # Without an approved revision, the en-US doc should be returned.
        obj = get_object_fallback(Document, "A doc", "fr")
        eq_(en_d, obj)

        # Approve a revision, then fr doc should be returned.
        ApprovedRevisionFactory(document=fr_d)
        obj = get_object_fallback(Document, "A doc", "fr")
        eq_(fr_d, obj)
コード例 #6
0
ファイル: test_readouts.py プロジェクト: zu83/kitsune
    def test_by_product(self):
        """Test the product filtering of the readout."""
        p = ProductFactory(title="Firefox", slug="firefox")
        ready = ApprovedRevisionFactory(is_ready_for_localization=True)
        ApprovedRevisionFactory(
            document=ready.document,
            is_ready_for_localization=False,
            significance=MEDIUM_SIGNIFICANCE,
        )

        # 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)
コード例 #7
0
ファイル: test_readouts.py プロジェクト: zu83/kitsune
    def test_only_how_to_contribute(self):
        """Test that only Administration articles are shown"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        p = ProductFactory(title="Firefox", slug="firefox")

        d1 = DocumentFactory(products=[p])
        d2 = DocumentFactory(title="Admin",
                             category=ADMINISTRATION_CATEGORY,
                             products=[p])

        ApprovedRevisionFactory(document=d1)
        ApprovedRevisionFactory(document=d2)

        eq_(1, len(self.rows(locale=locale, product=p)))
        eq_(d2.title, self.row(locale=locale, product=p)["title"])
        eq_("", self.row(locale=locale, product=p)["status"])
コード例 #8
0
ファイル: test_readouts.py プロジェクト: zu83/kitsune
    def test_only_how_to_contribute(self):
        """Test that only How To Contribute articles are shown"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        p = ProductFactory(title="Firefox", slug="firefox")

        d1 = DocumentFactory(products=[p])
        d2 = DocumentFactory(title="How To",
                             category=HOW_TO_CONTRIBUTE_CATEGORY,
                             products=[p])

        ApprovedRevisionFactory(document=d1)
        ApprovedRevisionFactory(document=d2)

        eq_(1, len(self.rows(locale=locale, product=p)))
        eq_(d2.title, self.row(locale=locale, product=p)["title"])
        eq_("", self.row(locale=locale, product=p)["status"])
コード例 #9
0
ファイル: test_models.py プロジェクト: rootmeb/kitsune
 def test_correct_ready_for_localization_if_insignificant(self):
     """Revision.clean() must clear is_ready_for_l10n if the rev is of
     typo-level significance."""
     r = ApprovedRevisionFactory(is_ready_for_localization=True,
                                 significance=TYPO_SIGNIFICANCE)
     r.clean()
     assert not r.is_ready_for_localization
コード例 #10
0
ファイル: test_models.py プロジェクト: rootmeb/kitsune
    def test_majorly_outdated_with_unapproved_parents(self):
        """Migrations might introduce translated revisions without based_on
        set. Tolerate these.

        If based_on of a translation's current_revision is None, the
        translation should be considered out of date iff any
        major-significance, approved revision to the English article exists.

        """
        # Create a parent doc with only an unapproved revision...
        parent_rev = RevisionFactory()
        # ...and a translation with a revision based on nothing.
        trans = DocumentFactory(parent=parent_rev.document, locale='de')
        trans_rev = RevisionFactory(document=trans, is_approved=True)

        assert trans_rev.based_on is None, \
            ('based_on defaulted to something non-None, which this test '
             "wasn't expecting.")

        assert not trans.is_majorly_outdated(), \
            ('A translation was considered majorly out of date even though '
             'the English document has never had an approved revision of '
             'major significance.')

        ApprovedRevisionFactory(document=parent_rev.document,
                                significance=MAJOR_SIGNIFICANCE,
                                is_ready_for_localization=True)

        assert trans.is_majorly_outdated(), \
            ('A translation was not considered majorly outdated when its '
             "current revision's based_on value was None.")
コード例 #11
0
 def test_untranslated(self):
     """Assert untranslated templates are labeled as such."""
     d = TemplateDocumentFactory()
     untranslated = ApprovedRevisionFactory(document=d,
                                            is_ready_for_localization=True)
     row = self.row()
     eq_(row["title"], untranslated.document.title)
     eq_(str(row["status"]), "Translation Needed")
コード例 #12
0
ファイル: test_readouts.py プロジェクト: chupahanks/kitsune
 def test_untranslated(self):
     """Assert untranslated templates are labeled as such."""
     d = TemplateDocumentFactory()
     untranslated = ApprovedRevisionFactory(document=d,
                                            is_ready_for_localization=True)
     row = self.row()
     eq_(row['title'], untranslated.document.title)
     eq_(unicode(row['status']), 'Translation Needed')
コード例 #13
0
def doc_rev_parser(content,
                   title="Installing Firefox",
                   parser_cls=WikiParser,
                   **kwargs):
    p = parser_cls()
    d = DocumentFactory(title=title, **kwargs)
    r = ApprovedRevisionFactory(document=d, content=content)
    return (d, r, p)
コード例 #14
0
    def test_unapproved_revision_not_updates_html(self):
        """Creating an unapproved revision does not update document.html"""
        d = ApprovedRevisionFactory(content='Here to stay').document
        assert 'Here to stay' in d.html, '"Here to stay" not in %s' % d.html

        # Creating another approved revision keeps initial content
        RevisionFactory(document=d, content='Fail to replace html')
        assert 'Here to stay' in d.html, '"Here to stay" not in %s' % d.html
コード例 #15
0
 def test_orphan_non_english(self):
     """Discussing a non-English article with no parent shouldn't crash."""
     # Guard against regressions of bug 658045.
     r = ApprovedRevisionFactory(document__locale="de")
     response = self.client.get(
         reverse("wiki.discuss.threads", args=[r.document.slug], locale="de")
     )
     eq_(200, response.status_code)
コード例 #16
0
 def test_video_cdn(self):
     """Video URLs can link to the CDN if a CDN setting is set."""
     v = VideoFactory()
     d = ApprovedRevisionFactory(content="[[V:%s]]" % v.title).document
     doc = pq(d.html)
     assert settings.GALLERY_VIDEO_URL in doc("source").eq(1).attr("src")
     assert settings.GALLERY_VIDEO_URL in doc("video").attr("data-fallback")
     assert settings.GALLERY_VIDEO_URL in doc("source").eq(0).attr("src")
コード例 #17
0
 def test_approved_over_unreviewed(self):
     """Favor an approved revision over a more recent unreviewed one."""
     approved = ApprovedRevisionFactory(is_ready_for_localization=False)
     RevisionFactory(document=approved.document,
                     is_ready_for_localization=False,
                     is_approved=False,
                     reviewed=None)
     eq_(approved, approved.document.localizable_or_latest_revision())
コード例 #18
0
    def test_link_with_localization(self):
        """A link to an English doc with a local translation."""
        en_d = DocumentFactory(title="A doc")
        ApprovedRevisionFactory(document=en_d)

        fr_d = DocumentFactory(parent=en_d, title="Une doc", locale="fr")

        # Without an approved revision, link should go to en-US doc.
        # The site should stay in fr locale (/<locale>/<en-US slug>).
        link = pq(self.p.parse("[[A doc]]", locale="fr"))
        eq_("/fr/kb/a-doc", link.find("a").attr("href"))
        eq_("A doc", link.find("a").text())

        # Approve a revision. Now link should go to fr doc.
        ApprovedRevisionFactory(document=fr_d)
        link = pq(self.p.parse("[[A doc]]", locale="fr"))
        eq_("/fr/kb/une-doc", link.find("a").attr("href"))
        eq_("Une doc", link.find("a").text())
コード例 #19
0
ファイル: test_parser.py プロジェクト: ziegeer/kitsune
    def test_link_with_localization(self):
        """A link to an English doc with a local translation."""
        en_d = DocumentFactory(title='A doc')
        ApprovedRevisionFactory(document=en_d)

        fr_d = DocumentFactory(parent=en_d, title='Une doc', locale='fr')

        # Without an approved revision, link should go to en-US doc.
        # The site should stay in fr locale (/<locale>/<en-US slug>).
        link = pq(self.p.parse('[[A doc]]', locale='fr'))
        eq_('/fr/kb/a-doc', link.find('a').attr('href'))
        eq_('A doc', link.find('a').text())

        # Approve a revision. Now link should go to fr doc.
        ApprovedRevisionFactory(document=fr_d)
        link = pq(self.p.parse('[[A doc]]', locale='fr'))
        eq_('/fr/kb/une-doc', link.find('a').attr('href'))
        eq_('Une doc', link.find('a').text())
コード例 #20
0
ファイル: test_views.py プロジェクト: pirateyporat/kitsune
    def test_custom_event_while_fallback_locale(self):
        """If a document is shown in fallback locale because the document is not
        available in requested locale, it should fire a "Fallback Locale" GA event"""
        # A Approved revision ready for localization
        r = ApprovedRevisionFactory(is_ready_for_localization=True)
        # A document and revision in bn-BD locale
        trans = DocumentFactory(parent=r.document, locale='bn-BD')
        ApprovedRevisionFactory(document=trans, based_on=r)
        # Get the bn-IN locale version of the document
        url = reverse('wiki.document', args=[r.document.slug], locale='bn-IN')
        response = self.client.get(url)
        eq_(200, response.status_code)

        doc = pq(response.content)
        ga_data = r.document.slug + "/bn-IN" + "/bn-BD"
        assert ga_data in doc('body').attr('data-ga-push')
        assert '"Fallback Locale"' in doc('body').attr('data-ga-push')
        assert '"Not Localized"' not in doc('body').attr('data-ga-push')
コード例 #21
0
    def test_needs_changes(self):
        """Test status for article that needs changes"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        d = TemplateDocumentFactory(needs_change=True)
        ApprovedRevisionFactory(document=d)

        row = self.row(locale=locale)

        eq_(row['title'], d.title)
        eq_(str(row['status']), 'Changes Needed')
コード例 #22
0
 def test_for_in_template(self):
     """Verify that {for}'s render correctly in template."""
     d = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + 'for')
     ApprovedRevisionFactory(
         document=d, content='{for win}windows{/for}{for mac}mac{/for}')
     p = WikiParser()
     content = p.parse('[[{}for]]'.format(TEMPLATE_TITLE_PREFIX))
     eq_(
         '<p><span class="for" data-for="win">windows</span>'
         '<span class="for" data-for="mac">mac</span>\n\n</p>', content)
コード例 #23
0
    def test_consider_max_significance(self):
        """Use max significance for determining change significance

        When determining how significantly an article has changed
        since translation, use the max significance of the approved
        revisions, not just that of the latest ready-to-localize one.
        """
        translation = TranslatedRevisionFactory(document__locale='de', is_approved=True)
        ApprovedRevisionFactory(
            document=translation.document.parent,
            is_ready_for_localization=False,  # should still count
            significance=MAJOR_SIGNIFICANCE)
        ApprovedRevisionFactory(
            document=translation.document.parent,
            is_ready_for_localization=True,
            significance=MEDIUM_SIGNIFICANCE)
        row = self.row()
        eq_(row['title'], translation.document.title)
        eq_(str(row['status']), 'Immediate Update Needed')
コード例 #24
0
 def create_documents(self, locale):
     """Create a document in English and a translated document for the locale"""
     en = settings.WIKI_DEFAULT_LANGUAGE
     en_content = "This article is in English"
     trans_content = "This article is translated into %slocale" % locale
     # Create an English article and a translation for the locale
     en_doc = DocumentFactory(locale=en)
     ApprovedRevisionFactory(document=en_doc,
                             content=en_content,
                             is_ready_for_localization=True)
     trans_doc = DocumentFactory(parent=en_doc, locale=locale)
     # Create a new revision of the localized document
     trans_rev = ApprovedRevisionFactory(document=trans_doc,
                                         content=trans_content)
     # Make the created revision the current one for the localized document
     trans_doc.current_revision = trans_rev
     trans_doc.save()
     # Return both the English version and the localized version of the document
     return en_doc, trans_doc
コード例 #25
0
 def test_video_modal_caption_text(self):
     """Video modal can change title and placeholder text."""
     v = VideoFactory()
     r = ApprovedRevisionFactory(
         content='[[V:%s|modal|placeholder=Place<b>holder</b>|title=WOOT]]'
         % v.title)
     d = r.document
     doc = pq(d.html)
     eq_('WOOT', doc('.video-modal')[0].attrib['title'])
     eq_('Place<b>holder</b>', doc('.video-placeholder').html().strip())
コード例 #26
0
 def test_video_modal_caption_text(self):
     """Video modal can change title and placeholder text."""
     v = VideoFactory()
     r = ApprovedRevisionFactory(
         content="[[V:%s|modal|placeholder=Place<b>holder</b>|title=WOOT]]" % v.title
     )
     d = r.document
     doc = pq(d.html)
     eq_("WOOT", doc(".video-modal")[0].attrib["title"])
     eq_("Place<b>holder</b>", doc(".video-placeholder").html().strip())
コード例 #27
0
 def test_video_modal(self):
     """Video modal defaults for plcaeholder and text."""
     v = VideoFactory()
     replacement = '<img class="video-thumbnail" src="%s"/>' % v.thumbnail_url_if_set()
     d = ApprovedRevisionFactory(content="[[V:%s|modal]]" % v.title).document
     doc = pq(d.html)
     eq_(v.title, doc(".video-modal")[0].attrib["title"])
     eq_(1, doc(".video video").length)
     eq_(replacement, doc(".video-placeholder").html().strip())
     eq_("video modal-trigger", doc("div.video").attr("class"))
コード例 #28
0
ファイル: test_facets.py プロジェクト: ziegeer/kitsune
    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)
コード例 #29
0
ファイル: test_cron.py プロジェクト: sophianyberg/kitsune
    def setUp(self):
        today = datetime.today()
        self.start_of_first_week = today - timedelta(days=today.weekday(), weeks=12)

        revisions = ApprovedRevisionFactory.create_batch(3, created=self.start_of_first_week)

        reviewer = UserFactory()
        ApprovedRevisionFactory(reviewer=reviewer, created=self.start_of_first_week)

        ApprovedRevisionFactory(
            creator=revisions[1].creator,
            reviewer=reviewer,
            created=self.start_of_first_week + timedelta(weeks=1, days=2),
        )
        ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(weeks=1, days=1))

        for r in revisions:
            lr = ApprovedRevisionFactory(
                created=self.start_of_first_week + timedelta(days=1), document__locale="es"
            )
            ApprovedRevisionFactory(
                created=self.start_of_first_week + timedelta(weeks=2, days=1),
                creator=lr.creator,
                document__locale="es",
            )

        answers = AnswerFactory.create_batch(
            7, created=self.start_of_first_week + timedelta(weeks=1, days=2)
        )

        AnswerFactory(
            question=answers[2].question,
            creator=answers[2].question.creator,
            created=self.start_of_first_week + timedelta(weeks=1, days=2),
        )

        for a in answers[:2]:
            AnswerFactory(
                creator=a.creator, created=self.start_of_first_week + timedelta(weeks=2, days=5)
            )

        call_command("cohort_analysis")
コード例 #30
0
 def test_template_locale(self):
     """Localized template is returned."""
     py_doc, p = doc_parse_markup("English content", "[[Template:test]]")
     parent = TemplateDocumentFactory()
     d = TemplateDocumentFactory(
         parent=parent, title=TEMPLATE_TITLE_PREFIX + "test", locale="fr"
     )
     ApprovedRevisionFactory(content="French Content", document=d)
     eq_(py_doc.text(), "English content")
     py_doc = pq(p.parse("[[T:test]]", locale="fr"))
     eq_(py_doc.text(), "French Content")