-
Notifications
You must be signed in to change notification settings - Fork 18
/
test_functional_simple.py
153 lines (116 loc) · 4.87 KB
/
test_functional_simple.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
# -*- coding: utf-8 -*-
import os
from PyPDFForm import FormWrapper
def test_fill(template_stream, pdf_samples, data_dict, request):
expected_path = os.path.join(pdf_samples, "simple", "sample_filled.pdf")
with open(expected_path, "rb+") as f:
obj = FormWrapper(template_stream).fill(data_dict)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
expected = f.read()
assert len(obj.stream) == len(expected)
assert obj.stream == expected
def test_fill_radiobutton(pdf_samples, template_with_radiobutton_stream, request):
expected_path = os.path.join(pdf_samples, "simple", "sample_filled_radiobutton.pdf")
with open(expected_path, "rb+") as f:
obj = FormWrapper(template_with_radiobutton_stream).fill(
{
"radio_1": 0,
"radio_2": 1,
"radio_3": 2,
},
)
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_fill_sejda_and_read(pdf_samples, sejda_template, sejda_data, request):
expected_path = os.path.join(pdf_samples, "simple", "sample_filled_sejda.pdf")
with open(expected_path, "rb+") as f:
obj = FormWrapper(sejda_template).fill(sejda_data)
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_fill_right_aligned(
sample_template_with_right_aligned_text_field, pdf_samples, request
):
expected_path = os.path.join(
pdf_samples, "simple", "sample_filled_right_aligned.pdf"
)
with open(expected_path, "rb+") as f:
obj = FormWrapper(sample_template_with_right_aligned_text_field).fill(
{
"name": "Hans Mustermann",
"fulladdress": "Musterstr. 12, 82903 Musterdorf, Musterland",
"advisorname": "Karl Test",
},
)
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_fill_font_color(sample_template_with_font_colors, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "simple", "test_fill_font_color.pdf")
with open(expected_path, "rb+") as f:
obj = FormWrapper(sample_template_with_font_colors).fill(
{
"red_12": "red",
"green_14": "green",
"blue_16": "blue",
"mixed_auto": "mixed",
},
)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
expected = f.read()
if os.name != "nt":
assert len(obj.read()) == len(expected)
assert obj.stream == expected
def test_fill_complex_fonts(sample_template_with_complex_fonts, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "simple", "test_fill_complex_fonts.pdf")
with open(expected_path, "rb+") as f:
obj = FormWrapper(sample_template_with_complex_fonts).fill(
{
"Courier": "Test",
"Courier-Bold": "Test",
"Courier-BoldOblique": "Test",
"Courier-Oblique": "Test",
"Helvetica": "Test",
"Helvetica-Bold": "Test",
"Helvetica-BoldOblique": "Test",
"Helvetica-Oblique": "Test",
"Times-Bold": "Test",
"Times-BoldItalic": "Test",
"Times-Italic": "Test",
"Times-Roman": "Test",
},
)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
expected = f.read()
if os.name != "nt":
assert len(obj.read()) == len(expected)
assert obj.stream == expected
def test_undo_checkbox(pdf_samples, request):
expected_path = os.path.join(
pdf_samples, "simple", "undo", "test_undo_checkbox.pdf"
)
with open(expected_path, "rb+") as f:
obj = FormWrapper(
os.path.join(pdf_samples, "simple", "undo", "sample_template_filled.pdf")
).fill(
{
"check": False,
"check_2": False,
"check_3": False,
},
)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
expected = f.read()
assert len(obj.stream) == len(expected)
assert obj.stream == expected