Merge pull request #933 from dod-ccpo/remove-unused-validation
Remove unused validation
This commit is contained in:
commit
9b521765c7
@ -2,7 +2,7 @@ from datetime import datetime
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
from wtforms.validators import ValidationError, StopValidation
|
from wtforms.validators import ValidationError
|
||||||
import pendulum
|
import pendulum
|
||||||
|
|
||||||
from atst.utils.localization import translate
|
from atst.utils.localization import translate
|
||||||
@ -83,27 +83,6 @@ def ListItemsUnique(message=translate("forms.validators.list_items_unique_messag
|
|||||||
return _list_items_unique
|
return _list_items_unique
|
||||||
|
|
||||||
|
|
||||||
def RequiredIf(criteria_function, message=translate("forms.validators.is_required")):
|
|
||||||
""" A validator which makes a field required only if another field
|
|
||||||
has a truthy value
|
|
||||||
Args:
|
|
||||||
criteria_function (function): calling this function on form results
|
|
||||||
in a boolean value that we want to check against;
|
|
||||||
if it's True, we require the field
|
|
||||||
message (str): an optional message to display if the field is
|
|
||||||
required but hasNone value
|
|
||||||
"""
|
|
||||||
|
|
||||||
def _required_if(form, field):
|
|
||||||
if criteria_function(form):
|
|
||||||
if field.data is None:
|
|
||||||
raise ValidationError(message)
|
|
||||||
else:
|
|
||||||
raise StopValidation()
|
|
||||||
|
|
||||||
return _required_if
|
|
||||||
|
|
||||||
|
|
||||||
def FileLength(max_length=50000000, message=None):
|
def FileLength(max_length=50000000, message=None):
|
||||||
def _file_length(_form, field):
|
def _file_length(_form, field):
|
||||||
if field.data is None or not isinstance(field.data, FileStorage):
|
if field.data is None or not isinstance(field.data, FileStorage):
|
||||||
|
@ -75,24 +75,6 @@ class TestListItemsUnique:
|
|||||||
validator(dummy_form, dummy_field)
|
validator(dummy_form, dummy_field)
|
||||||
|
|
||||||
|
|
||||||
class TestRequiredIf:
|
|
||||||
def test_RequiredIf_requires_field_if_arg_is_truthy(self, dummy_form, dummy_field):
|
|
||||||
validator = RequiredIf(lambda form: True)
|
|
||||||
dummy_field.data = None
|
|
||||||
|
|
||||||
with pytest.raises(ValidationError):
|
|
||||||
validator(dummy_form, dummy_field)
|
|
||||||
|
|
||||||
def test_RequiredIf_does_not_require_field_if_arg_is_falsy(
|
|
||||||
self, dummy_form, dummy_field
|
|
||||||
):
|
|
||||||
validator = RequiredIf(lambda form: False)
|
|
||||||
dummy_field.data = None
|
|
||||||
|
|
||||||
with pytest.raises(StopValidation):
|
|
||||||
validator(dummy_form, dummy_field)
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileLength:
|
class TestFileLength:
|
||||||
def test_FileLength(self, dummy_form, dummy_field, pdf_upload):
|
def test_FileLength(self, dummy_form, dummy_field, pdf_upload):
|
||||||
validator = FileLength(max_length=1)
|
validator = FileLength(max_length=1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user