forked from chinapandaman/PyPDFForm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dropdown.py
181 lines (143 loc) · 5.28 KB
/
test_dropdown.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
# -*- coding: utf-8 -*-
import os
from PyPDFForm import PdfWrapper
def test_schema(sample_template_with_dropdown):
obj = PdfWrapper(sample_template_with_dropdown)
for key, value in obj.schema["properties"].items():
if key == "dropdown_1":
assert value["maximum"] == 3
assert obj.sample_data["dropdown_1"] == 3
def test_dropdown_not_specified(sample_template_with_dropdown):
assert (
PdfWrapper(sample_template_with_dropdown)
.fill(
{
"test_1": "test_1",
"test_2": "test_2",
"test_3": "test_3",
"check_1": True,
"check_2": True,
"check_3": True,
"radio_1": 1,
}
)
.read()
)
def test_dropdown_one(sample_template_with_dropdown, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "dropdown", "dropdown_one.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(sample_template_with_dropdown).fill(
{
"test_1": "test_1",
"test_2": "test_2",
"test_3": "test_3",
"check_1": True,
"check_2": True,
"check_3": True,
"radio_1": 1,
"dropdown_1": 0,
},
)
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_dropdown_two(sample_template_with_dropdown, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "dropdown", "dropdown_two.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(sample_template_with_dropdown).fill(
{
"test_1": "test_1",
"test_2": "test_2",
"test_3": "test_3",
"check_1": True,
"check_2": True,
"check_3": True,
"radio_1": 1,
"dropdown_1": 1,
},
)
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_dropdown_three(sample_template_with_dropdown, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "dropdown", "dropdown_three.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(sample_template_with_dropdown).fill(
{
"test_1": "test_1",
"test_2": "test_2",
"test_3": "test_3",
"check_1": True,
"check_2": True,
"check_3": True,
"radio_1": 1,
"dropdown_1": 2,
},
)
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_dropdown_four(sample_template_with_dropdown, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "dropdown", "dropdown_four.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(sample_template_with_dropdown).fill(
{
"test_1": "test_1",
"test_2": "test_2",
"test_3": "test_3",
"check_1": True,
"check_2": True,
"check_3": True,
"radio_1": 1,
"dropdown_1": 3,
},
)
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_dropdown_alignment(dropdown_alignment, pdf_samples, request):
expected_path = os.path.join(
pdf_samples, "dropdown", "dropdown_alignment_expected.pdf"
)
with open(expected_path, "rb+") as f:
obj = PdfWrapper(dropdown_alignment).fill(
{
"dropdown_left": 0,
"dropdown_center": 1,
"dropdown_right": 2,
},
)
request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
expected = f.read()
if os.name != "nt":
assert len(obj.stream) == len(expected)
assert obj.stream == expected
def test_dropdown_alignment_sejda(dropdown_alignment_sejda, pdf_samples, request):
expected_path = os.path.join(
pdf_samples, "dropdown", "dropdown_alignment_sejda_expected.pdf"
)
with open(
expected_path,
"rb+",
) as f:
obj = PdfWrapper(dropdown_alignment_sejda).fill(
{
"dropdown_left": 0,
"dropdown_center": 1,
"dropdown_right": 2,
},
)
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