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


Python PublishableContentFactory.load_version方法代码示例

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


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

示例1: test_publish_content_article

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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
开发者ID:josephcab,项目名称:zds-site,代码行数:59,代码来源:tests_utils.py

示例2: test_ensure_slug_stay

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
    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,代码行数:59,代码来源:tests_models.py

示例3: test_publish_content_big_tuto

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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)
开发者ID:josephcab,项目名称:zds-site,代码行数:58,代码来源:tests_utils.py

示例4: test_image_with_non_ascii_chars

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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())
开发者ID:josephcab,项目名称:zds-site,代码行数:12,代码来源:tests_utils.py

示例5: test_char_count_after_publication

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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)
开发者ID:josephcab,项目名称:zds-site,代码行数:37,代码来源:tests_models.py

示例6: testParseBadManifest

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
    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,代码行数:37,代码来源:tests_utils.py

示例7: test_opinion_publication_guest

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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)
开发者ID:josephcab,项目名称:zds-site,代码行数:37,代码来源:tests_opinion_views.py

示例8: test_extract_is_none

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
    def test_extract_is_none(self):
        """Test the case of a null extract"""

        article = PublishableContentFactory(type='ARTICLE')
        versioned = article.load_version()

        given_title = 'Peu importe, en fait, ça compte peu'
        some_text = 'Disparaitra aussi vite que possible'

        # add a new extract with `None` for text
        version = versioned.repo_add_extract(given_title, None)

        # check on the model:
        new_extract = versioned.children[-1]
        self.assertIsNone(new_extract.text)

        # it remains when loading the manifest!
        versioned2 = article.load_version(sha=version)
        self.assertIsNotNone(versioned2)
        self.assertIsNone(versioned.children[-1].text)

        version = new_extract.repo_update(given_title, None)
        self.assertIsNone(new_extract.text)

        # it remains
        versioned2 = article.load_version(sha=version)
        self.assertIsNotNone(versioned2)
        self.assertIsNone(versioned.children[-1].text)

        version = new_extract.repo_update(given_title, some_text)
        self.assertIsNotNone(new_extract.text)
        self.assertEqual(some_text, new_extract.get_text())

        # now it changes
        versioned2 = article.load_version(sha=version)
        self.assertIsNotNone(versioned2)
        self.assertIsNotNone(versioned.children[-1].text)

        # ... and lets go back
        version = new_extract.repo_update(given_title, None)
        self.assertIsNone(new_extract.text)

        # it has changed
        versioned2 = article.load_version(sha=version)
        self.assertIsNotNone(versioned2)
        self.assertIsNone(versioned.children[-1].text)
开发者ID:josephcab,项目名称:zds-site,代码行数:48,代码来源:tests_models.py

示例9: test_publish_content_medium_tuto

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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)
开发者ID:josephcab,项目名称:zds-site,代码行数:46,代码来源:tests_utils.py

示例10: test_content_ordering

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
    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,代码行数:45,代码来源:tests_topbar_tags.py

示例11: test_tagged_tree_extract

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
 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,代码行数:14,代码来源:tests_utils.py

示例12: create_multiple_tags

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [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)
开发者ID:josephcab,项目名称:zds-site,代码行数:15,代码来源:tests.py

示例13: NotificationPublishableContentTest

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
class NotificationPublishableContentTest(TestCase):
    def setUp(self):
        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'))

    def test_follow_content_at_publication(self):
        """
        When a content is published, authors automatically follow it.
        """
        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertIsNone(subscription)

        # Signal call by the view at the publication.
        signals.new_content.send(sender=self.tuto.__class__, instance=self.tuto, by_email=False)

        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertTrue(subscription.is_active)

    def test_follow_content_from_view(self):
        """
        Allows a user to follow (or not) a content from the view.
        """
        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertIsNone(subscription)

        result = self.client.post(reverse('content:follow-reactions', args=[self.tuto.pk]), {'follow': 1})
        self.assertEqual(result.status_code, 302)

        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertTrue(subscription.is_active)
        result = self.client.post(reverse('content:follow-reactions', args=[self.tuto.pk]), {'follow': 0})
        self.assertEqual(result.status_code, 302)
        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertFalse(subscription.is_active)

    def test_answer_subscription(self):
        """
        When a user posts on a publishable content, the user gets subscribed.
        """
        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertIsNone(subscription)

        result = self.client.post(reverse('content:add-reaction') + '?pk={}'.format(self.tuto.pk), {
            'text': 'message',
            'last_note': '0'
        }, follow=True)
        self.assertEqual(result.status_code, 200)

        subscription = ContentReactionAnswerSubscription.objects.get_existing(user=self.user1, content_object=self.tuto)
        self.assertTrue(subscription.is_active)

    def test_notification_read(self):
        """
        When the notification is a reaction, it is marked as read
        when the corresponding content is displayed to the user.
        """
        ContentReactionFactory(related_content=self.tuto, author=self.user1, position=1)
        last_note = ContentReactionFactory(related_content=self.tuto, author=self.user2, position=2)
        self.tuto.last_note = last_note
        self.tuto.save()

        notification = Notification.objects.get(subscription__user=self.user1)
        self.assertFalse(notification.is_read)

        result = self.client.get(reverse('tutorial:view', args=[self.tuto.pk, self.tuto.slug]), follow=False)
        self.assertEqual(result.status_code, 200)

        notification = Notification.objects.get(subscription__user=self.user1)
        self.assertTrue(notification.is_read)

    def test_subscription_to_new_publications_from_user(self):
        """
        Any user may subscribe to new publications from a user.
        """
        result = self.client.post(reverse('content:follow', args=[self.user1.pk]), follow=False)
        self.assertEqual(result.status_code, 403)

        self.client.logout()
        self.assertTrue(self.client.login(username=self.user2.username, password='hostel77'), True)

#.........这里部分代码省略.........
开发者ID:josephcab,项目名称:zds-site,代码行数:103,代码来源:tests_basics.py

示例14: _create_and_publish_type_in_subcategory

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
 def _create_and_publish_type_in_subcategory(self, content_type, subcategory):
     tuto_1 = PublishableContentFactory(type=content_type, author_list=[self.user_author])
     tuto_1.subcategory.add(subcategory)
     tuto_1.save()
     tuto_1_draft = tuto_1.load_version()
     publish_content(tuto_1, tuto_1_draft, is_major_update=True)
开发者ID:josephcab,项目名称:zds-site,代码行数:8,代码来源:tests_lists.py

示例15: ContentTests

# 需要导入模块: from zds.tutorialv2.factories import PublishableContentFactory [as 别名]
# 或者: from zds.tutorialv2.factories.PublishableContentFactory import load_version [as 别名]
class ContentTests(TutorialTestMixin, TestCase):
    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()
        self.external = UserFactory(
            username=self.overridden_zds_app['member']['external_account'],
            password='anything')

    def test_public_lists(self):
        tutorial = PublishedContentFactory(author_list=[self.user_author])
        tutorial_unpublished = PublishableContentFactory(author_list=[self.user_author])
        article = PublishedContentFactory(author_list=[self.user_author], type='ARTICLE')
        article_unpublished = PublishableContentFactory(author_list=[self.user_author], type='ARTICLE')
        self.client.logout()
        resp = self.client.get(reverse('publication:list') + '?type=tutorial')
        self.assertContains(resp, tutorial.title)
        self.assertNotContains(resp, tutorial_unpublished.title)
        resp = self.client.get(reverse('publication:list') + '?type=article')
        self.assertContains(resp, article.title)
        self.assertNotContains(resp, article_unpublished.title)
        resp = self.client.get(reverse('content:find-tutorial', args=[self.user_author.pk]) + '?filter=public')
        self.assertContains(resp, tutorial.title)
        self.assertNotContains(resp, tutorial_unpublished.title)
        resp = self.client.get(reverse('content:find-tutorial', args=[self.user_author.pk]) + '?filter=redaction')
        self.assertEqual(resp.status_code, 403)
        resp = self.client.get(reverse('content:find-article', args=[self.user_author.pk]) + '?filter=public')
        self.assertContains(resp, article.title)
        self.assertNotContains(resp, article_unpublished.title)
        resp = self.client.get(reverse('content:find-article', args=[self.user_author.pk]) + '?filter=redaction')
        self.assertEqual(resp.status_code, 403)
        resp = self.client.get(reverse('content:find-article', args=[self.user_author.pk]) + '?filter=chuck-norris')
        self.assertEqual(resp.status_code, 404)

    def _create_and_publish_type_in_subcategory(self, content_type, subcategory):
        tuto_1 = PublishableContentFactory(type=content_type, author_list=[self.user_author])
        tuto_1.subcategory.add(subcategory)
        tuto_1.save()
        tuto_1_draft = tuto_1.load_version()
        publish_content(tuto_1, tuto_1_draft, is_major_update=True)

    def test_list_categories(self):
        category_1 = ContentCategoryFactory()
        subcategory_1 = SubCategoryFactory(category=category_1)
        subcategory_2 = SubCategoryFactory(category=category_1)
        # Not in context if nothing published inside this subcategory
        SubCategoryFactory(category=category_1)

        for _ in range(5):
            self._create_and_publish_type_in_subcategory('TUTORIAL', subcategory_1)
            self._create_and_publish_type_in_subcategory('ARTICLE', subcategory_2)

        self.client.logout()
        resp = self.client.get(reverse('publication:list'))

        context_categories = list(resp.context_data['categories'])
        self.assertEqual(context_categories[0].contents_count, 10)
        self.assertEqual(context_categories[0].subcategories, [subcategory_1, subcategory_2])
        self.assertEqual(context_categories, [category_1])

    def test_private_lists(self):
        tutorial = PublishedContentFactory(author_list=[self.user_author])
        tutorial_unpublished = PublishableContentFactory(author_list=[self.user_author])
        article = PublishedContentFactory(author_list=[self.user_author], type='ARTICLE')
        article_unpublished = PublishableContentFactory(author_list=[self.user_author], type='ARTICLE')
        self.client.login(
            username=self.user_author.username,
            password='hostel77')
        resp = self.client.get(reverse('content:find-tutorial', args=[self.user_author.pk]))
        self.assertContains(resp, tutorial.title)
        self.assertContains(resp, tutorial_unpublished.title)
#.........这里部分代码省略.........
开发者ID:josephcab,项目名称:zds-site,代码行数:103,代码来源:tests_lists.py


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