server/tag-categories: order tag categories alphabetically when requested

This commit is contained in:
Shyam Sunder 2020-01-12 12:18:53 -05:00
parent 53ec25f4c4
commit 978a384d9e
3 changed files with 6 additions and 5 deletions

View file

@ -131,11 +131,12 @@ def get_category_by_name(name: str, lock: bool = False) -> model.TagCategory:
def get_all_category_names() -> List[str]:
return [row[0] for row in db.session.query(model.TagCategory.name).all()]
return [cat.name for cat in get_all_categories()]
def get_all_categories() -> List[model.TagCategory]:
return db.session.query(model.TagCategory).all()
return db.session.query(model.TagCategory).order_by(
model.TagCategory.name.asc()).all()
def try_get_default_category(

View file

@ -17,7 +17,7 @@ def inject_config(config_injector):
def test_retrieving_multiple(user_factory, tag_factory, context_factory):
tag1 = tag_factory(names=['t1'])
tag2 = tag_factory(names=['t2'])
db.session.add_all([tag1, tag2])
db.session.add_all([tag2, tag1])
db.session.flush()
with patch('szurubooru.func.tags.serialize_tag'):
tags.serialize_tag.return_value = 'serialized tag'

View file

@ -148,7 +148,7 @@ def test_get_category_by_name(tag_category_factory):
def test_get_all_category_names(tag_category_factory):
category1 = tag_category_factory(name='cat1')
category2 = tag_category_factory(name='cat2')
db.session.add_all([category1, category2])
db.session.add_all([category2, category1])
db.session.flush()
assert tag_categories.get_all_category_names() == ['cat1', 'cat2']
@ -156,7 +156,7 @@ def test_get_all_category_names(tag_category_factory):
def test_get_all_categories(tag_category_factory):
category1 = tag_category_factory(name='cat1')
category2 = tag_category_factory(name='cat2')
db.session.add_all([category1, category2])
db.session.add_all([category2, category1])
db.session.flush()
assert tag_categories.get_all_categories() == [category1, category2]