当前位置: 首页>>代码示例>>Python>>正文


Python tests.DocumentFactory类代码示例

本文整理汇总了Python中kitsune.wiki.tests.DocumentFactory的典型用法代码示例。如果您正苦于以下问题:Python DocumentFactory类的具体用法?Python DocumentFactory怎么用?Python DocumentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DocumentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_majorly_outdated_with_unapproved_parents

    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.")
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:32,代码来源:test_models.py

示例2: test_from_french

 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)
开发者ID:1234-,项目名称:kitsune,代码行数:7,代码来源:test_parser.py

示例3: test_id_only

    def test_id_only(self):
        from_url = Document.from_url

        d = DocumentFactory(locale='en-US', title=u'How to delete Google Chrome?')
        doc = from_url(d.get_absolute_url(), id_only=True)
        self.assertEqual(d.title, doc.title)
        self.assertEqual(d.locale, doc.locale)
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:7,代码来源:test_models.py

示例4: test_miscounting_archived

    def test_miscounting_archived(self):
        """
        Verify that the l10n overview readout treats archived docs consistently.

        Bug 1012384
        """
        locale = 'nl'
        parent1 = DocumentFactory(category=CANNED_RESPONSES_CATEGORY, is_archived=False)
        translation1 = DocumentFactory(parent=parent1, locale=locale)
        parent2 = DocumentFactory(category=CANNED_RESPONSES_CATEGORY, is_archived=True)
        translation2 = DocumentFactory(parent=parent2, locale=locale)

        trans_rev1 = ApprovedRevisionFactory(document=parent1, is_ready_for_localization=True)
        ApprovedRevisionFactory(document=translation1, based_on=trans_rev1)
        trans_rev2 = ApprovedRevisionFactory(document=parent2, is_ready_for_localization=True)
        ApprovedRevisionFactory(document=translation2, based_on=trans_rev2)

        # Document.save() will enforce that parents and translations share is_archived.
        # The point of this is to test what happens when that isn't true though,
        # so bypass Document.save().
        translation2.is_archived = False
        ModelBase.save(translation2)
        eq_(translation2.is_archived, False)

        overview = l10n_overview_rows(locale)
        eq_(1, overview['all']['denominator'])
        eq_(1, overview['all']['numerator'])
开发者ID:1234-,项目名称:kitsune,代码行数:27,代码来源:test_readouts.py

示例5: test_check_host

 def test_check_host(self):
     from_url = Document.from_url
     d_en = DocumentFactory(locale='en-US', title=u'How to delete Google Chrome?')
     sumo_host = 'http://support.mozilla.org'
     invalid_url = urlparse.urljoin(sumo_host, d_en.get_absolute_url())
     self.assertIsNone(from_url(invalid_url))
     self.assertEqual(d_en, from_url(invalid_url, check_host=False))
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:7,代码来源:test_models.py

示例6: test_no_redirect_on_unsaved_change

 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()
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:8,代码来源:test_models.py

示例7: test_get_topics

    def test_get_topics(self):
        """Test the get_topics() method."""
        en_us = DocumentFactory(topics=TopicFactory.create_batch(2))
        eq_(2, len(en_us.get_topics()))

        # Localized document inherits parent's topics.
        DocumentFactory(parent=en_us)
        eq_(2, len(en_us.get_topics()))
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:8,代码来源:test_models.py

示例8: test_cannot_make_non_localizable_if_children

    def test_cannot_make_non_localizable_if_children(self):
        """You can't make a document non-localizable if it has children."""
        # Make English rev:
        en_doc = DocumentFactory(is_localizable=True)

        # Make Deutsch translation:
        DocumentFactory(parent=en_doc, locale='de')
        en_doc.is_localizable = False
        self.assertRaises(ValidationError, en_doc.save)
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:9,代码来源:test_models.py

示例9: test_delete_tagged_document

    def test_delete_tagged_document(self):
        """Make sure deleting a tagged doc deletes its tag relationships."""
        # TODO: Move to wherever the tests for TaggableMixin are.
        # This works because Django's delete() sees the `tags` many-to-many
        # field (actually a manager) and follows the reference.
        d = DocumentFactory(tags=['grape'])
        eq_(1, TaggedItem.objects.count())

        d.delete()
        eq_(0, TaggedItem.objects.count())
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例10: test_add_and_delete

    def test_add_and_delete(self):
        """Adding a doc should add it to the search index; deleting should
        delete it."""
        doc = DocumentFactory()
        RevisionFactory(document=doc, is_approved=True)
        self.refresh()
        eq_(DocumentMappingType.search().count(), 1)

        doc.delete()
        self.refresh()
        eq_(DocumentMappingType.search().count(), 0)
开发者ID:1234-,项目名称:kitsune,代码行数:11,代码来源:test_es.py

示例11: _make_document

    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
开发者ID:1234-,项目名称:kitsune,代码行数:11,代码来源:test_api.py

示例12: test_redirect_to_translated_document

    def test_redirect_to_translated_document(self):
        from_url = Document.from_url

        d_en = DocumentFactory(locale='en-US', title=u'How to delete Google Chrome?')
        d_tr = DocumentFactory(locale='tr', title=u'Google Chrome\'u nasıl silerim?', parent=d_en)
        # The /tr/kb/how-to-delete-google-chrome URL for Turkish locale
        # should be redirected to /tr/kb/google-chromeu-nasl-silerim
        # if there is a Turkish translation of the document.
        tr_translate_url = reverse('wiki.document', locale='tr', args=[d_en.slug])
        self.assertEqual(d_en.translated_to('tr'), from_url(tr_translate_url))
        self.assertEqual(d_tr, from_url(tr_translate_url))
        self.assertEqual(d_en, from_url(d_en.get_absolute_url()))
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:12,代码来源:test_models.py

示例13: test_category_inheritance

    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)
开发者ID:ChromiumEx,项目名称:kitsune,代码行数:26,代码来源:test_models.py

示例14: test_ready_for_l10n

    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"])
开发者ID:chupahanks,项目名称:kitsune,代码行数:14,代码来源:test_readouts.py

示例15: test_only_show_wiki_and_questions

    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)
开发者ID:Andisutra80,项目名称:kitsune,代码行数:48,代码来源:test_search_simple.py


注:本文中的kitsune.wiki.tests.DocumentFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。