本文整理汇总了Python中zds.tutorialv2.factories.PublishableContentFactory类的典型用法代码示例。如果您正苦于以下问题:Python PublishableContentFactory类的具体用法?Python PublishableContentFactory怎么用?Python PublishableContentFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PublishableContentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_opinion_publication_guest
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: testParseBadManifest
def testParseBadManifest(self):
base_content = PublishableContentFactory(author_list=[self.user_author])
versioned = base_content.load_version()
versioned.add_container(Container('un peu plus près de 42'))
versioned.dump_json()
manifest = os.path.join(versioned.get_path(), 'manifest.json')
dictionary = json_handler.load(open(manifest))
old_title = dictionary['title']
# first bad title
dictionary['title'] = 81 * ['a']
self.assertRaises(BadManifestError,
get_content_from_json, dictionary, None, '',
max_title_len=PublishableContent._meta.get_field('title').max_length)
dictionary['title'] = ''.join(dictionary['title'])
self.assertRaises(BadManifestError,
get_content_from_json, dictionary, None, '',
max_title_len=PublishableContent._meta.get_field('title').max_length)
dictionary['title'] = '...'
self.assertRaises(InvalidSlugError,
get_content_from_json, dictionary, None, '',
max_title_len=PublishableContent._meta.get_field('title').max_length)
dictionary['title'] = old_title
dictionary['children'][0]['title'] = 81 * ['a']
self.assertRaises(BadManifestError,
get_content_from_json, dictionary, None, '',
max_title_len=PublishableContent._meta.get_field('title').max_length)
dictionary['children'][0]['title'] = 'bla'
dictionary['children'][0]['slug'] = '...'
self.assertRaises(InvalidSlugError,
get_content_from_json, dictionary, None, '',
max_title_len=PublishableContent._meta.get_field('title').max_length)
示例3: test_get_tuto_count
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)
示例4: test_get_validate_tutos
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])
示例5: test_get_draft_articles
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])
示例6: test_tagged_tree_extract
def test_tagged_tree_extract(self):
midsize = PublishableContentFactory(author_list=[self.user_author])
midsize_draft = midsize.load_version()
first_container = ContainerFactory(parent=midsize_draft, db_object=midsize)
second_container = ContainerFactory(parent=midsize_draft, db_object=midsize)
first_extract = ExtractFactory(container=first_container, db_object=midsize)
second_extract = ExtractFactory(container=second_container, db_object=midsize)
tagged_tree = get_target_tagged_tree_for_extract(first_extract, midsize_draft)
paths = {i[0]: i[3] for i in tagged_tree}
self.assertTrue(paths[second_extract.get_full_slug()])
self.assertFalse(paths[second_container.get_path(True)])
self.assertFalse(paths[first_container.get_path(True)])
示例7: test_get_draft_tutos
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])
示例8: test_publish_content_article
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
示例9: test_get_beta_tutos
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])
示例10: test_get_public_tutos
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)
示例11: test_get_public_articles
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)
示例12: setUp
def setUp(self):
self.staff = StaffProfileFactory().user
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
self.mas = ProfileFactory().user
self.overridden_zds_app['member']['bot_account'] = self.mas.username
self.licence = LicenceFactory()
self.subcategory = SubCategoryFactory()
self.user_author = ProfileFactory().user
self.user_staff = StaffProfileFactory().user
self.user_guest = ProfileFactory().user
self.tuto = PublishableContentFactory(type='TUTORIAL')
self.tuto.authors.add(self.user_author)
UserGalleryFactory(gallery=self.tuto.gallery, user=self.user_author, mode='W')
self.tuto.licence = self.licence
self.tuto.subcategory.add(self.subcategory)
self.tuto.save()
self.beta_forum = ForumFactory(
pk=self.overridden_zds_app['forum']['beta_forum_id'],
category=CategoryFactory(position=1),
position_in_category=1) # ensure that the forum, for the beta versions, is created
self.tuto_draft = self.tuto.load_version()
self.part1 = ContainerFactory(parent=self.tuto_draft, db_object=self.tuto)
self.chapter1 = ContainerFactory(parent=self.part1, db_object=self.tuto)
self.extract1 = ExtractFactory(container=self.chapter1, db_object=self.tuto)
bot = Group(name=self.overridden_zds_app['member']['bot_group'])
bot.save()
示例13: setUp
def setUp(self):
self.mas = ProfileFactory().user
self.overridden_zds_app['member']['bot_account'] = self.mas.username
self.licence = LicenceFactory()
self.user_author = ProfileFactory().user
self.staff = StaffProfileFactory().user
self.tuto = PublishableContentFactory(type='TUTORIAL')
self.tuto.authors.add(self.user_author)
UserGalleryFactory(gallery=self.tuto.gallery, user=self.user_author, mode='W')
self.tuto.licence = self.licence
self.tuto.save()
self.tuto_draft = self.tuto.load_version()
self.part1 = ContainerFactory(parent=self.tuto_draft, db_object=self.tuto)
self.chapter1 = ContainerFactory(parent=self.part1, db_object=self.tuto)
self.old_registry = {key: value for key, value in PublicatorRegistry.get_all_registered()}
class TestPdfPublicator(Publicator):
def publish(self, md_file_path, base_name, **kwargs):
with Path(base_name + '.pdf').open('w') as f:
f.write('bla')
shutil.copy2(str(Path(base_name + '.pdf')),
str(Path(md_file_path.replace('__building', '')).parent))
PublicatorRegistry.registry['pdf'] = TestPdfPublicator()
示例14: setUp
def setUp(self):
# don't build PDF to speed up the tests
self.user1 = ProfileFactory().user
self.user2 = ProfileFactory().user
# create a tutorial
self.tuto = PublishableContentFactory(type='TUTORIAL')
self.tuto.authors.add(self.user1)
UserGalleryFactory(gallery=self.tuto.gallery, user=self.user1, mode='W')
self.tuto.licence = LicenceFactory()
self.tuto.subcategory.add(SubCategoryFactory())
self.tuto.save()
tuto_draft = self.tuto.load_version()
# then, publish it !
version = tuto_draft.current_version
self.published = publish_content(self.tuto, tuto_draft, is_major_update=True)
self.tuto.sha_public = version
self.tuto.sha_draft = version
self.tuto.public_version = self.published
self.tuto.save()
self.assertTrue(self.client.login(username=self.user1.username, password='hostel77'))
示例15: setUp
def setUp(self):
self.licence = LicenceFactory()
self.subcategory = SubCategoryFactory()
self.author = ProfileFactory()
self.user = ProfileFactory()
self.staff = StaffProfileFactory()
self.tuto = PublishableContentFactory(type='TUTORIAL')
self.tuto.authors.add(self.author.user)
self.tuto.licence = self.licence
self.tuto.subcategory.add(self.subcategory)
self.tuto.save()
self.validation = Validation(
content=self.tuto,
version=self.tuto.sha_draft,
comment_authors='bla',
date_proposition=datetime.now(),
)
self.validation.save()
self.topic = send_mp(author=self.author.user, users=[], title='Title', text='Testing', subtitle='', leave=False)
self.topic.participants.add(self.user.user)
send_message_mp(self.user.user, self.topic, 'Testing')
# humane_delta test
periods = ((1, 0), (2, 1), (3, 7), (4, 30), (5, 360))
cont = dict()
cont['date_today'] = periods[0][0]
cont['date_yesterday'] = periods[1][0]
cont['date_last_week'] = periods[2][0]
cont['date_last_month'] = periods[3][0]
cont['date_last_year'] = periods[4][0]
self.context = Context(cont)