/
object_single_integration.txt
282 lines (237 loc) · 6.37 KB
/
object_single_integration.txt
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
=====================================
ObjectWidget single integration tests
=====================================
Checking components on the highest possible level.
>>> from datetime import date
>>> from z3c.form import form
>>> from z3c.form import field
>>> from z3c.form import testing
>>> from z3c.form.object import registerFactoryAdapter
>>> registerFactoryAdapter(testing.IObjectWidgetSingleSubIntegration,
... testing.ObjectWidgetSingleSubIntegration)
>>> request = testing.TestRequest()
>> from z3c.form.object import registerFactoryAdapter
>> registerFactoryAdapter(testing.IObjectWidgetSingleSubIntegration,
.. testing.ObjectWidgetSingleSubIntegration)
>>> class EForm(form.EditForm):
... form.extends(form.EditForm)
... fields = field.Fields(testing.IObjectWidgetSingleIntegration)
Our single content object:
>>> obj = testing.ObjectWidgetSingleIntegration()
We recreate the form each time, to stay as close as possible.
In real life the form gets instantiated and destroyed with each request.
>>> def getForm(request, fname=None):
... frm = EForm(obj, request)
... testing.addTemplate(frm, 'integration_edit.pt')
... frm.update()
... content = frm.render()
... if fname is not None:
... testing.saveHtml(content, fname)
... return content
Empty
------
All blank and empty values:
>>> content = getForm(request, 'ObjectWidget_single_edit_empty.html')
>>> print(testing.plainText(content))
Object label
Int label
*
[]
Bool label
*
( )
yes
( )
no
Choice label
*
[[ ]]
ChoiceOpt label
[No value]
TextLine label
*
[]
Date label
*
[]
ReadOnly label
*
[]
[Apply]
Some valid default values
--------------------------
>>> obj.subobj = testing.ObjectWidgetSingleSubIntegration(
... singleInt=-100,
... singleBool=False,
... singleChoice='two',
... singleChoiceOpt='six',
... singleTextLine=u'some text one',
... singleDate=date(2014, 6, 20),
... singleReadOnly=u'some R/O text')
>>> content = getForm(request, 'ObjectWidget_single_edit_simple.html')
>>> print(testing.plainText(content))
Object label
Int label
*
[-100]
Bool label
*
( )
yes
(O)
no
Choice label
*
[two]
ChoiceOpt label
[six]
TextLine label
*
[some text one]
Date label
*
[14/06/20]
ReadOnly label
*
some R/O text
[Apply]
Wrong values
-------------
Set wrong values:
>>> submit = testing.getSubmitValues(content)
>>> submit['form.widgets.subobj.widgets.singleInt'] = u'foobar'
>>> submit['form.widgets.subobj.widgets.singleTextLine'] = u'foo\nbar'
>>> submit['form.widgets.subobj.widgets.singleDate'] = u'foobar'
>>> submit['form.buttons.apply'] = 'Apply'
>>> request = testing.TestRequest(form=submit)
We should get lots of errors:
>>> content = getForm(request, 'ObjectWidget_single_edit_submit_wrong.html')
>>> print(testing.plainText(content,
... './/ul[@id="form-errors"]'))
* Object label: The entered value is not a valid integer literal.
Constraint not satisfied
The datetime string did not match the pattern 'yy/MM/dd'.
>>> print(testing.plainText(content,
... './/div[@id="row-form-widgets-subobj"]/b/div[@class="error"]'))
The entered value is not a valid integer literal.
Constraint not satisfied
The datetime string did not match the pattern 'yy/MM/dd'.
>>> print(testing.plainText(content,
... './/div[@id="row-form-widgets-subobj"]'))
The entered value is not a valid integer literal.
Constraint not satisfied
The datetime string did not match the pattern u'yy/MM/dd'. Object label
Int label
*
<BLANKLINE>
The entered value is not a valid integer literal.
[foobar]
<BLANKLINE>
Bool label
*
<BLANKLINE>
( )
yes
(O)
no
<BLANKLINE>
Choice label
*
<BLANKLINE>
[two]
<BLANKLINE>
ChoiceOpt label
<BLANKLINE>
[six]
<BLANKLINE>
TextLine label
*
<BLANKLINE>
Constraint not satisfied
[foo
bar]
<BLANKLINE>
Date label
*
<BLANKLINE>
The datetime string did not match the pattern u'yy/MM/dd'.
[foobar]
<BLANKLINE>
ReadOnly label
*
<BLANKLINE>
some R/O text
Let's fix the values:
>>> submit = testing.getSubmitValues(content)
>>> submit['form.widgets.subobj.widgets.singleInt'] = u'1042'
>>> submit['form.widgets.subobj.widgets.singleBool'] = u'true'
>>> submit['form.widgets.subobj.widgets.singleChoice:list'] = u'three'
>>> submit['form.widgets.subobj.widgets.singleChoiceOpt:list'] = u'four'
>>> submit['form.widgets.subobj.widgets.singleTextLine'] = u'foobar'
>>> submit['form.widgets.subobj.widgets.singleDate'] = u'14/06/21'
>>> submit['form.buttons.apply'] = 'Apply'
>>> request = testing.TestRequest(form=submit)
>>> content = getForm(request, 'ObjectWidget_single_edit_submit_fixed.html')
>>> print(testing.plainText(content))
Data successfully updated.
<BLANKLINE>
Object label
Int label
*
[1,042]
Bool label
*
(O)
yes
( )
no
Choice label
*
[three]
ChoiceOpt label
[four]
TextLine label
*
[foobar]
Date label
*
[14/06/21]
ReadOnly label
*
some R/O text
[Apply]
Bool was misbehaving
>>> submit = testing.getSubmitValues(content)
>>> submit['form.widgets.subobj.widgets.singleBool'] = u'false'
>>> submit['form.buttons.apply'] = 'Apply'
>>> request = testing.TestRequest(form=submit)
>>> content = getForm(request, 'ObjectWidget_single_edit_submit_bool1.html')
>>> print(testing.plainText(content))
Data successfully updated.
...
>>> pprint(obj.subobj)
<ObjectWidgetSingleSubIntegration
singleBool: False
singleChoice: 'three'
singleChoiceOpt: 'four'
singleDate: datetime.date(2014, 6, 21)
singleInt: 1042
singleReadOnly: u'some R/O text'
singleTextLine: u'foobar'>
>>> submit = testing.getSubmitValues(content)
>>> submit['form.widgets.subobj.widgets.singleBool'] = u'true'
>>> submit['form.buttons.apply'] = 'Apply'
>>> request = testing.TestRequest(form=submit)
>>> content = getForm(request, 'ObjectWidget_single_edit_submit_bool2.html')
>>> print(testing.plainText(content))
Data successfully updated.
...
>>> pprint(obj.subobj)
<ObjectWidgetSingleSubIntegration
singleBool: True
singleChoice: 'three'
singleChoiceOpt: 'four'
singleDate: datetime.date(2014, 6, 21)
singleInt: 1042
singleReadOnly: u'some R/O text'
singleTextLine: u'foobar'>