本文整理汇总了Python中kitsune.wiki.tests.DocumentFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python DocumentFactory.save方法的具体用法?Python DocumentFactory.save怎么用?Python DocumentFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kitsune.wiki.tests.DocumentFactory
的用法示例。
在下文中一共展示了DocumentFactory.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_category_inheritance
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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)
示例2: test_template_title_and_category_localized
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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()
示例3: test_from_french
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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)
示例4: test_no_redirect_on_unsaved_change
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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()
示例5: _make_document
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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
示例6: test_ready_for_l10n
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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"])
示例7: test_only_show_wiki_and_questions
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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)
示例8: create_documents
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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
示例9: test_document_is_template
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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
示例10: test_template_title_and_category_to_template
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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()
示例11: test_wiki_section
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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()
示例12: test_search_suggestions_questions
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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
示例13: _create_doc
# 需要导入模块: from kitsune.wiki.tests import DocumentFactory [as 别名]
# 或者: from kitsune.wiki.tests.DocumentFactory import save [as 别名]
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()