23 |
23 |
from wcs import fields
|
24 |
24 |
|
25 |
25 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
26 |
|
from test_all import create_superuser, create_environment
|
|
26 |
from test_all import create_superuser
|
27 |
27 |
|
28 |
28 |
|
29 |
29 |
def pytest_generate_tests(metafunc):
|
... | ... | |
59 |
59 |
|
60 |
60 |
def test_backoffice_csv(pub):
|
61 |
61 |
create_superuser(pub)
|
62 |
|
create_environment(pub)
|
|
62 |
|
|
63 |
datasource = {
|
|
64 |
'type': 'formula',
|
|
65 |
'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])
|
|
66 |
}
|
|
67 |
FormDef.wipe()
|
|
68 |
formdef = FormDef()
|
|
69 |
formdef.name = 'form title'
|
|
70 |
formdef.fields = [
|
|
71 |
fields.StringField(
|
|
72 |
id='1', label='1st field', type='string',
|
|
73 |
display_locations=['validation', 'summary', 'listings']),
|
|
74 |
fields.ItemField(
|
|
75 |
id='2', label='2nd field', type='item',
|
|
76 |
items=['foo', 'bar', 'baz'],
|
|
77 |
display_locations=['validation', 'summary', 'listings']),
|
|
78 |
fields.ItemField(
|
|
79 |
id='3', label='3rd field', type='item',
|
|
80 |
data_source=datasource, varname='foo'),
|
|
81 |
]
|
|
82 |
formdef.workflow_roles = {'_receiver': 1}
|
|
83 |
formdef.store()
|
|
84 |
|
|
85 |
formdef.data_class().wipe()
|
|
86 |
for i in range(3):
|
|
87 |
formdata = formdef.data_class()()
|
|
88 |
formdata.receipt_time = datetime.datetime(2015, 1, 1).timetuple()
|
|
89 |
formdata.data = {'1': 'FOO BAR %d' % i}
|
|
90 |
if i == 0:
|
|
91 |
formdata.data['2'] = 'foo'
|
|
92 |
formdata.data['2_display'] = 'foo'
|
|
93 |
formdata.data['3'] = 'A'
|
|
94 |
formdata.data['3_display'] = 'aa'
|
|
95 |
else:
|
|
96 |
formdata.data['2'] = 'baz'
|
|
97 |
formdata.data['2_display'] = 'baz'
|
|
98 |
formdata.data['3'] = 'C'
|
|
99 |
formdata.data['3_display'] = 'cc'
|
|
100 |
if i < 2:
|
|
101 |
formdata.jump_status('new')
|
|
102 |
formdata.store()
|
|
103 |
|
63 |
104 |
app = login(get_app(pub))
|
64 |
105 |
resp = app.get('/backoffice/management/form-title/')
|
65 |
106 |
resp = resp.click('Export as CSV File')
|
66 |
107 |
assert resp.headers['content-type'].startswith('text/')
|
67 |
|
assert len(resp.text.splitlines()) == 18 # 17 + header line
|
|
108 |
assert len(resp.text.splitlines()) == 3 # 3 + header line
|
68 |
109 |
assert len(resp.text.splitlines()[0].split(',')) == 7
|
69 |
110 |
|
70 |
111 |
formdef = FormDef.get_by_urlname('form-title')
|
... | ... | |
77 |
118 |
# check item fields with datasources get two columns (id & text)
|
78 |
119 |
assert resp.text.splitlines()[0].split(',')[6] == '3rd field'
|
79 |
120 |
assert resp.text.splitlines()[0].split(',')[7] == '' # 3rd field, continue
|
80 |
|
assert resp.text.splitlines()[1].split(',')[6] == 'A'
|
81 |
|
assert resp.text.splitlines()[1].split(',')[7] == 'aa'
|
|
121 |
assert resp.text.splitlines()[1].split(',')[6] == 'C'
|
|
122 |
assert resp.text.splitlines()[1].split(',')[7] == 'cc'
|
82 |
123 |
|
83 |
124 |
resp = app.get('/backoffice/management/form-title/')
|
84 |
125 |
resp.forms['listing-settings']['filter'] = 'all'
|
85 |
126 |
resp = resp.forms['listing-settings'].submit()
|
86 |
127 |
resp_csv = resp.click('Export as CSV File')
|
87 |
|
assert len(resp_csv.text.splitlines()) == 51
|
|
128 |
assert len(resp_csv.text.splitlines()) == 4
|
88 |
129 |
|
89 |
130 |
# test status filter
|
90 |
131 |
resp.forms['listing-settings']['filter'] = 'pending'
|
... | ... | |
93 |
134 |
resp.forms['listing-settings']['filter-2-value'] = 'baz'
|
94 |
135 |
resp = resp.forms['listing-settings'].submit()
|
95 |
136 |
resp_csv = resp.click('Export as CSV File')
|
96 |
|
assert len(resp_csv.text.splitlines()) == 9
|
|
137 |
assert len(resp_csv.text.splitlines()) == 2
|
97 |
138 |
|
98 |
139 |
# test criteria filters
|
99 |
140 |
resp.forms['listing-settings']['filter-start'].checked = True
|
... | ... | |
108 |
149 |
resp.forms['listing-settings']['filter-2-value'] = 'baz'
|
109 |
150 |
resp = resp.forms['listing-settings'].submit()
|
110 |
151 |
resp_csv = resp.click('Export as CSV File')
|
111 |
|
assert len(resp_csv.text.splitlines()) == 9
|
|
152 |
assert len(resp_csv.text.splitlines()) == 2
|
112 |
153 |
assert 'Created' in resp_csv.text.splitlines()[0]
|
113 |
154 |
|
114 |
155 |
# test column selection
|
... | ... | |
118 |
159 |
assert 'Created' not in resp_csv.text.splitlines()[0]
|
119 |
160 |
|
120 |
161 |
|
121 |
|
def test_backoffice_export_long_listings(pub):
|
|
162 |
def test_backoffice_export_long_listings(settings, pub):
|
|
163 |
settings.WCS_SYNC_EXPORT_LIMIT = 1
|
122 |
164 |
create_superuser(pub)
|
123 |
|
create_environment(pub)
|
124 |
|
formdef = FormDef.get_by_urlname('form-title')
|
125 |
|
for i in range(100):
|
|
165 |
|
|
166 |
FormDef.wipe()
|
|
167 |
formdef = FormDef()
|
|
168 |
formdef.name = 'form title'
|
|
169 |
formdef.fields = [
|
|
170 |
fields.StringField(
|
|
171 |
id='1', label='1st field', type='string',
|
|
172 |
display_locations=['validation', 'summary', 'listings']),
|
|
173 |
]
|
|
174 |
formdef.workflow_roles = {'_receiver': 1}
|
|
175 |
formdef.store()
|
|
176 |
|
|
177 |
formdef.data_class().wipe()
|
|
178 |
for i in range(2):
|
126 |
179 |
formdata = formdef.data_class()()
|
127 |
|
formdata.just_created()
|
128 |
180 |
formdata.receipt_time = datetime.datetime(2015, 1, 1).timetuple()
|
129 |
181 |
formdata.data = {'1': 'BAZ BAZ %d' % i}
|
130 |
182 |
formdata.jump_status('new')
|
... | ... | |
138 |
190 |
assert 'completed' in resp.text
|
139 |
191 |
resp = resp.click('Download Export')
|
140 |
192 |
resp_lines = resp.text.splitlines()
|
141 |
|
assert resp_lines[0] == 'Number,Created,Last Modified,User Label,1st field,2nd field,Status'
|
142 |
|
assert len(resp_lines) == 118
|
|
193 |
assert resp_lines[0] == 'Number,Created,Last Modified,User Label,1st field,Status'
|
|
194 |
assert len(resp_lines) == 3
|
143 |
195 |
assert resp_lines[1].split(',')[1].startswith(
|
144 |
196 |
time.strftime('%Y-%m-%d', formdata.receipt_time))
|
145 |
197 |
assert resp_lines[1].split(',')[2].startswith(
|
... | ... | |
171 |
223 |
fd.close()
|
172 |
224 |
|
173 |
225 |
create_superuser(pub)
|
174 |
|
create_environment(pub)
|
|
226 |
|
|
227 |
FormDef.wipe()
|
|
228 |
formdef = FormDef()
|
|
229 |
formdef.name = 'form title'
|
|
230 |
formdef.fields = []
|
|
231 |
formdef.workflow_roles = {'_receiver': 1}
|
|
232 |
formdef.store()
|
|
233 |
|
|
234 |
formdef.data_class().wipe()
|
|
235 |
formdata = formdef.data_class()()
|
|
236 |
formdata.jump_status('new')
|
|
237 |
formdata.store()
|
|
238 |
|
175 |
239 |
app = login(get_app(pub))
|
176 |
240 |
resp = app.get('/backoffice/management/form-title/')
|
177 |
241 |
resp_csv = resp.click('Export as CSV File')
|
... | ... | |
191 |
255 |
fd.close()
|
192 |
256 |
|
193 |
257 |
create_superuser(pub)
|
194 |
|
create_environment(pub)
|
|
258 |
|
|
259 |
FormDef.wipe()
|
|
260 |
formdef = FormDef()
|
|
261 |
formdef.name = 'form title'
|
|
262 |
formdef.fields = []
|
|
263 |
formdef.workflow_roles = {'_receiver': 1}
|
|
264 |
formdef.store()
|
|
265 |
|
|
266 |
formdef.data_class().wipe()
|
|
267 |
formdata = formdef.data_class()()
|
|
268 |
formdata.jump_status('new')
|
|
269 |
formdata.store()
|
|
270 |
|
195 |
271 |
app = login(get_app(pub))
|
196 |
272 |
resp = app.get('/backoffice/management/form-title/')
|
197 |
273 |
resp_csv = resp.click('Export as CSV File')
|
... | ... | |
207 |
283 |
|
208 |
284 |
def test_backoffice_csv_export_block(pub):
|
209 |
285 |
create_superuser(pub)
|
210 |
|
create_environment(pub)
|
211 |
286 |
|
212 |
287 |
block = BlockDef()
|
213 |
288 |
block.name = 'foobar'
|
... | ... | |
218 |
293 |
block.digest_template = 'X{{foobar_var_foo}}Y'
|
219 |
294 |
block.store()
|
220 |
295 |
|
221 |
|
formdef = FormDef.get_by_urlname('form-title')
|
222 |
|
formdef.fields = []
|
223 |
|
formdef.store() # make sure sql columns are removed
|
224 |
|
|
|
296 |
FormDef.wipe()
|
|
297 |
formdef = FormDef()
|
|
298 |
formdef.name = 'form title'
|
225 |
299 |
formdef.fields = [
|
226 |
300 |
fields.BlockField(id='1', label='test', type='block:foobar', max_items=3),
|
227 |
301 |
]
|
|
302 |
formdef.workflow_roles = {'_receiver': 1}
|
228 |
303 |
formdef.store()
|
229 |
304 |
|
230 |
305 |
formdef.data_class().wipe()
|
231 |
306 |
formdata = formdef.data_class()()
|
232 |
|
formdata.data = {}
|
233 |
|
formdata.data['1'] = {
|
234 |
|
'data': [
|
235 |
|
{'123': 'foo', '234': 'bar'},
|
236 |
|
{'123': 'foo2', '234': 'bar2'},
|
237 |
|
],
|
238 |
|
'schema': {'123': 'string', '234': 'string'},
|
|
307 |
formdata.data = {
|
|
308 |
'1': {
|
|
309 |
'data': [
|
|
310 |
{'123': 'foo', '234': 'bar'},
|
|
311 |
{'123': 'foo2', '234': 'bar2'},
|
|
312 |
],
|
|
313 |
'schema': {'123': 'string', '234': 'string'},
|
|
314 |
}
|
239 |
315 |
}
|
240 |
316 |
formdata.just_created()
|
241 |
317 |
formdata.jump_status('new')
|
... | ... | |
253 |
329 |
|
254 |
330 |
def test_backoffice_ods(pub):
|
255 |
331 |
create_superuser(pub)
|
256 |
|
create_environment(pub)
|
|
332 |
|
|
333 |
FormDef.wipe()
|
|
334 |
formdef = FormDef()
|
|
335 |
formdef.name = 'form title'
|
|
336 |
formdef.fields = [
|
|
337 |
fields.FileField(
|
|
338 |
id='4', label='file field', type='file',
|
|
339 |
display_locations=['validation', 'summary', 'listings']),
|
|
340 |
fields.DateField(
|
|
341 |
id='5', label='date field', type='date',
|
|
342 |
display_locations=['validation', 'summary', 'listings']),
|
|
343 |
fields.StringField(
|
|
344 |
id='6', label='number field', type='string',
|
|
345 |
display_locations=['validation', 'summary', 'listings']),
|
|
346 |
fields.StringField(
|
|
347 |
id='7', label='phone field', type='string',
|
|
348 |
display_locations=['validation', 'summary', 'listings']),
|
|
349 |
fields.DateField(
|
|
350 |
id='8', label='very old field', type='date',
|
|
351 |
display_locations=['validation', 'summary', 'listings']),
|
|
352 |
fields.StringField(
|
|
353 |
id='9', label='string field', type='string',
|
|
354 |
display_locations=['validation', 'summary', 'listings']),
|
|
355 |
]
|
|
356 |
formdef.workflow_roles = {'_receiver': 1}
|
|
357 |
formdef.store()
|
|
358 |
|
257 |
359 |
app = login(get_app(pub))
|
258 |
360 |
resp = app.get('/backoffice/management/form-title/')
|
259 |
361 |
resp = resp.click('Export a Spreadsheet')
|
... | ... | |
261 |
363 |
assert 'filename=form-title.ods' in resp.headers['content-disposition']
|
262 |
364 |
assert resp.body[:2] == b'PK' # ods has a zip container
|
263 |
365 |
|
264 |
|
formdef = FormDef.get_by_urlname('form-title')
|
265 |
|
formdef.fields.append(fields.FileField(
|
266 |
|
id='4', label='file field', type='file',
|
267 |
|
display_locations=['validation', 'summary', 'listings']))
|
268 |
|
formdef.fields.append(fields.DateField(
|
269 |
|
id='5', label='date field', type='date',
|
270 |
|
display_locations=['validation', 'summary', 'listings']))
|
271 |
|
formdef.fields.append(fields.StringField(
|
272 |
|
id='6', label='number field', type='string',
|
273 |
|
display_locations=['validation', 'summary', 'listings']))
|
274 |
|
formdef.fields.append(fields.StringField(
|
275 |
|
id='7', label='phone field', type='string',
|
276 |
|
display_locations=['validation', 'summary', 'listings']))
|
277 |
|
formdef.fields.append(fields.DateField(
|
278 |
|
id='8', label='very old field', type='date',
|
279 |
|
display_locations=['validation', 'summary', 'listings']))
|
280 |
|
formdef.fields.append(fields.StringField(
|
281 |
|
id='9', label='string field', type='string',
|
282 |
|
display_locations=['validation', 'summary', 'listings']))
|
283 |
|
formdef.store()
|
284 |
|
|
285 |
|
formdata = formdef.data_class().select(lambda x: x.status == 'wf-new')[0]
|
286 |
|
formdata.data['4'] = PicklableUpload('/foo/bar', content_type='text/plain')
|
|
366 |
formdef.data_class().wipe()
|
|
367 |
formdata = formdef.data_class()()
|
|
368 |
formdata.data = {
|
|
369 |
'4': PicklableUpload('/foo/bar', content_type='text/plain'),
|
|
370 |
'5': time.strptime('2015-05-12', '%Y-%m-%d'),
|
|
371 |
'6': '12345',
|
|
372 |
'7': '0102030405',
|
|
373 |
'8': time.strptime('1871-03-18', '%Y-%m-%d'),
|
|
374 |
'9': 'plop\npl\x1dop', # with control characters
|
|
375 |
}
|
287 |
376 |
formdata.data['4'].receive([b'hello world'])
|
288 |
|
formdata.data['5'] = time.strptime('2015-05-12', '%Y-%m-%d')
|
289 |
|
formdata.data['6'] = '12345'
|
290 |
|
formdata.data['7'] = '0102030405'
|
291 |
|
formdata.data['8'] = time.strptime('1871-03-18', '%Y-%m-%d')
|
292 |
|
formdata.data['9'] = 'plop\npl\x1dop' # with control characters
|
|
377 |
formdata.just_created()
|
|
378 |
formdata.jump_status('new')
|
293 |
379 |
formdata.store()
|
294 |
380 |
|
295 |
381 |
resp = app.get('/backoffice/management/form-title/')
|
... | ... | |
346 |
432 |
@pytest.mark.skipif('xlwt is None')
|
347 |
433 |
def test_backoffice_xls(pub):
|
348 |
434 |
create_superuser(pub)
|
349 |
|
create_environment(pub)
|
|
435 |
|
|
436 |
FormDef.wipe()
|
|
437 |
formdef = FormDef()
|
|
438 |
formdef.name = 'form title'
|
|
439 |
formdef.fields = []
|
|
440 |
formdef.store()
|
|
441 |
|
350 |
442 |
app = login(get_app(pub))
|
351 |
443 |
resp = app.get('/backoffice/management/form-title/')
|
352 |
444 |
assert 'Excel Export' not in resp.text
|