Add missing regex and validation for StringFields
This commit adds further validation for StringFields that were missing it. This mostly amounted to being Regex patters and max lengths.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
from wtforms.validators import ValidationError
|
||||
import uuid
|
||||
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
from atst.forms.data import ENV_ROLES, ENV_ROLE_NO_ACCESS as NO_ACCESS
|
||||
from atst.forms.data import ENV_ROLES
|
||||
from atst.forms.application_member import *
|
||||
|
||||
|
||||
def test_environment_form():
|
||||
form_data = {
|
||||
"environment_id": 123,
|
||||
"environment_id": str(uuid.uuid4()),
|
||||
"environment_name": "testing",
|
||||
"role": ENV_ROLES[0][0],
|
||||
"disabled": True,
|
||||
@@ -17,12 +16,13 @@ def test_environment_form():
|
||||
|
||||
|
||||
def test_environment_form_default_no_access():
|
||||
form_data = {"environment_id": 123, "environment_name": "testing"}
|
||||
env_id = str(uuid.uuid4())
|
||||
form_data = {"environment_id": env_id, "environment_name": "testing"}
|
||||
form = EnvironmentForm(data=form_data)
|
||||
|
||||
assert form.validate()
|
||||
assert form.data == {
|
||||
"environment_id": 123,
|
||||
"environment_id": env_id,
|
||||
"environment_name": "testing",
|
||||
"role": None,
|
||||
"disabled": False,
|
||||
@@ -31,7 +31,7 @@ def test_environment_form_default_no_access():
|
||||
|
||||
def test_environment_form_invalid():
|
||||
form_data = {
|
||||
"environment_id": 123,
|
||||
"environment_id": str(uuid.uuid4()),
|
||||
"environment_name": "testing",
|
||||
"role": "not a real choice",
|
||||
}
|
||||
|
@@ -4,16 +4,16 @@ import pytest
|
||||
from atst.forms.validators import *
|
||||
|
||||
|
||||
class TestIsNumber:
|
||||
class TestNumber:
|
||||
@pytest.mark.parametrize("valid", ["0", "12", "-12"])
|
||||
def test_IsNumber_accepts_integers(self, valid, dummy_form, dummy_field):
|
||||
validator = IsNumber()
|
||||
def test_Number_accepts_integers(self, valid, dummy_form, dummy_field):
|
||||
validator = Number()
|
||||
dummy_field.data = valid
|
||||
validator(dummy_form, dummy_field)
|
||||
|
||||
@pytest.mark.parametrize("invalid", ["12.1", "two"])
|
||||
def test_IsNumber_rejects_anything_else(self, invalid, dummy_form, dummy_field):
|
||||
validator = IsNumber()
|
||||
def test_Number_rejects_anything_else(self, invalid, dummy_form, dummy_field):
|
||||
validator = Number()
|
||||
dummy_field.data = invalid
|
||||
with pytest.raises(ValidationError):
|
||||
validator(dummy_form, dummy_field)
|
||||
|
Reference in New Issue
Block a user