fields: consider the empty string as a valid (null) date (#23162)
This commit is contained in:
parent
1b2dc7f44e
commit
cab586baaa
|
@ -582,7 +582,7 @@ def test_process_notification_user_provision(pub):
|
|||
}
|
||||
CmdHoboNotify.process_notification(notification)
|
||||
assert User.count() == 1
|
||||
if birthdate is not None: # wrong value : no nothing
|
||||
if birthdate not in (None, ''): # wrong value : no nothing
|
||||
assert User.select()[0].form_data['_birthdate'].tm_year == 2000
|
||||
else: # empty value : empty field
|
||||
assert User.select()[0].form_data['_birthdate'] is None
|
||||
|
|
|
@ -2919,13 +2919,15 @@ def test_profile(two_pubs):
|
|||
assert http_patch_request.call_count == 1
|
||||
assert http_patch_request.call_args[0][1] == '{"bar": "2018-03-20"}'
|
||||
|
||||
user.form_data['4'] = datetime.datetime.now().timetuple()
|
||||
user.store()
|
||||
year = User.get(user.id).form_data.get('4').tm_year
|
||||
for date_value in ('baddate', '', {}, [], None):
|
||||
# reset date to a known value
|
||||
user.form_data['4'] = datetime.datetime.now().timetuple()
|
||||
user.store()
|
||||
year = User.get(user.id).form_data.get('4').tm_year
|
||||
# perform action
|
||||
item.fields = [{'field_id': 'bar', 'value': date_value}]
|
||||
item.perform(formdata)
|
||||
if date_value is not None: # bad value : do nothing
|
||||
if date_value not in (None, ''): # bad value : do nothing
|
||||
assert User.get(user.id).form_data.get('4').tm_year == year
|
||||
else: # empty value : empty field
|
||||
assert User.get(user.id).form_data.get('4') == None
|
||||
|
@ -2934,7 +2936,7 @@ def test_profile(two_pubs):
|
|||
http_patch_request.return_value = (None, 200, '', None)
|
||||
get_response().process_after_jobs()
|
||||
assert http_patch_request.call_count == 1
|
||||
if date_value is not None: # bad value : do nothing
|
||||
if date_value not in (None, ''): # bad value : do nothing
|
||||
assert http_patch_request.call_args[0][1] == '{}'
|
||||
else: # empty value : null field
|
||||
assert http_patch_request.call_args[0][1] == '{"bar": null}'
|
||||
|
@ -3282,7 +3284,7 @@ def test_set_backoffice_field_date(two_pubs):
|
|||
assert datetime.date(*formdata.data['bo1'][:3]) == datetime.date(2017, 3, 23)
|
||||
|
||||
# invalid values => do nothing
|
||||
for value in ('plop', '', {}, [], '{{ blah }}'):
|
||||
for value in ('plop', {}, []):
|
||||
item = SetBackofficeFieldsWorkflowStatusItem()
|
||||
item.parent = st1
|
||||
item.fields = [{'field_id': 'bo1', 'value': value}]
|
||||
|
|
|
@ -980,7 +980,7 @@ class DateField(WidgetField):
|
|||
|
||||
@classmethod
|
||||
def convert_value_from_anything(cls, value):
|
||||
if value is None:
|
||||
if value is None or value == '':
|
||||
return None
|
||||
date_value = evalutils.make_date(value).timetuple() # could raise ValueError
|
||||
return date_value
|
||||
|
|
Loading…
Reference in New Issue