server/tag-categories: correct exception type

This commit is contained in:
rr- 2016-08-14 10:17:31 +02:00
parent 92075bb455
commit 3db4f39545
2 changed files with 11 additions and 11 deletions

View File

@ -53,9 +53,9 @@ def update_category_name(category, name):
def update_category_color(category, color): def update_category_color(category, color):
if not color: if not color:
raise InvalidTagCategoryNameError('Color cannot be empty.') raise InvalidTagCategoryColorError('Color cannot be empty.')
if not re.match(r'^#?[0-9a-z]+$', color): if not re.match(r'^#?[0-9a-z]+$', color):
raise InvalidTagCategoryNameError('Invalid color.') raise InvalidTagCategoryColorError('Invalid color.')
if util.value_exceeds_column_size(color, db.TagCategory.color): if util.value_exceeds_column_size(color, db.TagCategory.color):
raise InvalidTagCategoryColorError('Color is too long.') raise InvalidTagCategoryColorError('Color is too long.')
category.color = color category.color = color

View File

@ -54,18 +54,18 @@ def test_simple_updating(test_ctx):
assert category.color == 'white' assert category.color == 'white'
assert os.path.exists(os.path.join(config.config['data_dir'], 'tags.json')) assert os.path.exists(os.path.join(config.config['data_dir'], 'tags.json'))
@pytest.mark.parametrize('input', [ @pytest.mark.parametrize('input,expected_exception', [
{'name': None}, ({'name': None}, tag_categories.InvalidTagCategoryNameError),
{'name': ''}, ({'name': ''}, tag_categories.InvalidTagCategoryNameError),
{'name': '!bad'}, ({'name': '!bad'}, tag_categories.InvalidTagCategoryNameError),
{'color': None}, ({'color': None}, tag_categories.InvalidTagCategoryColorError),
{'color': ''}, ({'color': ''}, tag_categories.InvalidTagCategoryColorError),
{'color': '; float:left'}, ({'color': '; float:left'}, tag_categories.InvalidTagCategoryColorError),
]) ])
def test_trying_to_pass_invalid_input(test_ctx, input): def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
db.session.add(test_ctx.tag_category_factory(name='meta', color='black')) db.session.add(test_ctx.tag_category_factory(name='meta', color='black'))
db.session.commit() db.session.commit()
with pytest.raises(tag_categories.InvalidTagCategoryNameError): with pytest.raises(expected_exception):
test_ctx.api.put( test_ctx.api.put(
test_ctx.context_factory( test_ctx.context_factory(
input={**input, **{'version': 1}}, input={**input, **{'version': 1}},