From 3db4f3954534a615652dbefcda261523d98a72d3 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 14 Aug 2016 10:17:31 +0200 Subject: [PATCH] server/tag-categories: correct exception type --- server/szurubooru/func/tag_categories.py | 4 ++-- .../tests/api/test_tag_category_updating.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/szurubooru/func/tag_categories.py b/server/szurubooru/func/tag_categories.py index 68efaa4..ea84b8a 100644 --- a/server/szurubooru/func/tag_categories.py +++ b/server/szurubooru/func/tag_categories.py @@ -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 diff --git a/server/szurubooru/tests/api/test_tag_category_updating.py b/server/szurubooru/tests/api/test_tag_category_updating.py index c1bdefe..78b0996 100644 --- a/server/szurubooru/tests/api/test_tag_category_updating.py +++ b/server/szurubooru/tests/api/test_tag_category_updating.py @@ -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}},