testdef: handle empty file fields (#75616) #178
|
@ -632,6 +632,14 @@ def test_validation_file_field(pub):
|
|||
testdef = TestDef.create_from_formdata(formdef, formdata)
|
||||
testdef.run(formdef)
|
||||
|
||||
# test against empty value
|
||||
formdata.data['1'] = None
|
||||
testdef = TestDef.create_from_formdata(formdef, formdata)
|
||||
with pytest.raises(TestError) as excinfo:
|
||||
testdef.run(formdef)
|
||||
assert str(excinfo.value) == 'Empty value for field "File": required field.'
|
||||
|
||||
# test with filename that will negate next field condition
|
||||
upload = PicklableUpload('hop.pdf', 'application/pdf', 'ascii')
|
||||
upload.receive([b'first line', b'second line'])
|
||||
formdata.data['1'] = upload
|
||||
|
|
|
@ -79,7 +79,7 @@ class TestDef(sql.TestDef):
|
|||
if field.id in formdata.data:
|
||||
value = formdata.data[field.id]
|
||||
|
||||
if hasattr(field, 'get_json_value'):
|
||||
if value and hasattr(field, 'get_json_value'):
|
||||
value = field.get_json_value(value)
|
||||
|
||||
field_data[field.id] = value
|
||||
|
|
Loading…
Reference in New Issue