mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Add validation for provider SMS percentages
We could alternatively put the "add up to 100%" error on the page
using form-level errors [^1] and a custom flash message. Putting
the error on each field is slightly simpler and does make it clear
the issue is with all of the fields together.
[^1]: 22636b55ed
This commit is contained in:
@@ -337,3 +337,46 @@ def test_edit_sms_provider_ratio_submit(
|
||||
)
|
||||
|
||||
assert mock_update_provider.call_args_list == expected_calls
|
||||
|
||||
|
||||
@pytest.mark.parametrize('post_data, expected_error', [
|
||||
(
|
||||
{
|
||||
sms_provider_1['identifier']: 90,
|
||||
sms_provider_2['identifier']: 20
|
||||
},
|
||||
"Must add up to 100%"
|
||||
),
|
||||
(
|
||||
{
|
||||
sms_provider_1['identifier']: 101,
|
||||
sms_provider_2['identifier']: 20
|
||||
},
|
||||
"Must be between 0 and 100"
|
||||
),
|
||||
])
|
||||
def test_edit_sms_provider_submit_invalid_percentages(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
post_data,
|
||||
expected_error,
|
||||
stub_providers,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.provider_client.get_all_providers',
|
||||
return_value=stub_providers
|
||||
)
|
||||
mock_update_provider = mocker.patch(
|
||||
'app.provider_client.update_provider'
|
||||
)
|
||||
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.edit_sms_provider_ratio',
|
||||
_data=post_data,
|
||||
_follow_redirects=True
|
||||
)
|
||||
|
||||
assert expected_error in page.select_one('.govuk-error-message').text
|
||||
mock_update_provider.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user