From 978a384d9eed75f410f5add5fc95cb78171b4ed9 Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Sun, 12 Jan 2020 12:18:53 -0500 Subject: [PATCH] server/tag-categories: order tag categories alphabetically when requested --- server/szurubooru/func/tag_categories.py | 5 +++-- server/szurubooru/tests/api/test_tag_retrieving.py | 2 +- server/szurubooru/tests/func/test_tag_categories.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/szurubooru/func/tag_categories.py b/server/szurubooru/func/tag_categories.py index bec2f0d..b6e0257 100644 --- a/server/szurubooru/func/tag_categories.py +++ b/server/szurubooru/func/tag_categories.py @@ -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( diff --git a/server/szurubooru/tests/api/test_tag_retrieving.py b/server/szurubooru/tests/api/test_tag_retrieving.py index 43a0766..c720b6e 100644 --- a/server/szurubooru/tests/api/test_tag_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_retrieving.py @@ -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' diff --git a/server/szurubooru/tests/func/test_tag_categories.py b/server/szurubooru/tests/func/test_tag_categories.py index d1e5570..d886703 100644 --- a/server/szurubooru/tests/func/test_tag_categories.py +++ b/server/szurubooru/tests/func/test_tag_categories.py @@ -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]