Пример #1
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")
Пример #2
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')
Пример #3
0
 def test_indirect_recursion(self):
     """Make sure indirect recursion is caught."""
     boo = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + "Boo")
     yah = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + "Yah")
     ApprovedRevisionFactory(
         document=boo, content="Paper [[{}Yah]] Cups".format(TEMPLATE_TITLE_PREFIX)
     )
     ApprovedRevisionFactory(
         document=yah, content="Wooden [[{}Boo]] Bats".format(TEMPLATE_TITLE_PREFIX)
     )
     recursion_message = RECURSION_MESSAGE % (TEMPLATE_TITLE_PREFIX + "Boo")
     eq_("<p>Paper Wooden %s Bats\n Cups\n</p>" % recursion_message, boo.content_parsed)
Пример #4
0
    def test_only_templates(self):
        """Test that only templates are shown"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        p = ProductFactory(title='Firefox', slug='firefox')

        d = DocumentFactory(products=[p])
        t = TemplateDocumentFactory(products=[p])
        ApprovedRevisionFactory(document=d)
        ApprovedRevisionFactory(document=TemplateDocumentFactory())

        eq_(1, len(self.rows(locale=locale, product=p)))
        eq_(t.title, self.row(locale=locale, product=p)['title'])
        eq_('', self.row(locale=locale, product=p)['status'])
Пример #5
0
    def setUp(self):
        super(TestFacetHelpers, self).setUp()
        # 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])
        doc1_revision = ApprovedRevisionFactory(document=doc1,
                                                is_ready_for_localization=True)

        doc1_localized = DocumentFactory(locale="de",
                                         products=[],
                                         topics=[],
                                         parent=doc1)
        ApprovedRevisionFactory(document=doc1_localized,
                                based_on=doc1_revision)

        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)
Пример #6
0
    def test_removing_template_category(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)
        eq_(d.category, TEMPLATES_CATEGORY)
        assert d.title.startswith(TEMPLATE_TITLE_PREFIX)

        # First try and change the category without also changing the title. It should fail.
        data = new_document_data()
        data.update({
            'title': d.title,
            'category': CATEGORIES[0][0],
            'slug': d.slug,
            'form': 'doc'
        })
        url = reverse('wiki.edit_document', args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).category, TEMPLATES_CATEGORY)
        # This message gets HTML encoded.
        assert ('Documents with titles that start with &#34;Template:&#34; must be in the '
                'templates category.' in res.content)

        # Now try and change the title while also changing the category.
        data['title'] = 'not a template'
        url = reverse('wiki.edit_document', args=[d.slug])
        self.client.post(url, data)
        eq_(Document.objects.get(id=d.id).category, CATEGORIES[0][0])
Пример #7
0
    def test_retitling_template(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)

        old_title = d.title
        new_title = 'Not a template'

        # First try and change the title without also changing the category. It should fail.
        data = new_document_data()
        data.update({
            'title': new_title,
            'category': d.category,
            'slug': d.slug,
            'form': 'doc'
        })
        url = reverse('wiki.edit_document', args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, old_title)
        # This message gets HTML encoded.
        assert ('Documents in the Template category must have titles that start with '
                '&#34;Template:&#34;.'
                in res.content)

        # Now try and change the title while also changing the category.
        data['category'] = CATEGORIES[0][0]
        url = reverse('wiki.edit_document', args=[d.slug])
        self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, new_title)
Пример #8
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')
Пример #9
0
    def test_retitling_template(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)

        old_title = d.title
        new_title = "Not a template"

        # First try and change the title without also changing the category. It should fail.
        data = new_document_data()
        data.update({
            "title": new_title,
            "category": d.category,
            "slug": d.slug,
            "form": "doc"
        })
        url = reverse("wiki.edit_document", args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, old_title)
        # This message gets HTML encoded.
        assert (
            b"Documents in the Template category must have titles that start with "
            b"&#34;Template:&#34;." in res.content)

        # Now try and change the title while also changing the category.
        data["category"] = CATEGORIES[0][0]
        url = reverse("wiki.edit_document", args=[d.slug])
        self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).title, new_title)
Пример #10
0
    def test_removing_template_category(self):
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)
        eq_(d.category, TEMPLATES_CATEGORY)
        assert d.title.startswith(TEMPLATE_TITLE_PREFIX)

        # First try and change the category without also changing the title. It should fail.
        data = new_document_data()
        data.update({
            "title": d.title,
            "category": CATEGORIES[0][0],
            "slug": d.slug,
            "form": "doc"
        })
        url = reverse("wiki.edit_document", args=[d.slug])
        res = self.client.post(url, data, follow=True)
        eq_(Document.objects.get(id=d.id).category, TEMPLATES_CATEGORY)
        # This message gets HTML encoded.
        assert (
            b"Documents with titles that start with &#34;Template:&#34; must be in the "
            b"templates category." in res.content)

        # Now try and change the title while also changing the category.
        data["title"] = "not a template"
        url = reverse("wiki.edit_document", args=[d.slug])
        self.client.post(url, data)
        eq_(Document.objects.get(id=d.id).category, CATEGORIES[0][0])
Пример #11
0
 def test_vote_on_template(self):
     """
     Throw helpful_vote a document that is a template and see if it 400s.
     """
     d = TemplateDocumentFactory()
     r = RevisionFactory(document=d)
     response = self.client.post(reverse("wiki.document_vote", args=["hi"]),
                                 {"revision_id": r.id})
     eq_(400, response.status_code)
Пример #12
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)
Пример #13
0
    def test_needs_review(self):
        """Test status for article that needs review"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        d = TemplateDocumentFactory()
        RevisionFactory(document=d)

        row = self.row(locale=locale)

        eq_(row['title'], d.title)
        eq_(str(row['status']), 'Review Needed')
Пример #14
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')
Пример #15
0
    def test_direct_recursion(self):
        """Make sure direct recursion is caught on the very first nesting."""
        d = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + "Boo")

        # Twice so the second revision sees content identical to itself:
        ApprovedRevisionFactory.create_batch(
            2, document=d, content="Fine [[{}Boo]] Fellows".format(TEMPLATE_TITLE_PREFIX)
        )

        recursion_message = RECURSION_MESSAGE % (TEMPLATE_TITLE_PREFIX + "Boo")
        expected = "<p>Fine %s Fellows\n</p>" % recursion_message
        eq_(expected, d.content_parsed)
Пример #16
0
    def test_counting_unready_templates(self):
        """Templates without a ready-for-l10n rev don't count"""
        # Make a template with an approved but not-ready-for-l10n rev:
        d = TemplateDocumentFactory(is_localizable=True)
        r = ApprovedRevisionFactory(document=d, is_ready_for_localization=False)

        # It shouldn't show up in the total:
        eq_(0, l10n_overview_rows('de')['templates']['denominator'])

        r.is_ready_for_localization = True
        r.save()
        eq_(1, l10n_overview_rows('de')['templates']['denominator'])
Пример #17
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)
Пример #18
0
    def test_unready_for_l10n(self):
        """Test status for article that is not ready for l10n"""
        locale = settings.WIKI_DEFAULT_LANGUAGE
        d = TemplateDocumentFactory()
        RevisionFactory(document=d, is_ready_for_localization=True)
        ApprovedRevisionFactory(
            document=d, is_ready_for_localization=False, significance=MAJOR_SIGNIFICANCE)

        row = self.row(locale=locale)

        eq_(row['title'], d.title)
        eq_(str(row['status']), 'Changes Not Ready For Localization')
Пример #19
0
    def test_template_title_and_category_from_template(self):
        d = TemplateDocumentFactory()

        # First, try and change just the title. It should fail.
        d.title = 'Not A Template'
        self.assertRaises(ValidationError, d.save)

        # Next, try and change just the category. It should also fail.
        d = Document.objects.get(id=d.id)  # reset
        d.category = CATEGORIES[0][0]
        self.assertRaises(ValidationError, d.save)

        # Finally, try and change both title and category. It should work.
        d = Document.objects.get(id=d.id)  # reset
        d.title = 'Not A Template'
        d.category = CATEGORIES[0][0]
        d.save()
Пример #20
0
    def test_template_title_and_category_from_template(self):
        d = TemplateDocumentFactory()

        # First, try and change just the title. It should fail.
        d.title = 'Not A Template'
        self.assertRaises(ValidationError, d.save)

        # Next, try and change just the category. It should also fail.
        d = Document.objects.get(id=d.id)  # reset
        d.category = CATEGORIES[0][0]
        self.assertRaises(ValidationError, d.save)

        # Finally, try and change both title and category. It should work.
        d = Document.objects.get(id=d.id)  # reset
        d.title = 'Not A Template'
        d.category = CATEGORIES[0][0]
        d.save()
Пример #21
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)
Пример #22
0
 def test_unapproved_template(self):
     TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + "new")
     p = WikiParser()
     doc = pq(p.parse("[[T:new]]"))
     eq_('The template "new" does not exist or has no approved revision.', doc.text())