273 |
273 |
formdef.store()
|
274 |
274 |
formdef.data_class().wipe()
|
275 |
275 |
|
276 |
|
formdata = formdef.data_class()()
|
277 |
|
formdata.just_created()
|
278 |
|
formdata.data = {
|
279 |
|
'5': PicklableUpload('test.txt', 'text/plain'),
|
280 |
|
}
|
281 |
|
formdata.data['5'].receive([b'hello world'])
|
282 |
|
formdata.store()
|
283 |
|
|
284 |
|
assert formdata.data['5'].qfilename in os.listdir(os.path.join(pub.app_dir, 'uploads'))
|
285 |
|
clean_unused_files(pub)
|
286 |
|
assert os.listdir(os.path.join(pub.app_dir, 'uploads')) == [formdata.data['5'].qfilename]
|
287 |
|
formdata.anonymise()
|
288 |
|
clean_unused_files(pub)
|
289 |
|
assert len(os.listdir(os.path.join(pub.app_dir, 'uploads'))) == 1 # file is not removed
|
290 |
|
|
291 |
276 |
if not pub.site_options.has_section('options'):
|
292 |
277 |
pub.site_options.add_section('options')
|
293 |
278 |
|
294 |
|
for behaviour in ('move', 'remove'):
|
295 |
|
pub.site_options.set('options', 'unused-files-behaviour', behaviour)
|
|
279 |
for behaviour in (None, 'move', 'remove'):
|
|
280 |
if behaviour:
|
|
281 |
pub.site_options.set('options', 'unused-files-behaviour', behaviour)
|
296 |
282 |
|
297 |
283 |
formdata = formdef.data_class()()
|
298 |
284 |
formdata.just_created()
|
... | ... | |
403 |
389 |
# 1 attachment
|
404 |
390 |
assert len(glob.glob(os.path.join(pub.app_dir, 'unused-files/attachments/*/*'))) == 1
|
405 |
391 |
|
|
392 |
# unknown unused-files-behaviour: do nothing
|
|
393 |
pub.site_options.set('options', 'unused-files-behaviour', 'foo')
|
|
394 |
formdata = formdef.data_class()()
|
|
395 |
formdata.just_created()
|
|
396 |
formdata.data = {
|
|
397 |
'5': PicklableUpload('test-no-remove.txt', 'text/plain'),
|
|
398 |
}
|
|
399 |
formdata.data['5'].receive([b'hello world'])
|
|
400 |
formdata.store()
|
|
401 |
|
|
402 |
assert formdata.data['5'].qfilename in os.listdir(os.path.join(pub.app_dir, 'uploads'))
|
|
403 |
clean_unused_files(pub)
|
|
404 |
assert os.listdir(os.path.join(pub.app_dir, 'uploads')) == [formdata.data['5'].qfilename]
|
|
405 |
formdata.anonymise()
|
|
406 |
clean_unused_files(pub)
|
|
407 |
assert len(os.listdir(os.path.join(pub.app_dir, 'uploads'))) == 1 # file is not removed
|
|
408 |
|
406 |
409 |
|
407 |
410 |
def test_get_formdefs_of_all_kinds(pub):
|
408 |
411 |
from wcs.admin.settings import UserFieldsFormDef
|