-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't allow group names with leading or trailing whitespace #8834
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,34 @@ def test_it_raises_if_name_too_long(self, schema): | |
with pytest.raises(ValidationError, match="name:.*is too long"): | ||
schema.validate({"name": "o" * (GROUP_NAME_MAX_LENGTH + 1)}) | ||
|
||
def test_it_raises_if_name_isnt_a_string(self, schema): | ||
name = 42 | ||
|
||
with pytest.raises( | ||
ValidationError, match=f"name: {name} is not of type 'string'" | ||
): | ||
schema.validate({"name": name}) | ||
Comment on lines
+43
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When calling string methods like |
||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
[ | ||
f" {'o' * GROUP_NAME_MIN_LENGTH}", | ||
f"{'o' * GROUP_NAME_MIN_LENGTH} ", | ||
" " * GROUP_NAME_MIN_LENGTH, | ||
], | ||
) | ||
def test_it_raises_if_name_has_leading_or_trailing_whitespace(self, schema, name): | ||
with pytest.raises( | ||
ValidationError, | ||
match="Group names can't have leading or trailing whitespace.", | ||
): | ||
schema.validate({"name": name}) | ||
|
||
def test_it_validates_with_no_data(self, schema): | ||
appstruct = schema.validate({}) | ||
|
||
assert appstruct == {} | ||
Comment on lines
+66
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_it_validates_with_valid_name(self, schema): | ||
appstruct = schema.validate({"name": "Perfectly Fine"}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tests for the sad path here, but what about the happy path? If I copy some text with leading/trailing whitespace and paste it into the name field, the group name should be trimmed, assuming it is neither too short nor too long.