• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python factories.PublishableContentFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了PublishableContentFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:josephcab,项目名称:zds-site,代码行数:35,代码来源:tests_opinion_views.py


示例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)
开发者ID:josephcab,项目名称:zds-site,代码行数:35,代码来源:tests_utils.py


示例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)
开发者ID:josephcab,项目名称:zds-site,代码行数:10,代码来源:tests_models.py


示例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])
开发者ID:josephcab,项目名称:zds-site,代码行数:11,代码来源:tests_models.py


示例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])
开发者ID:josephcab,项目名称:zds-site,代码行数:11,代码来源:tests_models.py


示例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)])
开发者ID:josephcab,项目名称:zds-site,代码行数:12,代码来源:tests_utils.py


示例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])
开发者ID:josephcab,项目名称:zds-site,代码行数:12,代码来源:tests_models.py


示例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
开发者ID:josephcab,项目名称:zds-site,代码行数:57,代码来源:tests_utils.py


示例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])
开发者ID:josephcab,项目名称:zds-site,代码行数:13,代码来源:tests_models.py


示例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)
开发者ID:josephcab,项目名称:zds-site,代码行数:14,代码来源:tests_models.py


示例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)
开发者ID:josephcab,项目名称:zds-site,代码行数:15,代码来源:tests_models.py


示例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()
开发者ID:josephcab,项目名称:zds-site,代码行数:34,代码来源:tests_move.py


示例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()
开发者ID:josephcab,项目名称:zds-site,代码行数:27,代码来源:tests_utils.py


示例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'))
开发者ID:josephcab,项目名称:zds-site,代码行数:25,代码来源:tests_tricky.py


示例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)
开发者ID:josephcab,项目名称:zds-site,代码行数:35,代码来源:tests_interventions.py


示例16: test_char_count_after_publication

    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)
开发者ID:josephcab,项目名称:zds-site,代码行数:35,代码来源:tests_models.py


示例17: test_content_ordering

    def test_content_ordering(self):
        category_1 = ContentCategoryFactory()
        category_2 = ContentCategoryFactory()
        subcategory_1 = SubCategoryFactory(category=category_1)
        subcategory_1.position = 5
        subcategory_1.save()
        subcategory_2 = SubCategoryFactory(category=category_1)
        subcategory_2.position = 1
        subcategory_2.save()
        subcategory_3 = SubCategoryFactory(category=category_2)

        tuto_1 = PublishableContentFactory(type='TUTORIAL')
        tuto_1.subcategory.add(subcategory_1)
        tuto_1_draft = tuto_1.load_version()
        publish_content(tuto_1, tuto_1_draft, is_major_update=True)

        top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories')
        expected = [(subcategory_1.title, subcategory_1.slug, category_1.slug)]
        self.assertEqual(top_categories_tuto[category_1.title], expected)

        tuto_2 = PublishableContentFactory(type='TUTORIAL')
        tuto_2.subcategory.add(subcategory_2)
        tuto_2_draft = tuto_2.load_version()
        publish_content(tuto_2, tuto_2_draft, is_major_update=True)

        top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories')
        # New subcategory is now first is the list
        expected.insert(0, (subcategory_2.title, subcategory_2.slug, category_1.slug))
        self.assertEqual(top_categories_tuto[category_1.title], expected)

        article_1 = PublishableContentFactory(type='TUTORIAL')
        article_1.subcategory.add(subcategory_3)
        article_1_draft = tuto_2.load_version()
        publish_content(article_1, article_1_draft, is_major_update=True)

        # New article has no impact
        top_categories_tuto = topbar_publication_categories('TUTORIAL').get('categories')
        self.assertEqual(top_categories_tuto[category_1.title], expected)

        top_categories_contents = topbar_publication_categories(['TUTORIAL', 'ARTICLE']).get('categories')
        expected_2 = [(subcategory_3.title, subcategory_3.slug, category_2.slug)]
        self.assertEqual(top_categories_contents[category_1.title], expected)
        self.assertEqual(top_categories_contents[category_2.title], expected_2)
开发者ID:josephcab,项目名称:zds-site,代码行数:43,代码来源:tests_topbar_tags.py


示例18: setUp

    def setUp(self):
        self.overridden_zds_app = overridden_zds_app
        # don't build PDF to speed up the tests
        overridden_zds_app['content']['build_pdf_when_published'] = False

        self.staff = StaffProfileFactory().user

        settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
        self.mas = ProfileFactory().user
        overridden_zds_app['member']['bot_account'] = self.mas.username

        bot = Group(name=overridden_zds_app['member']['bot_group'])
        bot.save()
        self.external = UserFactory(
            username=overridden_zds_app['member']['external_account'],
            password='anything')

        self.beta_forum = ForumFactory(
            pk=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.licence = LicenceFactory()
        self.subcategory = SubCategoryFactory()

        self.user_author = ProfileFactory().user
        self.user_staff = StaffProfileFactory().user
        self.user_guest = ProfileFactory().user

        # create a tutorial
        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()

        # fill it with one part, containing one chapter, containing one extract
        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)

        # then, publish it !
        version = self.tuto_draft.current_version
        self.published = publish_content(self.tuto, self.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.tutofeed = LastTutorialsFeedRSS()
开发者ID:josephcab,项目名称:zds-site,代码行数:53,代码来源:tests_feeds.py


示例19: test_ensure_slug_stay

    def test_ensure_slug_stay(self):
        """This test ensures that slugs are not modified when coming from a manifest"""

        tuto = PublishableContentFactory(type='TUTORIAL')
        versioned = tuto.load_version()

        random = 'Non, piti bug, tu ne reviendras plus !!!'
        title = "N'importe quel titre"

        # add three container with the same title
        versioned.repo_add_container(title, random, random)  # x
        versioned.repo_add_container(title, random, random)  # x-1
        version = versioned.repo_add_container(title, random, random)  # x-2
        self.assertEqual(len(versioned.children), 3)

        current = tuto.load_version(sha=version)
        self.assertEqual(len(current.children), 3)

        for index, child in enumerate(current.children):
            self.assertEqual(child.slug, versioned.children[index].slug)  # same order

        # then, delete the second one:
        last_slug = versioned.children[2].slug
        version = versioned.children[1].repo_delete()
        self.assertEqual(len(versioned.children), 2)
        self.assertEqual(versioned.children[1].slug, last_slug)

        current = tuto.load_version(sha=version)
        self.assertEqual(len(current.children), 2)

        for index, child in enumerate(current.children):
            self.assertEqual(child.slug, versioned.children[index].slug)  # slug remains

        # same test with extracts
        chapter = versioned.children[0]
        chapter.repo_add_extract(title, random)  # x
        chapter.repo_add_extract(title, random)  # x-1
        version = chapter.repo_add_extract(title, random)  # x-2
        self.assertEqual(len(chapter.children), 3)

        current = tuto.load_version(sha=version)
        self.assertEqual(len(current.children[0].children), 3)

        for index, child in enumerate(current.children[0].children):
            self.assertEqual(child.slug, chapter.children[index].slug)  # slug remains

        # delete the second one!
        last_slug = chapter.children[2].slug
        version = chapter.children[1].repo_delete()
        self.assertEqual(len(chapter.children), 2)
        self.assertEqual(chapter.children[1].slug, last_slug)

        current = tuto.load_version(sha=version)
        self.assertEqual(len(current.children[0].children), 2)

        for index, child in enumerate(current.children[0].children):
            self.assertEqual(child.slug, chapter.children[index].slug)  # slug remains for extract as well!
开发者ID:josephcab,项目名称:zds-site,代码行数:57,代码来源:tests_models.py


示例20: test_publish_content_big_tuto

    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)
开发者ID:josephcab,项目名称:zds-site,代码行数:56,代码来源:tests_utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_current_user函数代码示例发布时间:2022-05-26
下一篇:
Python resourcelibrary.need函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap