From e92bd2fd8007cde5b5e6f39d9ece09cb4119c468 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 2 Feb 2017 20:03:24 +0100 Subject: [PATCH] server/tags: fix getting default category name No categories? Should have thrown an error rather than returning None. --- server/szurubooru/func/tag_categories.py | 4 ++-- server/szurubooru/tests/func/test_tag_categories.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/szurubooru/func/tag_categories.py b/server/szurubooru/func/tag_categories.py index bca15df2..a9169dec 100644 --- a/server/szurubooru/func/tag_categories.py +++ b/server/szurubooru/func/tag_categories.py @@ -139,8 +139,8 @@ def get_default_category(lock=False): def get_default_category_name(): if cache.has(DEFAULT_CATEGORY_NAME_CACHE_KEY): return cache.get(DEFAULT_CATEGORY_NAME_CACHE_KEY) - default_category = try_get_default_category() - default_category_name = default_category.name if default_category else None + default_category = get_default_category() + default_category_name = default_category.name cache.put(DEFAULT_CATEGORY_NAME_CACHE_KEY, default_category_name) return default_category_name diff --git a/server/szurubooru/tests/func/test_tag_categories.py b/server/szurubooru/tests/func/test_tag_categories.py index 70f0aa0e..cf74c2a5 100644 --- a/server/szurubooru/tests/func/test_tag_categories.py +++ b/server/szurubooru/tests/func/test_tag_categories.py @@ -193,7 +193,8 @@ def test_get_default_category_name(tag_category_factory): assert tag_categories.get_default_category_name() == category1.name db.session.query(db.TagCategory).delete() cache.purge() - assert tag_categories.get_default_category_name() is None + with pytest.raises(tag_categories.TagCategoryNotFoundError): + tag_categories.get_default_category_name() def test_get_default_category_name_caching(tag_category_factory):