server/tags: fix getting default category name

No categories? Should have thrown an error rather than returning None.
This commit is contained in:
rr- 2017-02-02 20:03:24 +01:00
parent cce543e0b6
commit e92bd2fd80
2 changed files with 4 additions and 3 deletions

View file

@ -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

View file

@ -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):