server/tag-categories: correct exception type
This commit is contained in:
parent
92075bb455
commit
3db4f39545
|
@ -53,9 +53,9 @@ def update_category_name(category, name):
|
|||
|
||||
def update_category_color(category, 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):
|
||||
raise InvalidTagCategoryNameError('Invalid color.')
|
||||
raise InvalidTagCategoryColorError('Invalid color.')
|
||||
if util.value_exceeds_column_size(color, db.TagCategory.color):
|
||||
raise InvalidTagCategoryColorError('Color is too long.')
|
||||
category.color = color
|
||||
|
|
|
@ -54,18 +54,18 @@ def test_simple_updating(test_ctx):
|
|||
assert category.color == 'white'
|
||||
assert os.path.exists(os.path.join(config.config['data_dir'], 'tags.json'))
|
||||
|
||||
@pytest.mark.parametrize('input', [
|
||||
{'name': None},
|
||||
{'name': ''},
|
||||
{'name': '!bad'},
|
||||
{'color': None},
|
||||
{'color': ''},
|
||||
{'color': '; float:left'},
|
||||
@pytest.mark.parametrize('input,expected_exception', [
|
||||
({'name': None}, tag_categories.InvalidTagCategoryNameError),
|
||||
({'name': ''}, tag_categories.InvalidTagCategoryNameError),
|
||||
({'name': '!bad'}, tag_categories.InvalidTagCategoryNameError),
|
||||
({'color': None}, tag_categories.InvalidTagCategoryColorError),
|
||||
({'color': ''}, tag_categories.InvalidTagCategoryColorError),
|
||||
({'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.commit()
|
||||
with pytest.raises(tag_categories.InvalidTagCategoryNameError):
|
||||
with pytest.raises(expected_exception):
|
||||
test_ctx.api.put(
|
||||
test_ctx.context_factory(
|
||||
input={**input, **{'version': 1}},
|
||||
|
|
Loading…
Reference in New Issue