本文整理汇总了Python中zds.tutorialv2.factories.PublishableContentFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python PublishableContentFactory.save方法的具体用法?Python PublishableContentFactory.save怎么用?Python PublishableContentFactory.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zds.tutorialv2.factories.PublishableContentFactory
的用法示例。
在下文中一共展示了PublishableContentFactory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_opinion_publication_guest
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_opinion_publication_guest(self):
"""
Test the publication of PublishableContent where type is OPINION (with guest => 403).
"""
text_publication = 'Aussi tôt dit, aussi tôt fait !'
opinion = PublishableContentFactory(type='OPINION')
opinion.authors.add(self.user_author)
UserGalleryFactory(gallery=opinion.gallery, user=self.user_author, mode='W')
opinion.licence = self.licence
opinion.save()
opinion_draft = opinion.load_version()
ExtractFactory(container=opinion_draft, db_object=opinion)
ExtractFactory(container=opinion_draft, db_object=opinion)
self.assertEqual(
self.client.login(
username=self.user_guest.username,
password='hostel77'),
True)
result = self.client.post(
reverse('validation:publish-opinion', kwargs={'pk': opinion.pk, 'slug': opinion.slug}),
{
'text': text_publication,
'source': '',
'version': opinion_draft.current_version
},
follow=False)
self.assertEqual(result.status_code, 403)
self.assertEqual(PublishedContent.objects.count(), 0)
示例2: test_char_count_after_publication
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_char_count_after_publication(self):
"""Test the ``get_char_count()`` function.
Special care should be taken with this function, since:
- The username of the author is, by default "Firmxxx" where "xxx" depends on the tests before ;
- The titles (!) also contains a number that also depends on the number of tests before ;
- The date is ``datetime.now()`` and contains the months, which is never a fixed number of letters.
"""
author = ProfileFactory().user
author.username = 'NotAFirm1Clone'
author.save()
len_date_now = len(date(datetime.now(), 'd F Y'))
article = PublishedContentFactory(type='ARTICLE', author_list=[author], title='Un titre')
published = PublishedContent.objects.filter(content=article).first()
self.assertEqual(published.get_char_count(), 160 + len_date_now)
tuto = PublishableContentFactory(type='TUTORIAL', author_list=[author], title='Un titre')
# add a chapter, so it becomes a middle tutorial
tuto_draft = tuto.load_version()
chapter1 = ContainerFactory(parent=tuto_draft, db_object=tuto, title='Un chapitre')
ExtractFactory(container=chapter1, db_object=tuto, title='Un extrait')
published = publish_content(tuto, tuto_draft, is_major_update=True)
tuto.sha_public = tuto_draft.current_version
tuto.sha_draft = tuto_draft.current_version
tuto.public_version = published
tuto.save()
published = PublishedContent.objects.filter(content=tuto).first()
self.assertEqual(published.get_char_count(), 335 + len_date_now)
示例3: test_publish_content_article
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_publish_content_article(self):
"""test and ensure the behavior of ``publish_content()`` and ``unpublish_content()``"""
# 1. Article:
article = PublishableContentFactory(type='ARTICLE')
article.authors.add(self.user_author)
UserGalleryFactory(gallery=article.gallery, user=self.user_author, mode='W')
article.licence = self.licence
article.save()
# populate the article
article_draft = article.load_version()
ExtractFactory(container=article_draft, db_object=article)
ExtractFactory(container=article_draft, db_object=article)
self.assertEqual(len(article_draft.children), 2)
# publish !
article = PublishableContent.objects.get(pk=article.pk)
published = publish_content(article, article_draft)
self.assertEqual(published.content, article)
self.assertEqual(published.content_pk, article.pk)
self.assertEqual(published.content_type, article.type)
self.assertEqual(published.content_public_slug, article_draft.slug)
self.assertEqual(published.sha_public, article.sha_draft)
public = article.load_version(sha=published.sha_public, public=published)
self.assertIsNotNone(public)
self.assertTrue(public.PUBLIC) # it's a PublicContent object
self.assertEqual(public.type, published.content_type)
self.assertEqual(public.current_version, published.sha_public)
# test object created in database
self.assertEqual(PublishedContent.objects.filter(content=article).count(), 1)
published = PublishedContent.objects.filter(content=article).last()
self.assertEqual(published.content_pk, article.pk)
self.assertEqual(published.content_public_slug, article_draft.slug)
self.assertEqual(published.content_type, article.type)
self.assertEqual(published.sha_public, public.current_version)
# test creation of files:
self.assertTrue(os.path.isdir(published.get_prod_path()))
self.assertTrue(os.path.isfile(os.path.join(published.get_prod_path(), 'manifest.json')))
prod_path = public.get_prod_path()
self.assertTrue(prod_path.endswith('.html'), prod_path)
self.assertTrue(os.path.isfile(prod_path), prod_path) # normally, an HTML file should exists
self.assertIsNone(public.introduction) # since all is in the HTML file, introduction does not exists anymore
self.assertIsNone(public.conclusion)
article.public_version = published
article.save()
# depublish it !
unpublish_content(article)
self.assertEqual(PublishedContent.objects.filter(content=article).count(), 0) # published object disappear
self.assertFalse(os.path.exists(public.get_prod_path())) # article was removed
示例4: test_publish_content_big_tuto
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_publish_content_big_tuto(self):
# 4. Big tutorial:
bigtuto = PublishableContentFactory(type='TUTORIAL')
bigtuto.authors.add(self.user_author)
UserGalleryFactory(gallery=bigtuto.gallery, user=self.user_author, mode='W')
bigtuto.licence = self.licence
bigtuto.save()
# populate with 2 part (1 chapter with 1 extract each)
bigtuto_draft = bigtuto.load_version()
part1 = ContainerFactory(parent=bigtuto_draft, db_objet=bigtuto)
chapter1 = ContainerFactory(parent=part1, db_objet=bigtuto)
ExtractFactory(container=chapter1, db_object=bigtuto)
part2 = ContainerFactory(parent=bigtuto_draft, db_objet=bigtuto)
chapter2 = ContainerFactory(parent=part2, db_objet=bigtuto)
ExtractFactory(container=chapter2, db_object=bigtuto)
# publish it
bigtuto = PublishableContent.objects.get(pk=bigtuto.pk)
published = publish_content(bigtuto, bigtuto_draft)
self.assertEqual(published.content, bigtuto)
self.assertEqual(published.content_pk, bigtuto.pk)
self.assertEqual(published.content_type, bigtuto.type)
self.assertEqual(published.content_public_slug, bigtuto_draft.slug)
self.assertEqual(published.sha_public, bigtuto.sha_draft)
public = bigtuto.load_version(sha=published.sha_public, public=published)
self.assertIsNotNone(public)
self.assertTrue(public.PUBLIC) # it's a PublicContent object
self.assertEqual(public.type, published.content_type)
self.assertEqual(public.current_version, published.sha_public)
# test creation of files:
self.assertTrue(os.path.isdir(published.get_prod_path()))
self.assertTrue(os.path.isfile(os.path.join(published.get_prod_path(), 'manifest.json')))
self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), public.introduction)))
self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), public.conclusion)))
self.assertEqual(len(public.children), 2)
for part in public.children:
self.assertTrue(os.path.isdir(part.get_prod_path())) # a directory for each part
# ... and an HTML file for introduction and conclusion
self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), part.introduction)))
self.assertTrue(os.path.isfile(os.path.join(public.get_prod_path(), part.conclusion)))
self.assertEqual(len(part.children), 1)
for chapter in part.children:
# the HTML file is located in the good directory:
self.assertEqual(part.get_prod_path(), os.path.dirname(chapter.get_prod_path()))
self.assertTrue(os.path.isfile(chapter.get_prod_path())) # an HTML file for each chapter
self.assertIsNone(chapter.introduction)
self.assertIsNone(chapter.conclusion)
示例5: test_get_tuto_count
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_tuto_count(self):
# Start with 0
self.assertEqual(self.user1.get_tuto_count(), 0)
# Create Tuto !
minituto = PublishableContentFactory(type='TUTORIAL')
minituto.authors.add(self.user1.user)
minituto.gallery = GalleryFactory()
minituto.save()
# Should be 1
self.assertEqual(self.user1.get_tuto_count(), 1)
示例6: test_image_with_non_ascii_chars
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_image_with_non_ascii_chars(self):
"""seen on #4144"""
article = PublishableContentFactory(type='article', author_list=[self.user_author])
image_string = '![Portrait de Richard Stallman en 2014. [Source](https://commons.wikimedia.org/wiki/' \
'File:Richard_Stallman_-_Fête_de_l%27Humanité_2014_-_010.jpg).]' \
'(/media/galleries/4410/c1016bf1-a1de-48a1-9ef1-144308e8725d.jpg)'
article.sha_draft = article.load_version().repo_update(article.title, image_string, '', update_slug=False)
article.save(force_slug_update=False)
publish_content(article, article.load_version())
self.assertTrue(PublishedContent.objects.filter(content_id=article.pk).exists())
示例7: test_get_draft_articles
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_draft_articles(self):
# Start with 0
self.assertEqual(len(self.user1.get_draft_articles()), 0)
# Create article !
article = PublishableContentFactory(type='ARTICLE')
article.authors.add(self.user1.user)
article.save()
# Should be 1
articles = self.user1.get_draft_articles()
self.assertEqual(len(articles), 1)
self.assertEqual(article, articles[0])
示例8: test_get_validate_tutos
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_validate_tutos(self):
# Start with 0
self.assertEqual(len(self.user1.get_validate_tutos()), 0)
# Create Tuto !
validatetuto = PublishableContentFactory(type='TUTORIAL', author_list=[self.user1.user])
validatetuto.sha_validation = 'whatever'
validatetuto.save()
# Should be 1
validatetutos = self.user1.get_validate_tutos()
self.assertEqual(len(validatetutos), 1)
self.assertEqual(validatetuto, validatetutos[0])
示例9: test_get_draft_tutos
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_draft_tutos(self):
# Start with 0
self.assertEqual(len(self.user1.get_draft_tutos()), 0)
# Create Tuto !
drafttuto = PublishableContentFactory(type='TUTORIAL')
drafttuto.authors.add(self.user1.user)
drafttuto.gallery = GalleryFactory()
drafttuto.save()
# Should be 1
drafttutos = self.user1.get_draft_tutos()
self.assertEqual(len(drafttutos), 1)
self.assertEqual(drafttuto, drafttutos[0])
示例10: create_multiple_tags
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def create_multiple_tags(self, number_of_tags=REST_PAGE_SIZE):
tags = []
for tag in range(0, number_of_tags):
tags.append('number' + str(tag))
# Prepare content containing all the tags
content = PublishableContentFactory(type='TUTORIAL')
content.add_tags(tags)
content.save()
content_draft = content.load_version()
# then, publish it !
publish_content(content, content_draft)
示例11: test_get_beta_tutos
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_beta_tutos(self):
# Start with 0
self.assertEqual(len(self.user1.get_beta_tutos()), 0)
# Create Tuto !
betatetuto = PublishableContentFactory(type='TUTORIAL')
betatetuto.authors.add(self.user1.user)
betatetuto.gallery = GalleryFactory()
betatetuto.sha_beta = 'whatever'
betatetuto.save()
# Should be 1
betatetutos = self.user1.get_beta_tutos()
self.assertEqual(len(betatetutos), 1)
self.assertEqual(betatetuto, betatetutos[0])
示例12: test_get_public_tutos
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_public_tutos(self):
# Start with 0
self.assertEqual(len(self.user1.get_public_tutos()), 0)
# Create Tuto !
publictuto = PublishableContentFactory(type='TUTORIAL')
publictuto.authors.add(self.user1.user)
publictuto.gallery = GalleryFactory()
publictuto.sha_public = 'whatever'
publictuto.save()
# Should be 0 because publication was not used
publictutos = self.user1.get_public_tutos()
self.assertEqual(len(publictutos), 0)
PublishedContentFactory(author_list=[self.user1.user])
self.assertEqual(len(self.user1.get_public_tutos()), 1)
示例13: test_get_public_articles
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_get_public_articles(self):
# Start with 0
self.assertEqual(len(self.user1.get_public_articles()), 0)
# Create article !
article = PublishableContentFactory(type='ARTICLE')
article.authors.add(self.user1.user)
article.sha_public = 'whatever'
article.save()
# Should be 0
articles = self.user1.get_public_articles()
self.assertEqual(len(articles), 0)
# Should be 1
PublishedContentFactory(author_list=[self.user1.user], type='ARTICLE')
self.assertEqual(len(self.user1.get_public_articles()), 1)
self.assertEqual(len(self.user1.get_public_tutos()), 0)
示例14: test_publish_content_medium_tuto
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_publish_content_medium_tuto(self):
# 3. Medium-size tutorial
midsize_tuto = PublishableContentFactory(type='TUTORIAL')
midsize_tuto.authors.add(self.user_author)
UserGalleryFactory(gallery=midsize_tuto.gallery, user=self.user_author, mode='W')
midsize_tuto.licence = self.licence
midsize_tuto.save()
# populate with 2 chapters (1 extract each)
midsize_tuto_draft = midsize_tuto.load_version()
chapter1 = ContainerFactory(parent=midsize_tuto_draft, db_objet=midsize_tuto)
ExtractFactory(container=chapter1, db_object=midsize_tuto)
chapter2 = ContainerFactory(parent=midsize_tuto_draft, db_objet=midsize_tuto)
ExtractFactory(container=chapter2, db_object=midsize_tuto)
# publish it
midsize_tuto = PublishableContent.objects.get(pk=midsize_tuto.pk)
published = publish_content(midsize_tuto, midsize_tuto_draft)
self.assertEqual(published.content, midsize_tuto)
self.assertEqual(published.content_pk, midsize_tuto.pk)
self.assertEqual(published.content_type, midsize_tuto.type)
self.assertEqual(published.content_public_slug, midsize_tuto_draft.slug)
self.assertEqual(published.sha_public, midsize_tuto.sha_draft)
public = midsize_tuto.load_version(sha=published.sha_public, public=published)
self.assertIsNotNone(public)
self.assertTrue(public.PUBLIC) # it's a PublicContent object
self.assertEqual(public.type, published.content_type)
self.assertEqual(public.current_version, published.sha_public)
# test creation of files:
self.assertTrue(Path(published.get_prod_path()).is_dir())
self.assertTrue(Path(published.get_prod_path(), 'manifest.json').is_file())
self.assertTrue(Path(public.get_prod_path(), public.introduction).is_file())
self.assertTrue(Path(public.get_prod_path(), public.conclusion).is_file())
self.assertEqual(len(public.children), 2)
for child in public.children:
self.assertTrue(os.path.isfile(child.get_prod_path())) # an HTML file for each chapter
self.assertIsNone(child.introduction)
self.assertIsNone(child.conclusion)
示例15: test_upercase_and_lowercase_search_give_same_results
# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import save [as 别名]
def test_upercase_and_lowercase_search_give_same_results(self):
"""Pretty self-explanatory function name, isn't it ?"""
if not self.manager.connected_to_es:
return
# 1. Index lowercase stuffs
text_lc = 'test'
topic_1_lc = TopicFactory(forum=self.forum, author=self.user, title=text_lc)
tag_lc = TagFactory(title=text_lc)
topic_1_lc.tags.add(tag_lc)
topic_1_lc.subtitle = text_lc
topic_1_lc.save()
post_1_lc = PostFactory(topic=topic_1_lc, author=self.user, position=1)
post_1_lc.text = post_1_lc.text_html = text_lc
post_1_lc.save()
tuto_lc = PublishableContentFactory(type='TUTORIAL')
tuto_draft_lc = tuto_lc.load_version()
tuto_lc.title = text_lc
tuto_lc.authors.add(self.user)
subcategory_lc = SubCategoryFactory(title=text_lc)
tuto_lc.subcategory.add(subcategory_lc)
tuto_lc.tags.add(tag_lc)
tuto_lc.save()
tuto_draft_lc.description = text_lc
tuto_draft_lc.repo_update_top_container(text_lc, tuto_lc.slug, text_lc, text_lc)
chapter1_lc = ContainerFactory(parent=tuto_draft_lc, db_object=tuto_lc)
extract_lc = ExtractFactory(container=chapter1_lc, db_object=tuto_lc)
extract_lc.repo_update(text_lc, text_lc)
published_lc = publish_content(tuto_lc, tuto_draft_lc, is_major_update=True)
tuto_lc.sha_public = tuto_draft_lc.current_version
tuto_lc.sha_draft = tuto_draft_lc.current_version
tuto_lc.public_version = published_lc
tuto_lc.save()
# 2. Index uppercase stuffs
text_uc = 'TEST'
topic_1_uc = TopicFactory(forum=self.forum, author=self.user, title=text_uc)
topic_1_uc.tags.add(tag_lc) # Note: a constraint forces tags title to be unique
topic_1_uc.subtitle = text_uc
topic_1_uc.save()
post_1_uc = PostFactory(topic=topic_1_uc, author=self.user, position=1)
post_1_uc.text = post_1_uc.text_html = text_uc
post_1_uc.save()
tuto_uc = PublishableContentFactory(type='TUTORIAL')
tuto_draft_uc = tuto_uc.load_version()
tuto_uc.title = text_uc
tuto_uc.authors.add(self.user)
tuto_uc.subcategory.add(subcategory_lc)
tuto_uc.tags.add(tag_lc)
tuto_uc.save()
tuto_draft_uc.description = text_uc
tuto_draft_uc.repo_update_top_container(text_uc, tuto_uc.slug, text_uc, text_uc)
chapter1_uc = ContainerFactory(parent=tuto_draft_uc, db_object=tuto_uc)
extract_uc = ExtractFactory(container=chapter1_uc, db_object=tuto_uc)
extract_uc.repo_update(text_uc, text_uc)
published_uc = publish_content(tuto_uc, tuto_draft_uc, is_major_update=True)
tuto_uc.sha_public = tuto_draft_uc.current_version
tuto_uc.sha_draft = tuto_draft_uc.current_version
tuto_uc.public_version = published_uc
tuto_uc.save()
# 3. Index and search:
self.assertEqual(len(self.manager.setup_search(Search().query(MatchAll())).execute()), 0)
# index
for model in self.indexable:
if model is FakeChapter:
continue
self.manager.es_bulk_indexing_of_model(model)
self.manager.refresh_index()
result = self.client.get(reverse('search:query') + '?q=' + text_lc, follow=False)
self.assertEqual(result.status_code, 200)
response_lc = result.context['object_list'].execute()
self.assertEqual(response_lc.hits.total, 8)
result = self.client.get(reverse('search:query') + '?q=' + text_uc, follow=False)
self.assertEqual(result.status_code, 200)
response_uc = result.context['object_list'].execute()
#.........这里部分代码省略.........