Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ dist/**
# IDE related
.vscode/**
~*
.codex
8 changes: 8 additions & 0 deletions docassemble/AssemblyLine/al_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ def as_pdf(

if isinstance(main_doc, DAFileCollection):
main_doc = main_doc.pdf
if isinstance(main_doc, DAFile):
main_doc.title = self.title
main_doc.filename = filename
try:
Expand Down Expand Up @@ -1730,7 +1731,14 @@ def as_pdf(
pdfa=pdfa,
append_matching_suffix=append_matching_suffix,
)
bundle_filename = f"{base_name(self.filename)}{append_suffix}.pdf"
pdf.title = self.title
pdf.filename = bundle_filename
try:
pdf.set_attributes(filename=bundle_filename)
pdf.set_mimetype("application/pdf")
except:
pass
else:
pdf = pdf_concatenate(
[document.as_pdf(key=key, refresh=refresh) for document in files],
Expand Down
69 changes: 69 additions & 0 deletions docassemble/AssemblyLine/test_al_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,75 @@ def test_upload_pdf(self):
pass


class FakePdf(DAFile):
def __init__(self, filename="file.pdf", title="child"):
self.instanceName = "fake_pdf"
self.has_nonrandom_instance_name = True
self.filename = filename
self.title = title
self.attribute_filenames = []
self.mimetype = None

def set_attributes(self, **kwargs):
if "filename" in kwargs:
self.attribute_filenames.append(kwargs["filename"])

def set_mimetype(self, mimetype):
self.mimetype = mimetype


class FakeSingleDoc:
def __init__(self, pdf):
self._pdf = pdf

def is_enabled(self, refresh=True):
return True

def as_pdf(self, **kwargs):
return self._pdf


class TestSingleDocumentBundleFilename(unittest.TestCase):
def test_bundle_as_pdf_renames_single_document_to_bundle_filename(self):
child_pdf = FakePdf()
bundle = ALDocumentBundle(
"bundle",
elements=[FakeSingleDoc(child_pdf)],
title="Bundle title",
filename="bundle-output.pdf",
enabled=True,
)

result = bundle.as_pdf()

self.assertIs(result, child_pdf)
self.assertEqual(result.title, "Bundle title")
self.assertEqual(result.filename, "bundle-output.pdf")
self.assertEqual(result.attribute_filenames, ["bundle-output.pdf"])
self.assertEqual(result.mimetype, "application/pdf")


class TestSingleDocumentFilename(unittest.TestCase):
def test_document_as_pdf_renames_plain_dafile_to_document_filename(self):
child_pdf = FakePdf()
doc = ALDocument(
"doc",
title="Document title",
filename="document-output.pdf",
enabled=True,
has_addendum=False,
)
doc["final"] = child_pdf

result = doc.as_pdf(refresh=False)

self.assertIs(result, child_pdf)
self.assertEqual(result.title, "Document title")
self.assertEqual(result.filename, "document-output.pdf")
self.assertEqual(result.attribute_filenames, ["document-output.pdf"])
self.assertEqual(result.mimetype, "application/pdf")


class test_aladdendum(unittest.TestCase):
def test_safe_value(self):
text_testcase1 = """Charged by my father with a very delicate mission, I repaired, towards the end of May, 1788, to the château of Ionis, situated a dozen leagues distant, in the lands lying between Angers and Saumur. I was twenty-two, and already practising the profession of lawyer, for which I experienced but slight inclination, although neither the study of business nor of argument had presented serious difficulties to me. Taking my youth into consideration, I was not esteemed without talent, and the standing of my father, a lawyer renowned in the locality, assured me a brilliant patronage in the future, in return for any paltry efforts I might make to be worthy of replacing him. But I would have preferred literature, a more dreamy life, a more independent and more individual use of my faculties, a responsibility less submissive to the passions and interests of others. As my family was well off, and I an only son, greatly spoiled and petted, I might have chosen my own career, but I would have thus afflicted my father, who took pride in his ability to direct me 4in the road which he had cleared in advance, and I loved him too tenderly to permit my instinct to outweigh his wishes.
Expand Down
Loading