Пример #1
0
    def test_template_title_and_category_localized(self):
        # Because localized articles are required to match templates with their
        # parents, this deserves extra testing.

        d_en = DocumentFactory()
        d_fr = DocumentFactory(parent=d_en, locale='fr')

        # Just changing the title isn't enough
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        self.assertRaises(ValidationError, d_fr.save)

        # Trying to change the category won't work, since `d_en` will force the
        # old category.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        self.assertRaises(ValidationError, d_fr.save)

        # Change the parent
        d_en.title = TEMPLATE_TITLE_PREFIX + d_en.title
        d_en.category = TEMPLATES_CATEGORY
        d_en.save()

        # Now the French article can be changed too.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        d_fr.save()
Пример #2
0
 def test_from_french(self):
     # Create the English document
     d = DocumentFactory(title='A doc')
     d.save()
     # Returns English document for French
     obj = get_object_fallback(Document, 'A doc', 'fr', '!')
     eq_(d, obj)
Пример #3
0
    def test_category_inheritance(self):
        """A document's categories must always be those of its parent."""
        some_category = CATEGORIES[1][0]
        other_category = CATEGORIES[2][0]

        # Notice if somebody ever changes the default on the category field,
        # which would invalidate our test:
        assert some_category != DocumentFactory().category

        parent = DocumentFactory(category=some_category)
        child = DocumentFactory(parent=parent, locale='de')

        # Make sure child sees stuff set on parent:
        eq_(some_category, child.category)

        # Child'd category should revert to parent's on save:
        child.category = other_category
        child.save()
        eq_(some_category, child.category)

        # Changing the parent category should change the child's:
        parent.category = other_category

        parent.save()
        eq_(other_category,
            parent.translations.get(locale=child.locale).category)
Пример #4
0
 def test_from_french(self):
     # Create the English document
     d = DocumentFactory(title="A doc")
     d.save()
     # Returns English document for French
     obj = get_object_fallback(Document, "A doc", "fr", "!")
     eq_(d, obj)
Пример #5
0
    def test_category_inheritance(self):
        """A document's categories must always be those of its parent."""
        some_category = CATEGORIES[1][0]
        other_category = CATEGORIES[2][0]

        # Notice if somebody ever changes the default on the category field,
        # which would invalidate our test:
        assert some_category != DocumentFactory().category

        parent = DocumentFactory(category=some_category)
        child = DocumentFactory(parent=parent, locale='de')

        # Make sure child sees stuff set on parent:
        eq_(some_category, child.category)

        # Child'd category should revert to parent's on save:
        child.category = other_category
        child.save()
        eq_(some_category, child.category)

        # Changing the parent category should change the child's:
        parent.category = other_category

        parent.save()
        eq_(other_category,
            parent.translations.get(locale=child.locale).category)
Пример #6
0
    def test_template_title_and_category_localized(self):
        # Because localized articles are required to match templates with their
        # parents, this deserves extra testing.

        d_en = DocumentFactory()
        d_fr = DocumentFactory(parent=d_en, locale='fr')

        # Just changing the title isn't enough
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        self.assertRaises(ValidationError, d_fr.save)

        # Trying to change the category won't work, since `d_en` will force the
        # old category.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        self.assertRaises(ValidationError, d_fr.save)

        # Change the parent
        d_en.title = TEMPLATE_TITLE_PREFIX + d_en.title
        d_en.category = TEMPLATES_CATEGORY
        d_en.save()

        # Now the French article can be changed too.
        d_fr = Document.objects.get(id=d_fr.id)  # reset
        d_fr.title = TEMPLATE_TITLE_PREFIX + d_fr.title
        d_fr.category = TEMPLATES_CATEGORY
        d_fr.save()
Пример #7
0
 def test_no_redirect_on_unsaved_change(self):
     """No redirect should be made when an unsaved doc's title or slug is
     changed."""
     d = DocumentFactory(title='Gerbil')
     d.title = 'Weasel'
     d.save()
     # There should be no redirect from Gerbil -> Weasel:
     assert not Document.objects.filter(title='Gerbil').exists()
Пример #8
0
 def test_no_redirect_on_unsaved_change(self):
     """No redirect should be made when an unsaved doc's title or slug is
     changed."""
     d = DocumentFactory(title='Gerbil')
     d.title = 'Weasel'
     d.save()
     # There should be no redirect from Gerbil -> Weasel:
     assert not Document.objects.filter(title='Gerbil').exists()
Пример #9
0
    def _make_document(self, **kwargs):
        defaults = {
            'title': 'How to make a pie from scratch with email ' + str(time.time()),
            'category': 10,
        }

        defaults.update(kwargs)
        d = DocumentFactory(**defaults)
        RevisionFactory(document=d, is_approved=True)
        d.save()
        return d
Пример #10
0
    def test_only_show_wiki_and_questions(self):
        """Tests that the simple 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 = ProductFactory(slug=u'desktop')
        ques = QuestionFactory(title=u'audio', product=p)
        ans = AnswerFactory(question=ques, content=u'volume')
        AnswerVoteFactory(answer=ans, helpful=True)

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

        thread1 = ThreadFactory(title=u'audio')
        PostFactory(thread=thread1)

        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)

        # Archive the article and question. They should no longer appear
        # in simple search results.
        ques.is_archived = True
        ques.save()
        doc.is_archived = True
        doc.save()

        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'], 0)
Пример #11
0
    def _make_document(self, **kwargs):
        defaults = {
            'title':
            'How to make a pie from scratch with email ' + str(time.time()),
            'category':
            10,
        }

        defaults.update(kwargs)
        d = DocumentFactory(**defaults)
        RevisionFactory(document=d, is_approved=True)
        d.save()
        return d
Пример #12
0
    def test_ready_for_l10n(self):
        d = DocumentFactory()
        r = RevisionFactory(document=d)
        d.current_revision = r
        d.save()

        data = kb_overview_rows()
        eq_(1, len(data))
        eq_(False, data[0]["ready_for_l10n"])

        ApprovedRevisionFactory(document=d, is_ready_for_localization=True)

        data = kb_overview_rows()
        eq_(True, data[0]["ready_for_l10n"])
Пример #13
0
    def test_ready_for_l10n(self):
        d = DocumentFactory()
        r = RevisionFactory(document=d)
        d.current_revision = r
        d.save()

        data = kb_overview_rows()
        eq_(1, len(data))
        eq_(False, data[0]['ready_for_l10n'])

        ApprovedRevisionFactory(document=d, is_ready_for_localization=True)

        data = kb_overview_rows()
        eq_(True, data[0]['ready_for_l10n'])
Пример #14
0
    def test_only_show_wiki_and_questions(self):
        """Tests that the simple 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 = ProductFactory(slug=u'desktop')
        ques = QuestionFactory(title=u'audio', product=p)
        ans = AnswerFactory(question=ques, content=u'volume')
        AnswerVoteFactory(answer=ans, helpful=True)

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

        thread1 = ThreadFactory(title=u'audio')
        PostFactory(thread=thread1)

        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)

        # Archive the article and question. They should no longer appear
        # in simple search results.
        ques.is_archived = True
        ques.save()
        doc.is_archived = True
        doc.save()

        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'], 0)
Пример #15
0
    def test_document_is_template(self):
        """is_template stays in sync with the title"""
        d = DocumentFactory(title='test')

        assert not d.is_template

        d.title = TEMPLATE_TITLE_PREFIX + 'test'
        d.category = TEMPLATES_CATEGORY
        d.save()

        assert d.is_template

        d.title = 'Back to document'
        d.category = CATEGORIES[0][0]
        d.save()

        assert not d.is_template
Пример #16
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
Пример #17
0
    def test_document_is_template(self):
        """is_template stays in sync with the title"""
        d = DocumentFactory(title='test')

        assert not d.is_template

        d.title = TEMPLATE_TITLE_PREFIX + 'test'
        d.category = TEMPLATES_CATEGORY
        d.save()

        assert d.is_template

        d.title = 'Back to document'
        d.category = CATEGORIES[0][0]
        d.save()

        assert not d.is_template
Пример #18
0
    def test_template_title_and_category_to_template(self):
        d = DocumentFactory()

        # First, try and change just the title. It should fail.
        d.title = TEMPLATE_TITLE_PREFIX + d.title
        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 = TEMPLATES_CATEGORY
        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 = TEMPLATE_TITLE_PREFIX + d.title
        d.category = TEMPLATES_CATEGORY
        d.save()
Пример #19
0
    def test_template_title_and_category_to_template(self):
        d = DocumentFactory()

        # First, try and change just the title. It should fail.
        d.title = TEMPLATE_TITLE_PREFIX + d.title
        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 = TEMPLATES_CATEGORY
        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 = TEMPLATE_TITLE_PREFIX + d.title
        d.category = TEMPLATES_CATEGORY
        d.save()
Пример #20
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
Пример #21
0
    def test_wiki_section(self):
        """Verify the wiki doc appears on the landing page."""
        # If "Mozilla News" article doesn't exist, home page
        # should still work and omit the section.
        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        eq_(len(doc('#doc-content')), 0)

        # Create the "Mozilla News" article and verify it on home page.
        d = DocumentFactory(title='Community Hub News', slug='community-hub-news')
        rev = ApprovedRevisionFactory(document=d, content='splendid')
        d.current_revision = rev
        d.save()
        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        community_news = doc('#doc-content')
        eq_(len(community_news), 1)
        assert 'splendid' in community_news.text()
Пример #22
0
    def test_wiki_section(self):
        """Verify the wiki doc appears on the landing page."""
        # If "Mozilla News" article doesn't exist, home page
        # should still work and omit the section.
        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        eq_(len(doc('#doc-content')), 0)

        # Create the "Mozilla News" article and verify it on home page.
        d = DocumentFactory(title='Community Hub News', slug='community-hub-news')
        rev = ApprovedRevisionFactory(document=d, content='splendid')
        d.current_revision = rev
        d.save()
        response = self.client.get(urlparams(reverse('community.home')))
        eq_(response.status_code, 200)
        doc = pq(response.content)
        community_news = doc('#doc-content')
        eq_(len(community_news), 1)
        assert 'splendid' in community_news.text()
Пример #23
0
    def test_search_suggestions_questions(self):
        """Verifies the view doesn't kick up an HTTP 500"""
        p = ProductFactory(slug=u"firefox")
        locale = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE)
        p.questions_locales.add(locale)
        TopicFactory(title="Fix problems", slug="fix-problems", product=p)
        q = QuestionFactory(product=p, title=u"CupcakesQuestion cupcakes")

        d = DocumentFactory(title=u"CupcakesKB cupcakes", category=10)
        d.products.add(p)

        RevisionFactory(document=d, is_approved=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
Пример #24
0
    def test_search_suggestions_questions(self):
        """Verifies the view doesn't kick up an HTTP 500"""
        p = ProductFactory(slug=u'firefox')
        l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE)
        p.questions_locales.add(l)
        TopicFactory(title='Fix problems', slug='fix-problems', product=p)
        q = QuestionFactory(product=p, title=u'CupcakesQuestion cupcakes')

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

        RevisionFactory(document=d, is_approved=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
Пример #25
0
 def _create_doc(self, content):
     # Create the canned responses article.
     doc = DocumentFactory(slug=REPLIES_DOCUMENT_SLUG)
     rev = RevisionFactory(document=doc, content=content, is_approved=True)
     doc.current_revision = rev
     doc.save()
Пример #26
0
 def _create_doc(self, content):
     # Create the canned responses article.
     doc = DocumentFactory(slug=REPLIES_DOCUMENT_SLUG)
     rev = RevisionFactory(document=doc, content=content, is_approved=True)
     doc.current_revision = rev
     doc.save()
Пример #27
0
class WikiDocumentSignalsTests(Elastic7TestCase):
    def setUp(self):
        self.document = DocumentFactory()
        self.document_id = self.document.id

    def get_doc(self):
        return WikiDocument.get(self.document_id)

    def test_document_save(self):
        RevisionFactory(document=self.document, is_approved=True)
        self.document.title = "foobar"
        self.document.save()

        self.assertEqual(self.get_doc().title["en-US"], "foobar")

    def test_revision_save(self):
        RevisionFactory(document=self.document,
                        is_approved=True,
                        keywords="foobar")

        self.assertIn("foobar", self.get_doc().keywords["en-US"])

    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)

    def test_topics_change(self):
        topic = TopicFactory()
        RevisionFactory(document=self.document, is_approved=True)
        self.document.topics.add(topic)

        self.assertIn(topic.id, self.get_doc().topic_ids)

        self.document.topics.remove(topic)

        self.assertEqual(None, self.get_doc().topic_ids)

    def test_document_delete(self):
        RevisionFactory(document=self.document, is_approved=True)
        self.document.delete()

        with self.assertRaises(NotFoundError):
            self.get_doc()

    def test_revision_delete(self):
        RevisionFactory(document=self.document,
                        keywords="revision1",
                        is_approved=True)
        revision2 = RevisionFactory(document=self.document,
                                    keywords="revision2",
                                    is_approved=True)
        self.assertEqual(self.get_doc().keywords["en-US"], "revision2")
        revision2.delete()

        self.assertNotIn("revision2", self.get_doc().keywords["en-US"])
        self.assertEqual(self.get_doc().keywords["en-US"], "revision1")

    def test_product_delete(self):
        RevisionFactory(document=self.document, is_approved=True)
        product = ProductFactory()
        self.document.products.add(product)
        product.delete()

        self.assertEqual(self.get_doc().product_ids, [])

    def test_topic_delete(self):
        RevisionFactory(document=self.document, is_approved=True)
        topic = TopicFactory()
        self.document.topics.add(topic)
        topic.delete()

        self.assertEqual(self.get_doc().topic_ids, [])

    def test_non_approved_revision_update(self):
        RevisionFactory(document=self.document, is_approved=False)

        with self.assertRaises(NotFoundError):
            self.get_doc()