mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Use unambiguously magic value for None choices
WTForms coerces `None` as a choice to `'None'` as a string when
rendering form fields (form fields will only ever have string data
because that what the browser posts back).
But internally WTForms coerces `None` to mean an unset value, ie where
the user hasn’t selected a radio button:
283b280320/src/wtforms/utils.py (L1-L20)
We shouldn’t use `None` to mean two different things. And in fact we
can’t, because it in effect means that we’re always getting a value
for the `move_to` field, even if the user hasn’t chosen to move any
templates. Which results in some very expected behaviour.
This commit is contained in:
@@ -901,7 +901,7 @@ def test_should_be_able_to_move_a_sub_item(
|
||||
template_folder_id=PARENT_FOLDER_ID,
|
||||
_data={
|
||||
'operation': 'move_to_existing_folder',
|
||||
'move_to': 'None',
|
||||
'move_to': '__NONE__',
|
||||
'templates_and_folders': [GRANDCHILD_FOLDER_ID],
|
||||
},
|
||||
_expected_status=302,
|
||||
@@ -929,6 +929,13 @@ def test_should_be_able_to_move_a_sub_item(
|
||||
'move_to_new_folder_name': 'foo',
|
||||
'move_to': PARENT_FOLDER_ID
|
||||
},
|
||||
# move to existing, but no templates to move
|
||||
{
|
||||
'operation': 'move_to_existing_folder',
|
||||
'templates_and_folders': [],
|
||||
'move_to_new_folder_name': '',
|
||||
'move_to': PARENT_FOLDER_ID
|
||||
},
|
||||
# move to new, but nothing selected to move
|
||||
{
|
||||
'operation': 'move_to_new_folder',
|
||||
@@ -944,6 +951,14 @@ def test_should_be_able_to_move_a_sub_item(
|
||||
'move_to': PARENT_FOLDER_ID,
|
||||
'add_template_by_template_type': 'email',
|
||||
},
|
||||
# add a new template, but also move to root folder
|
||||
{
|
||||
'operation': 'add_template',
|
||||
'templates_and_folders': [],
|
||||
'move_to_new_folder_name': '',
|
||||
'move_to': '__NONE__',
|
||||
'add_template_by_template_type': 'email',
|
||||
},
|
||||
])
|
||||
def test_no_action_if_user_fills_in_ambiguous_fields(
|
||||
client_request,
|
||||
|
||||
Reference in New Issue
Block a user