mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
Add form validation for max service and org name
There was a recent error in the logs because a service tried to change its name to one exceeding 255 characters (which is a limit on the database field). We can easily catch these errors on the form, so that the user doesn't see an error page.
This commit is contained in:
@@ -483,20 +483,27 @@ def test_should_not_hit_api_if_service_name_hasnt_changed(
|
||||
assert not mock_update_service.called
|
||||
|
||||
|
||||
def test_service_name_change_fails_if_new_name_has_less_than_2_alphanumeric_characters(
|
||||
@pytest.mark.parametrize('name, error_message', [
|
||||
('', 'Cannot be empty'),
|
||||
('.', 'Must include at least two alphanumeric characters'),
|
||||
('a' * 256, 'Service name must be 255 characters or fewer'),
|
||||
])
|
||||
def test_service_name_change_fails_if_new_name_fails_validation(
|
||||
client_request,
|
||||
mock_update_service,
|
||||
mock_service_name_is_unique,
|
||||
name,
|
||||
error_message,
|
||||
):
|
||||
page = client_request.post(
|
||||
'main.service_name_change',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'name': "."},
|
||||
_data={'name': name},
|
||||
_expected_status=200,
|
||||
)
|
||||
assert not mock_service_name_is_unique.called
|
||||
assert not mock_update_service.called
|
||||
assert page.find("span", {"class": "govuk-error-message"})
|
||||
assert error_message in page.find("span", {"class": "govuk-error-message"}).text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('user, expected_text, expected_link', [
|
||||
|
||||
Reference in New Issue
Block a user