-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_issues.py
317 lines (251 loc) · 16.8 KB
/
test_issues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# -*- coding: utf-8 -*-
# pylint: disable=line-too-long
import os
from PyPDFForm import PdfWrapper
def test_pdf_form_with_pages_without_widgets(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-246.pdf")).fill(
{"QCredit": "5000.63"}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-246-expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_pdf_form_with_central_aligned_text_fields(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-285.pdf")).fill(
{
"name": "Hans Mustermann",
"fulladdress": "Musterstr. 12, 82903 Musterdorf, Musterland",
"advisorname": "Karl Test",
}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-285-expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_pdf_form_with_central_aligned_text_fields_void(issue_pdf_directory):
assert PdfWrapper(os.path.join(issue_pdf_directory, "PPF-285.pdf")).fill({}).read()
def test_pdf_form_with_paragraph_fields_new_line_symbol_text(
issue_pdf_directory, request
):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-415.pdf")).fill(
{"Address": "Mr John Smith\n132, My Street\nKingston, New York 12401"}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-415-expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
if os.name != "nt":
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_pdf_form_with_paragraph_fields_new_line_symbol_text_overflow(
issue_pdf_directory, request
):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-415-2.pdf")).fill(
{
"multiline-text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Malesuada proin libero nunc consequat interdum varius sit amet mattis. Nec tincidunt praesent semper feugiat nibh sed.\nSed libero enim sed faucibus turpis. Cursus in hac habitasse platea dictumst quisque sagittis. Placerat in egestas erat imperdiet sed euismod. Id aliquet risus feugiat in ante metus dictum at. Proin fermentum leo vel orci porta non pulvinar. Consequat semper viverra nam libero justo.\nPellentesque massa placerat duis ultricies lacus sed. Amet est placerat in egestas erat imperdiet sed euismod nisi. Id cursus metus aliquam eleifend mi. Massa massa ultricies mi quis. Volutpat consequat mauris nunc congue nisi vitae suscipit tellus. Ut tellus elementum sagittis vitae.\n\nEtiam sit amet nisl purus in mollis nunc. Vel turpis nunc eget lorem dolor sed. Ultrices dui sapien eget mi proin sed libero enim. Condimentum id venenatis a condimentum vitae sapien pellentesque habitant. Libero volutpat sed cras ornare arcu. Commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula. Nisi est sit amet facilisis magna etiam. In iaculis nunc sed augue.\nSapien pellentesque habitant morbi tristique.\nCondimentum mattis pellentesque id nibh tortor id aliquet. Porttitor massa id neque aliquam vestibulum. Feugiat in fermentum posuere urna nec tincidunt praesent semper. Malesuada fames ac turpis egestas integer. Aenean vel elit scelerisque mauris pellentesque. Vel turpis nunc eget lorem dolor sed viverra. Nec feugiat nisl pretium fusce id velit ut tortor." # noqa
}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-415-2-expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_521(issue_pdf_directory, request):
expected_path = os.path.join(issue_pdf_directory, "521-expected.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(os.path.join(issue_pdf_directory, "521.pdf")).fill(
{
"Text1": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?", # noqa
"Text2": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. NEMO ENIM IPSAM VOLUPTATEM QUIA VOLUPTAS SIT ASPERNATUR AUT ODIT AUT FUGIT, SED QUIA CONSEQUUNTUR MAGNI DOLORES EOS QUI RATIONE VOLUPTATEM SEQUI NESCIUNT. NEQUE PORRO QUISQUAM EST, QUI DOLOREM IPSUM QUIA DOLOR SIT AMET, CONSECTETUR, ADIPISCI VELIT, SED QUIA NON NUMQUAM EIUS MODI TEMPORA INCIDUNT UT LABORE ET DOLORE MAGNAM ALIQUAM QUAERAT VOLUPTATEM. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?", # noqa
"Text3": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?", # noqa
},
)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.stream == expected
def test_pdf_form_with_paragraph_fields_new_line_symbol_short_text(
issue_pdf_directory, request
):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-415.pdf")).fill(
{"Address": "J Smith\n132 A St\nNYC, NY 12401"}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-415-3-expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
if os.name != "nt":
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_encrypted_edit_pdf_form(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "437.pdf"))
obj = obj.fill(obj.sample_data)
expected_path = os.path.join(issue_pdf_directory, "437_expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_fill_image(issue_pdf_directory, image_samples, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "560.pdf"))
obj = obj.fill({"ImageSign": os.path.join(image_samples, "sample_image.jpg")})
expected_path = os.path.join(issue_pdf_directory, "560_expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_reduce_paragraph_overflow_text_font_size(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-620.pdf")).fill(
{
"301 What Happened": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris congue, lorem sit amet venenatis lacinia, quam tortor pharetra ante, id facilisis neque velit ac tellus. Nam tincidunt felis quis eros malesuada, ac congue elit consequat. Ut eget porttitor augue. Integer ullamcorper lectus et est scelerisque, ac posuere mi tempor. Nunc vulputate vehicula bibendum. Aliquam erat volutpat. Morbi tortor." # noqa
}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-620-expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_ppf_627_schema(issue_pdf_directory):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-627.pdf"))
assert obj.schema["properties"]["S1 GF 7"]["maximum"] == 3
def test_ppf_627_fill_0(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-627.pdf")).fill(
{"S1 GF 7": 0}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-627-expected-0.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_ppf_627_fill_1(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-627.pdf")).fill(
{"S1 GF 7": 1}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-627-expected-1.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_ppf_627_fill_2(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-627.pdf")).fill(
{"S1 GF 7": 2}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-627-expected-2.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_ppf_627_fill_3(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "PPF-627.pdf")).fill(
{"S1 GF 7": 3}
)
expected_path = os.path.join(issue_pdf_directory, "PPF-627-expected-3.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_sejda_checkbox(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "683.pdf")).fill(
{"test_checkbox": True}
)
expected_path = os.path.join(issue_pdf_directory, "683_expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.read()) == len(expected)
assert obj.read() == expected
def test_update_key(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "733.pdf"))
for i in range(1, 10):
obj.update_widget_key("Description[0]", f"Description[{i}]", 1)
obj.update_widget_key("symbol[0]", f"symbol[{i}]", 1)
obj.update_widget_key("tradedate[0]", f"tradedate[{i}]", 1)
obj.update_widget_key("settlementdate[0]", f"settlementdate[{i}]", 1)
obj.update_widget_key("quantity[0]", f"quantity[{i}]", 1)
obj.update_widget_key("costperunit[0]", f"costperunit[{i}]", 1)
obj.update_widget_key("costabasis[0]", f"costabasis[{i}]", 1)
expected_path = os.path.join(issue_pdf_directory, "733_expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.preview
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.preview) == len(expected)
assert obj.preview == expected
def test_update_key_persist_properties(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "733.pdf"))
obj.widgets["SchwabAccountNumber[0]"].font_size = 20
for i in range(1, 10):
obj.update_widget_key("Description[0]", f"Description[{i}]", 1)
obj.update_widget_key("symbol[0]", f"symbol[{i}]", 1)
obj.update_widget_key("tradedate[0]", f"tradedate[{i}]", 1)
obj.update_widget_key("settlementdate[0]", f"settlementdate[{i}]", 1)
obj.update_widget_key("quantity[0]", f"quantity[{i}]", 1)
obj.update_widget_key("costperunit[0]", f"costperunit[{i}]", 1)
obj.update_widget_key("costabasis[0]", f"costabasis[{i}]", 1)
assert obj.widgets["SchwabAccountNumber[0]"].font_size == 20
expected_path = os.path.join(issue_pdf_directory, "733_expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.preview
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.preview) == len(expected)
assert obj.preview == expected
def test_bulk_update_key(issue_pdf_directory, request):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "733.pdf"))
for i in range(1, 10):
obj.update_widget_key("Description[0]", f"Description[{i}]", 1, defer=True)
obj.update_widget_key("symbol[0]", f"symbol[{i}]", 1, defer=True)
obj.update_widget_key("tradedate[0]", f"tradedate[{i}]", 1, defer=True)
obj.update_widget_key(
"settlementdate[0]", f"settlementdate[{i}]", 1, defer=True
)
obj.update_widget_key("quantity[0]", f"quantity[{i}]", 1, defer=True)
obj.update_widget_key("costperunit[0]", f"costperunit[{i}]", 1, defer=True)
obj.update_widget_key("costabasis[0]", f"costabasis[{i}]", 1, defer=True)
obj.commit_widget_key_updates()
expected_path = os.path.join(issue_pdf_directory, "733_expected.pdf")
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.preview
with open(expected_path, "rb+") as f:
expected = f.read()
assert len(obj.preview) == len(expected)
assert obj.preview == expected
def test_get_desc_in_schema(issue_pdf_directory):
obj = PdfWrapper(os.path.join(issue_pdf_directory, "757.pdf"))
assert (
obj.schema["properties"]["P1_checkbox4[0]"]["description"]
== "Part 1. Information About You. Your Full Name. 4. Has your name legally changed since the issuance of your Permanent Resident Card? Select Yes. (Proceed to Item Numbers 5. A. through 5. C.)."
) # noqa
assert (
obj.schema["properties"]["P1_checkbox4[1]"]["description"]
== "Part 1. Information About You. Your Full Name. 4. Has your name legally changed since the issuance of your Permanent Resident Card? Select No (Proceed to Item Numbers 6. A. through 6. I.)."
) # noqa
assert (
obj.schema["properties"]["P1_checkbox4[2]"]["description"]
== "Part 1. Information About You. Your Full Name. 4. Has your name legally changed since the issuance of your Permanent Resident Card? Select Not Applicable - I never received my previous card. (Proceed to Item Numbers 6. A. through 6. I.)."
) # noqa