PyPDFForm 1.4.30__tar.gz → 1.4.32__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of PyPDFForm might be problematic. Click here for more details.
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PKG-INFO +1 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/__init__.py +3 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/adapter.py +3 -4
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/font.py +2 -2
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/base.py +1 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/checkbox.py +1 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/dropdown.py +1 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/text.py +1 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/patterns.py +9 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/template.py +6 -6
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/utils.py +8 -8
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/watermark.py +5 -8
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/widgets/base.py +39 -6
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/widgets/text.py +1 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/wrapper.py +10 -6
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm.egg-info/PKG-INFO +1 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/setup.py +3 -1
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_create_widget.py +44 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_functional.py +7 -7
- {pypdfform-1.4.30 → pypdfform-1.4.32}/LICENSE +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/constants.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/coordinate.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/filler.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/image.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/__init__.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/image.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/radio.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/middleware/signature.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/widgets/__init__.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/widgets/checkbox.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm/widgets/dropdown.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm.egg-info/SOURCES.txt +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm.egg-info/dependency_links.txt +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm.egg-info/requires.txt +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/PyPDFForm.egg-info/top_level.txt +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/README.md +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/setup.cfg +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_adobe_mode.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_dropdown.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_dropdown_simple.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_fill_max_length_text_field.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_fill_max_length_text_field_simple.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_functional_simple.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_paragraph.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_paragraph_simple.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_preview.py +0 -0
- {pypdfform-1.4.30 → pypdfform-1.4.32}/tests/test_signature.py +0 -0
|
@@ -13,10 +13,10 @@ def readable(obj: Any) -> bool:
|
|
|
13
13
|
|
|
14
14
|
def fp_or_f_obj_or_stream_to_stream(
|
|
15
15
|
fp_or_f_obj_or_stream: Union[bytes, str, BinaryIO]
|
|
16
|
-
) ->
|
|
16
|
+
) -> bytes:
|
|
17
17
|
"""Converts a file path or a file object to a stream."""
|
|
18
18
|
|
|
19
|
-
result =
|
|
19
|
+
result = b""
|
|
20
20
|
if isinstance(fp_or_f_obj_or_stream, bytes):
|
|
21
21
|
result = fp_or_f_obj_or_stream
|
|
22
22
|
|
|
@@ -25,8 +25,7 @@ def fp_or_f_obj_or_stream_to_stream(
|
|
|
25
25
|
|
|
26
26
|
elif isinstance(fp_or_f_obj_or_stream, str):
|
|
27
27
|
if not isfile(fp_or_f_obj_or_stream):
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
pass
|
|
30
29
|
else:
|
|
31
30
|
with open(fp_or_f_obj_or_stream, "rb+") as _file:
|
|
32
31
|
result = _file.read()
|
|
@@ -42,9 +42,9 @@ def extract_font_from_text_appearance(text_appearance: str) -> Union[str, None]:
|
|
|
42
42
|
appearance string of a text field widget.
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
text_appearances = text_appearance.split(" ")
|
|
46
46
|
|
|
47
|
-
for each in
|
|
47
|
+
for each in text_appearances:
|
|
48
48
|
if each.startswith("/"):
|
|
49
49
|
text_segments = findall("[A-Z][^A-Z]*", each.replace("/", ""))
|
|
50
50
|
|
|
@@ -158,3 +158,12 @@ def simple_flatten_generic(annot: DictionaryObject) -> None:
|
|
|
158
158
|
annot[NameObject(Ff)] = NumberObject(
|
|
159
159
|
int(annot.get(NameObject(Ff), 0)) | READ_ONLY # noqa
|
|
160
160
|
)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def update_created_text_field_alignment(annot: DictionaryObject, val: int) -> None:
|
|
164
|
+
"""Patterns to update text alignment for text annotations created by the library."""
|
|
165
|
+
|
|
166
|
+
annot[NameObject(Q)] = NumberObject(val)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
NON_ACRO_FORM_PARAM_TO_FUNC = {"alignment": update_created_text_field_alignment}
|
|
@@ -118,7 +118,7 @@ def update_text_field_attributes(
|
|
|
118
118
|
) -> None:
|
|
119
119
|
"""Auto updates text fields' attributes."""
|
|
120
120
|
|
|
121
|
-
for
|
|
121
|
+
for _widgets in get_widgets_by_page(template_stream).values():
|
|
122
122
|
for _widget in _widgets:
|
|
123
123
|
key = get_widget_key(_widget)
|
|
124
124
|
|
|
@@ -155,11 +155,11 @@ def update_text_field_attributes(
|
|
|
155
155
|
def get_widgets_by_page(pdf: bytes) -> Dict[int, List[dict]]:
|
|
156
156
|
"""Iterates through a PDF and returns all widgets found grouped by page."""
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
159
159
|
|
|
160
160
|
result = {}
|
|
161
161
|
|
|
162
|
-
for i, page in enumerate(
|
|
162
|
+
for i, page in enumerate(pdf_file.pages):
|
|
163
163
|
widgets = page.annotations
|
|
164
164
|
result[i + 1] = []
|
|
165
165
|
if widgets:
|
|
@@ -177,7 +177,7 @@ def get_widgets_by_page(pdf: bytes) -> Dict[int, List[dict]]:
|
|
|
177
177
|
return result
|
|
178
178
|
|
|
179
179
|
|
|
180
|
-
def get_widget_key(widget: dict) -> Union[str, None]:
|
|
180
|
+
def get_widget_key(widget: dict) -> Union[str, list, None]:
|
|
181
181
|
"""Finds a PDF widget's annotated key by pattern matching."""
|
|
182
182
|
|
|
183
183
|
result = None
|
|
@@ -189,7 +189,7 @@ def get_widget_key(widget: dict) -> Union[str, None]:
|
|
|
189
189
|
return result
|
|
190
190
|
|
|
191
191
|
|
|
192
|
-
def get_widget_alignment(widget: dict) -> Union[str, None]:
|
|
192
|
+
def get_widget_alignment(widget: dict) -> Union[str, list, None]:
|
|
193
193
|
"""Finds a PDF widget's alignment by pattern matching."""
|
|
194
194
|
|
|
195
195
|
result = None
|
|
@@ -249,7 +249,7 @@ def is_text_multiline(widget: dict) -> bool:
|
|
|
249
249
|
return check_field_flag_bit(widget, MULTILINE)
|
|
250
250
|
|
|
251
251
|
|
|
252
|
-
def get_dropdown_choices(widget: dict) -> Union[Tuple[str], None]:
|
|
252
|
+
def get_dropdown_choices(widget: dict) -> Union[Tuple[str, ...], None]:
|
|
253
253
|
"""Returns string options of a dropdown field."""
|
|
254
254
|
|
|
255
255
|
result = None
|
|
@@ -62,10 +62,10 @@ def preview_widget_to_draw(widget: WIDGET_TYPES) -> Text:
|
|
|
62
62
|
def remove_all_widgets(pdf: bytes) -> bytes:
|
|
63
63
|
"""Removes all widgets from a PDF form."""
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
66
66
|
result_stream = BytesIO()
|
|
67
67
|
writer = PdfWriter()
|
|
68
|
-
for page in
|
|
68
|
+
for page in pdf_file.pages:
|
|
69
69
|
if page.annotations:
|
|
70
70
|
page.annotations.clear()
|
|
71
71
|
writer.add_page(page)
|
|
@@ -78,10 +78,10 @@ def remove_all_widgets(pdf: bytes) -> bytes:
|
|
|
78
78
|
def get_page_streams(pdf: bytes) -> List[bytes]:
|
|
79
79
|
"""Returns a list of streams where each is a page of the input PDF."""
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
82
82
|
result = []
|
|
83
83
|
|
|
84
|
-
for page in
|
|
84
|
+
for page in pdf_file.pages:
|
|
85
85
|
writer = PdfWriter()
|
|
86
86
|
writer.add_page(page)
|
|
87
87
|
with BytesIO() as f:
|
|
@@ -96,13 +96,13 @@ def merge_two_pdfs(pdf: bytes, other: bytes) -> bytes:
|
|
|
96
96
|
"""Merges two PDFs into one PDF."""
|
|
97
97
|
|
|
98
98
|
output = PdfWriter()
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
100
|
+
other_file = PdfReader(stream_to_io(other))
|
|
101
101
|
result = BytesIO()
|
|
102
102
|
|
|
103
|
-
for page in
|
|
103
|
+
for page in pdf_file.pages:
|
|
104
104
|
output.add_page(page)
|
|
105
|
-
for page in
|
|
105
|
+
for page in other_file.pages:
|
|
106
106
|
output.add_page(page)
|
|
107
107
|
|
|
108
108
|
output.write(result)
|
|
@@ -165,12 +165,9 @@ def create_watermarks_and_draw(
|
|
|
165
165
|
watermark = buff.read()
|
|
166
166
|
buff.close()
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
results.append(watermark if i == page_number - 1 else b"")
|
|
172
|
-
|
|
173
|
-
return results
|
|
168
|
+
return [
|
|
169
|
+
watermark if i == page_number - 1 else b"" for i in range(len(pdf_file.pages))
|
|
170
|
+
]
|
|
174
171
|
|
|
175
172
|
|
|
176
173
|
def merge_watermarks_with_pdf(
|
|
@@ -180,10 +177,10 @@ def merge_watermarks_with_pdf(
|
|
|
180
177
|
"""Merges watermarks with PDF."""
|
|
181
178
|
|
|
182
179
|
result = BytesIO()
|
|
183
|
-
|
|
180
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
184
181
|
output = PdfWriter()
|
|
185
182
|
|
|
186
|
-
for i, page in enumerate(
|
|
183
|
+
for i, page in enumerate(pdf_file.pages):
|
|
187
184
|
if watermarks[i]:
|
|
188
185
|
watermark = PdfReader(stream_to_io(watermarks[i]))
|
|
189
186
|
if watermark.pages:
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
"""Contains base class for all widgets to create."""
|
|
3
3
|
|
|
4
4
|
from io import BytesIO
|
|
5
|
-
from typing import List
|
|
5
|
+
from typing import List, cast
|
|
6
6
|
|
|
7
|
-
from pypdf import PdfReader
|
|
7
|
+
from pypdf import PdfReader, PdfWriter
|
|
8
|
+
from pypdf.generic import DictionaryObject
|
|
8
9
|
from reportlab.lib.colors import Color
|
|
9
10
|
from reportlab.pdfgen.canvas import Canvas
|
|
10
11
|
|
|
12
|
+
from ..constants import Annots
|
|
13
|
+
from ..patterns import NON_ACRO_FORM_PARAM_TO_FUNC
|
|
14
|
+
from ..template import get_widget_key
|
|
11
15
|
from ..utils import stream_to_io
|
|
12
16
|
|
|
13
17
|
|
|
@@ -16,6 +20,7 @@ class Widget:
|
|
|
16
20
|
|
|
17
21
|
USER_PARAMS = []
|
|
18
22
|
COLOR_PARAMS = []
|
|
23
|
+
ALLOWED_NON_ACRO_FORM_PARAMS = []
|
|
19
24
|
NONE_DEFAULTS = []
|
|
20
25
|
ACRO_FORM_FUNC = ""
|
|
21
26
|
|
|
@@ -29,12 +34,14 @@ class Widget:
|
|
|
29
34
|
) -> None:
|
|
30
35
|
"""Sets acro form parameters."""
|
|
31
36
|
|
|
37
|
+
super().__init__()
|
|
32
38
|
self.page_number = page_number
|
|
33
39
|
self.acro_form_params = {
|
|
34
40
|
"name": name,
|
|
35
41
|
"x": x,
|
|
36
42
|
"y": y,
|
|
37
43
|
}
|
|
44
|
+
self.non_acro_form_params = []
|
|
38
45
|
|
|
39
46
|
for each in self.USER_PARAMS:
|
|
40
47
|
user_input, param = each
|
|
@@ -50,6 +57,10 @@ class Widget:
|
|
|
50
57
|
elif user_input in self.NONE_DEFAULTS:
|
|
51
58
|
self.acro_form_params[param] = None
|
|
52
59
|
|
|
60
|
+
for each in self.ALLOWED_NON_ACRO_FORM_PARAMS:
|
|
61
|
+
if each in kwargs:
|
|
62
|
+
self.non_acro_form_params.append((each, kwargs.get(each)))
|
|
63
|
+
|
|
53
64
|
def watermarks(self, stream: bytes) -> List[bytes]:
|
|
54
65
|
"""Returns a list of watermarks after creating the widget."""
|
|
55
66
|
|
|
@@ -71,8 +82,30 @@ class Widget:
|
|
|
71
82
|
canvas.save()
|
|
72
83
|
watermark.seek(0)
|
|
73
84
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
return [
|
|
86
|
+
watermark.read() if i == self.page_number - 1 else b""
|
|
87
|
+
for i in range(page_count)
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def handle_non_acro_form_params(pdf: bytes, key: str, params: list) -> bytes:
|
|
92
|
+
"""Handles non acro form parameters when creating a widget."""
|
|
93
|
+
|
|
94
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
95
|
+
out = PdfWriter()
|
|
96
|
+
out.append(pdf_file)
|
|
97
|
+
|
|
98
|
+
for page in out.pages:
|
|
99
|
+
for annot in page.get(Annots, []): # noqa
|
|
100
|
+
annot = cast(DictionaryObject, annot.get_object())
|
|
101
|
+
_key = get_widget_key(annot.get_object())
|
|
102
|
+
|
|
103
|
+
if _key == key:
|
|
104
|
+
for param in params:
|
|
105
|
+
if param[0] in NON_ACRO_FORM_PARAM_TO_FUNC:
|
|
106
|
+
NON_ACRO_FORM_PARAM_TO_FUNC[param[0]](annot, param[1])
|
|
77
107
|
|
|
78
|
-
|
|
108
|
+
with BytesIO() as f:
|
|
109
|
+
out.write(f)
|
|
110
|
+
f.seek(0)
|
|
111
|
+
return f.read()
|
|
@@ -22,6 +22,7 @@ from .template import (build_widgets, dropdown_to_text,
|
|
|
22
22
|
from .utils import (get_page_streams, merge_two_pdfs, preview_widget_to_draw,
|
|
23
23
|
remove_all_widgets)
|
|
24
24
|
from .watermark import create_watermarks_and_draw, merge_watermarks_with_pdf
|
|
25
|
+
from .widgets.base import handle_non_acro_form_params
|
|
25
26
|
from .widgets.checkbox import CheckBoxWidget
|
|
26
27
|
from .widgets.dropdown import DropdownWidget
|
|
27
28
|
from .widgets.text import TextWidget
|
|
@@ -36,6 +37,7 @@ class FormWrapper:
|
|
|
36
37
|
) -> None:
|
|
37
38
|
"""Constructs all attributes for the object."""
|
|
38
39
|
|
|
40
|
+
super().__init__()
|
|
39
41
|
self.stream = fp_or_f_obj_or_stream_to_stream(template)
|
|
40
42
|
|
|
41
43
|
def read(self) -> bytes:
|
|
@@ -212,11 +214,15 @@ class PdfWrapper(FormWrapper):
|
|
|
212
214
|
if _class is None:
|
|
213
215
|
return self
|
|
214
216
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
).watermarks(self.read())
|
|
217
|
+
obj = _class(name=name, page_number=page_number, x=x, y=y, **kwargs)
|
|
218
|
+
watermarks = obj.watermarks(self.read())
|
|
218
219
|
|
|
219
220
|
self.stream = merge_watermarks_with_pdf(self.read(), watermarks)
|
|
221
|
+
if obj.non_acro_form_params:
|
|
222
|
+
self.stream = handle_non_acro_form_params(
|
|
223
|
+
self.stream, name, obj.non_acro_form_params
|
|
224
|
+
)
|
|
225
|
+
|
|
220
226
|
new_widgets = build_widgets(self.read())
|
|
221
227
|
for k, v in self.widgets.items():
|
|
222
228
|
if k in new_widgets:
|
|
@@ -292,15 +298,13 @@ class PdfWrapper(FormWrapper):
|
|
|
292
298
|
def schema(self) -> dict:
|
|
293
299
|
"""Generates a json schema for the PDF form template."""
|
|
294
300
|
|
|
295
|
-
|
|
301
|
+
return {
|
|
296
302
|
"type": "object",
|
|
297
303
|
"properties": {
|
|
298
304
|
key: value.schema_definition for key, value in self.widgets.items()
|
|
299
305
|
},
|
|
300
306
|
}
|
|
301
307
|
|
|
302
|
-
return result
|
|
303
|
-
|
|
304
308
|
@classmethod
|
|
305
309
|
def register_font(
|
|
306
310
|
cls, font_name: str, ttf_file: Union[bytes, str, BinaryIO]
|
|
@@ -6,7 +6,9 @@ import re
|
|
|
6
6
|
import setuptools
|
|
7
7
|
|
|
8
8
|
with open("PyPDFForm/__init__.py", encoding="utf8") as f:
|
|
9
|
-
version = re.search(r'__version__ = "(.*?)"', f.read())
|
|
9
|
+
version = re.search(r'__version__ = "(.*?)"', f.read())
|
|
10
|
+
if version:
|
|
11
|
+
version = version.group(1)
|
|
10
12
|
|
|
11
13
|
with open("README.md", mode="r", encoding="utf-8") as fh:
|
|
12
14
|
long_description = fh.read()
|
|
@@ -198,6 +198,50 @@ def test_create_text_default(template_stream, pdf_samples, request):
|
|
|
198
198
|
assert obj.stream == expected
|
|
199
199
|
|
|
200
200
|
|
|
201
|
+
def test_create_text_align_center(template_stream, pdf_samples, request):
|
|
202
|
+
expected_path = os.path.join(pdf_samples, "widget", "create_text_align_center.pdf")
|
|
203
|
+
with open(expected_path, "rb+") as f:
|
|
204
|
+
obj = PdfWrapper(template_stream).create_widget(
|
|
205
|
+
"text",
|
|
206
|
+
"foo",
|
|
207
|
+
1,
|
|
208
|
+
100,
|
|
209
|
+
100,
|
|
210
|
+
alignment=1,
|
|
211
|
+
)
|
|
212
|
+
assert obj.schema["properties"]["foo"]["type"] == "string"
|
|
213
|
+
|
|
214
|
+
request.config.results["expected_path"] = expected_path
|
|
215
|
+
request.config.results["stream"] = obj.read()
|
|
216
|
+
|
|
217
|
+
expected = f.read()
|
|
218
|
+
|
|
219
|
+
assert len(obj.stream) == len(expected)
|
|
220
|
+
assert obj.stream == expected
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def test_create_text_align_right(template_stream, pdf_samples, request):
|
|
224
|
+
expected_path = os.path.join(pdf_samples, "widget", "create_text_align_right.pdf")
|
|
225
|
+
with open(expected_path, "rb+") as f:
|
|
226
|
+
obj = PdfWrapper(template_stream).create_widget(
|
|
227
|
+
"text",
|
|
228
|
+
"foo",
|
|
229
|
+
1,
|
|
230
|
+
100,
|
|
231
|
+
100,
|
|
232
|
+
alignment=2,
|
|
233
|
+
)
|
|
234
|
+
assert obj.schema["properties"]["foo"]["type"] == "string"
|
|
235
|
+
|
|
236
|
+
request.config.results["expected_path"] = expected_path
|
|
237
|
+
request.config.results["stream"] = obj.read()
|
|
238
|
+
|
|
239
|
+
expected = f.read()
|
|
240
|
+
|
|
241
|
+
assert len(obj.stream) == len(expected)
|
|
242
|
+
assert obj.stream == expected
|
|
243
|
+
|
|
244
|
+
|
|
201
245
|
def test_create_text_default_filled(template_stream, pdf_samples, request):
|
|
202
246
|
expected_path = os.path.join(
|
|
203
247
|
pdf_samples, "widget", "create_text_default_filled.pdf"
|
|
@@ -12,7 +12,7 @@ from PyPDFForm.middleware.text import Text
|
|
|
12
12
|
def test_base_schema_definition():
|
|
13
13
|
try:
|
|
14
14
|
assert Widget("foo").schema_definition
|
|
15
|
-
|
|
15
|
+
raise AssertionError
|
|
16
16
|
except NotImplementedError:
|
|
17
17
|
pass
|
|
18
18
|
|
|
@@ -34,7 +34,7 @@ def test_fill(template_stream, pdf_samples, data_dict, request):
|
|
|
34
34
|
assert len(obj.stream) == len(expected)
|
|
35
35
|
assert obj.stream == expected
|
|
36
36
|
|
|
37
|
-
for
|
|
37
|
+
for widgets in template.get_widgets_by_page(obj.read()).values():
|
|
38
38
|
assert not widgets
|
|
39
39
|
|
|
40
40
|
|
|
@@ -375,7 +375,7 @@ def test_schema(sample_template_with_comb_text_field):
|
|
|
375
375
|
data["LastName"] = "XXXXXXXX"
|
|
376
376
|
try:
|
|
377
377
|
validate(instance=data, schema=schema)
|
|
378
|
-
|
|
378
|
+
raise AssertionError
|
|
379
379
|
except ValidationError:
|
|
380
380
|
pass
|
|
381
381
|
|
|
@@ -386,7 +386,7 @@ def test_schema(sample_template_with_comb_text_field):
|
|
|
386
386
|
data["Gender"] = 2
|
|
387
387
|
try:
|
|
388
388
|
validate(instance=data, schema=schema)
|
|
389
|
-
|
|
389
|
+
raise AssertionError
|
|
390
390
|
except ValidationError:
|
|
391
391
|
pass
|
|
392
392
|
|
|
@@ -396,12 +396,12 @@ def test_sample_data(sejda_template_complex):
|
|
|
396
396
|
try:
|
|
397
397
|
validate(instance=obj.sample_data, schema=obj.schema)
|
|
398
398
|
except ValidationError:
|
|
399
|
-
|
|
399
|
+
raise AssertionError from ValidationError
|
|
400
400
|
|
|
401
401
|
widget = Widget("foo")
|
|
402
402
|
try:
|
|
403
403
|
widget.sample_value()
|
|
404
|
-
|
|
404
|
+
raise AssertionError
|
|
405
405
|
except NotImplementedError:
|
|
406
406
|
pass
|
|
407
407
|
|
|
@@ -429,7 +429,7 @@ def test_fill_right_aligned(
|
|
|
429
429
|
assert len(obj.stream) == len(expected)
|
|
430
430
|
assert obj.stream == expected
|
|
431
431
|
|
|
432
|
-
for
|
|
432
|
+
for widgets in template.get_widgets_by_page(obj.read()).values():
|
|
433
433
|
assert not widgets
|
|
434
434
|
|
|
435
435
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|