Skip to content

Commit 8db0c06

Browse files
committed
Use string_required validator for content field
Also make the string_required validator trim whitespace and then check that the string is empty.
1 parent 3a34bb9 commit 8db0c06

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

framework/mongo/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def string_required(value):
9-
if value is None or value == '':
9+
if value is None or value.strip() == '':
1010
raise ValidationValueError('Value must not be empty.')
1111
return True
1212

tests/test_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,7 +4160,7 @@ def test_create_comment_content_cannot_be_empty(self):
41604160
is_public=True,
41614161
content=''
41624162
)
4163-
assert_equal(error.exception.message, 'Ensure this value is not empty.')
4163+
assert_equal(error.exception.message, 'Value must not be empty.')
41644164

41654165
def test_create_comment_content_cannot_be_whitespace(self):
41664166
with assert_raises(ValidationValueError) as error:
@@ -4172,7 +4172,7 @@ def test_create_comment_content_cannot_be_whitespace(self):
41724172
is_public=True,
41734173
content=' '
41744174
)
4175-
assert_equal(error.exception.message, 'Ensure this value is not empty.')
4175+
assert_equal(error.exception.message, 'Value must not be empty.')
41764176

41774177
def test_create_sends_comment_added_signal(self):
41784178
with capture_signals() as mock_signals:

website/project/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from modularodm import Q
1919
from modularodm import fields
20-
from modularodm.validators import MaxLengthValidator, ValueNotEmptyValidator
20+
from modularodm.validators import MaxLengthValidator
2121
from modularodm.exceptions import NoResultsFound
2222
from modularodm.exceptions import ValidationTypeError
2323
from modularodm.exceptions import ValidationValueError
@@ -181,7 +181,7 @@ class Comment(GuidStoredObject):
181181

182182
is_deleted = fields.BooleanField(default=False)
183183
content = fields.StringField(required=True,
184-
validate=(MaxLengthValidator(settings.COMMENT_MAXLENGTH), ValueNotEmptyValidator()))
184+
validate=[MaxLengthValidator(settings.COMMENT_MAXLENGTH), validators.string_required])
185185

186186
# Dictionary field mapping user IDs to dictionaries of report details:
187187
# {

0 commit comments

Comments
 (0)