server/tags: output tag category usages

This commit is contained in:
rr- 2016-05-09 22:39:04 +02:00
parent fcbfa90879
commit a668d3ef34
5 changed files with 11 additions and 2 deletions

4
API.md
View File

@ -1403,7 +1403,8 @@ experience.
```json5 ```json5
{ {
"name": <name>, "name": <name>,
"color": <color> "color": <color>,
"usages": <usages>
} }
``` ```
@ -1411,6 +1412,7 @@ experience.
- `<name>`: the category name. - `<name>`: the category name.
- `<color>`: the category color. - `<color>`: the category color.
- `<usages>`: how many tags is the given category used with.
## Detailed tag category ## Detailed tag category
**Description** **Description**

View File

@ -18,6 +18,7 @@ def serialize_category(category):
return { return {
'name': category.name, 'name': category.name,
'color': category.color, 'color': category.color,
'usages': category.tag_count,
} }
def serialize_category_with_details(category): def serialize_category_with_details(category):

View File

@ -21,7 +21,11 @@ def test_creating_category(test_ctx):
test_ctx.context_factory( test_ctx.context_factory(
input={'name': 'meta', 'color': 'black'}, input={'name': 'meta', 'color': 'black'},
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
assert result['tagCategory'] == {'name': 'meta', 'color': 'black'} assert result['tagCategory'] == {
'name': 'meta',
'color': 'black',
'usages': 0,
}
assert len(result['snapshots']) == 1 assert len(result['snapshots']) == 1
category = db.session.query(db.TagCategory).one() category = db.session.query(db.TagCategory).one()
assert category.name == 'meta' assert category.name == 'meta'

View File

@ -41,6 +41,7 @@ def test_retrieving_single(test_ctx):
'tagCategory': { 'tagCategory': {
'name': 'cat', 'name': 'cat',
'color': 'dummy', 'color': 'dummy',
'usages': 0,
}, },
'snapshots': [], 'snapshots': [],
} }

View File

@ -40,6 +40,7 @@ def test_simple_updating(test_ctx):
assert result['tagCategory'] == { assert result['tagCategory'] == {
'name': 'changed', 'name': 'changed',
'color': 'white', 'color': 'white',
'usages': 0,
} }
assert len(result['snapshots']) == 1 assert len(result['snapshots']) == 1
assert tag_categories.try_get_category_by_name('name') is None assert tag_categories.try_get_category_by_name('name') is None