Skip to content

Commit

Permalink
(Export PDF) Ajoute un test pour s'assurer que seules les parties rea…
Browse files Browse the repository at this point in the history
…dy_to_publish sont exportées
  • Loading branch information
philippemilink committed Mar 27, 2022
1 parent e2b2b52 commit 19188e8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion zds/tutorialv2/tests/tests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from zds.tutorialv2.publication_utils import publish_content, unpublish_content
from zds.tutorialv2.models.database import PublishableContent, PublishedContent, ContentReaction, ContentRead
from django.core.management import call_command
from zds.tutorialv2.publication_utils import Publicator, PublicatorRegistry
from zds.tutorialv2.publication_utils import Publicator, PublicatorRegistry, ZMarkdownRebberLatexPublicator
from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents
from zds import json_handler
from zds.utils.tests.factories import LicenceFactory
Expand Down Expand Up @@ -263,6 +263,13 @@ def test_export_only_ready_to_publish(self):
"""
Test exported contents contain only ready_to_publish==True parts.
"""

# We need to produce at least the .tex file, so use the real PDF publicator:
previous_pdf_publicator = PublicatorRegistry.get("pdf")
previous_build_pdf_when_published = self.overridden_zds_app["content"]["build_pdf_when_published"]
PublicatorRegistry.registry["pdf"] = ZMarkdownRebberLatexPublicator(".pdf")
self.overridden_zds_app["content"]["build_pdf_when_published"] = True

# Medium-size tutorial
midsize_tuto = PublishableContentFactory(type="TUTORIAL")

Expand Down Expand Up @@ -299,13 +306,31 @@ def test_export_only_ready_to_publish(self):
self.assertIsNone(child.introduction)
self.assertIsNone(child.conclusion)

# Test Markdown content:
self.assertTrue(published.has_md())
with Path(published.get_extra_contents_directory(), published.content_public_slug + ".md").open("r") as md:
content = md.read()
self.assertIn(chapter1.title, content)
self.assertIn(chapter2.title, content)
self.assertNotIn(chapter3.title, content)

# TODO: factorize getting texfile path with what is done in zds.tutorialv2.publication_utils.publish():
tmp_path = os.path.join(
settings.ZDS_APP["content"]["repo_public_path"], published.content_public_slug + "__building"
)
build_extra_contents_path = os.path.join(tmp_path, settings.ZDS_APP["content"]["extra_contents_dirname"])
base_name = os.path.join(build_extra_contents_path, published.content_public_slug)
tex_file = base_name + ".tex"
# PDF generation may fail, only test the tex content:
with open(tex_file) as tex:
content = tex.read()
self.assertIn(chapter1.title, content)
self.assertIn(chapter2.title, content)
self.assertNotIn(chapter3.title, content)

PublicatorRegistry.registry["pdf"] = previous_pdf_publicator
self.overridden_zds_app["content"]["build_pdf_when_published"] = previous_build_pdf_when_published

def test_tagged_tree_extract(self):
midsize = PublishableContentFactory(author_list=[self.user_author])
midsize_draft = midsize.load_version()
Expand Down

0 comments on commit 19188e8

Please sign in to comment.