Skip to content

Commit

Permalink
Merge pull request #85 from xsnippet/no-empty-snippets
Browse files Browse the repository at this point in the history
Do not allow empty snippets
  • Loading branch information
ikalnytskyi committed Apr 26, 2018
2 parents 7f672c1 + 7ed2d5e commit a6cd909
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/resources/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ async def test_post_snippet(testapp, testconf, snippet, rv):
{'content': 42},
{'message': '`content` - must be of string type.'},
),
(
{'content': ''},
{'message': '`content` - empty values not allowed.'},
),
(
{'content': 'test', 'tags': ['white space']},
{'message': '`tags` - {0: ["value does not match regex \'[\\\\w_-]+\'"]}.'},
Expand Down Expand Up @@ -713,6 +717,10 @@ async def test_put_snippet_not_found(testapp):
{'content': 42},
{'message': '`content` - must be of string type.'},
),
(
{'content': ''},
{'message': '`content` - empty values not allowed.'},
),
(
{'content': 'test', 'tags': ['white space']},
{'message': '`tags` - {0: ["value does not match regex \'[\\\\w_-]+\'"]}.'},
Expand Down Expand Up @@ -783,6 +791,10 @@ async def test_patch_snippet_not_found(testapp):
{'content': 42},
{'message': '`content` - must be of string type.'},
),
(
{'content': ''},
{'message': '`content` - empty values not allowed.'},
),
(
{'tags': ['white space']},
{'message': '`tags` - {0: ["value does not match regex \'[\\\\w_-]+\'"]}.'},
Expand Down
2 changes: 1 addition & 1 deletion xsnippet/api/resources/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def _write(resource, service_fn, *, status, conf):
v = cerberus.Validator({
'id': {'type': 'integer', 'readonly': True},
'title': {'type': 'string'},
'content': {'type': 'string', 'required': True},
'content': {'type': 'string', 'required': True, 'empty': False},
'syntax': {'type': 'string'},
'tags': {'type': 'list',
'schema': {'type': 'string', 'regex': '[\w_-]+'}},
Expand Down

0 comments on commit a6cd909

Please sign in to comment.