remove tags.json

This commit is contained in:
rr-
2017-10-01 21:46:53 +02:00
parent 253e28c1b5
commit 1c4c5c5f91
50 changed files with 448 additions and 633 deletions

View File

@ -73,7 +73,6 @@ def create_post(
for tag in new_tags:
snapshots.create(tag, None if anonymous else ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize_post(ctx, post)
@ -126,7 +125,6 @@ def update_post(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
ctx.session.flush()
snapshots.modify(post, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize_post(ctx, post)
@ -138,7 +136,6 @@ def delete_post(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
snapshots.delete(post, ctx.user)
posts.delete(post)
ctx.session.commit()
tags.export_to_json()
return {}

View File

@ -54,7 +54,6 @@ def create_tag(
ctx.session.flush()
snapshots.create(tag, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize(ctx, tag)
@ -95,7 +94,6 @@ def update_tag(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
ctx.session.flush()
snapshots.modify(tag, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize(ctx, tag)
@ -107,7 +105,6 @@ def delete_tag(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
snapshots.delete(tag, ctx.user)
tags.delete(tag)
ctx.session.commit()
tags.export_to_json()
return {}
@ -125,7 +122,6 @@ def merge_tags(
tags.merge_tags(source_tag, target_tag)
snapshots.merge(source_tag, target_tag, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize(ctx, target_tag)

View File

@ -31,7 +31,6 @@ def create_tag_category(
ctx.session.flush()
snapshots.create(category, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize(ctx, category)
@ -61,7 +60,6 @@ def update_tag_category(
ctx.session.flush()
snapshots.modify(category, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize(ctx, category)
@ -75,7 +73,6 @@ def delete_tag_category(
tag_categories.delete_category(category)
snapshots.delete(category, ctx.user)
ctx.session.commit()
tags.export_to_json()
return {}
@ -89,5 +86,4 @@ def set_tag_category_as_default(
ctx.session.flush()
snapshots.modify(category, ctx.user)
ctx.session.commit()
tags.export_to_json()
return _serialize(ctx, category)

View File

@ -224,7 +224,13 @@ class PostSerializer(serialization.BaseSerializer):
return self.post.flags
def serialize_tags(self) -> Any:
return [tag.names[0].name for tag in tags.sort_tags(self.post.tags)]
return [
{
'names': [name.name for name in tag.names],
'category': tag.category.name,
'usages': tag.post_count,
}
for tag in tags.sort_tags(self.post.tags)]
def serialize_relations(self) -> Any:
return sorted(

View File

@ -72,6 +72,14 @@ def sort_tags(tags: List[model.Tag]) -> List[model.Tag]:
)
def serialize_relation(tag):
return {
'names': [tag_name.name for tag_name in tag.names],
'category': tag.category.name,
'usages': tag.post_count,
}
class TagSerializer(serialization.BaseSerializer):
def __init__(self, tag: model.Tag) -> None:
self.tag = tag
@ -112,12 +120,12 @@ class TagSerializer(serialization.BaseSerializer):
def serialize_suggestions(self) -> Any:
return [
relation.names[0].name
serialize_relation(relation)
for relation in sort_tags(self.tag.suggestions)]
def serialize_implications(self) -> Any:
return [
relation.names[0].name
serialize_relation(relation)
for relation in sort_tags(self.tag.implications)]
@ -128,67 +136,6 @@ def serialize_tag(
return TagSerializer(tag).serialize(options)
def export_to_json() -> None:
tags = {} # type: Dict[int, Any]
categories = {} # type: Dict[int, Any]
for result in db.session.query(
model.TagCategory.tag_category_id,
model.TagCategory.name,
model.TagCategory.color).all():
categories[result[0]] = {
'name': result[1],
'color': result[2],
}
for result in (
db.session
.query(model.TagName.tag_id, model.TagName.name)
.order_by(model.TagName.order)
.all()):
if not result[0] in tags:
tags[result[0]] = {'names': []}
tags[result[0]]['names'].append(result[1])
for result in (
db.session
.query(model.TagSuggestion.parent_id, model.TagName.name)
.join(
model.TagName,
model.TagName.tag_id == model.TagSuggestion.child_id)
.all()):
if 'suggestions' not in tags[result[0]]:
tags[result[0]]['suggestions'] = []
tags[result[0]]['suggestions'].append(result[1])
for result in (
db.session
.query(model.TagImplication.parent_id, model.TagName.name)
.join(
model.TagName,
model.TagName.tag_id == model.TagImplication.child_id)
.all()):
if 'implications' not in tags[result[0]]:
tags[result[0]]['implications'] = []
tags[result[0]]['implications'].append(result[1])
for result in db.session.query(
model.Tag.tag_id,
model.Tag.category_id,
model.Tag.post_count).all():
tags[result[0]]['category'] = categories[result[1]]['name']
tags[result[0]]['usages'] = result[2]
output = {
'categories': list(categories.values()),
'tags': list(tags.values()),
}
export_path = os.path.join(config.config['data_dir'], 'tags.json')
with open(export_path, 'w') as handle:
handle.write(json.dumps(output, separators=(',', ':')))
def try_get_tag_by_name(name: str) -> Optional[model.Tag]:
return (
db.session

View File

@ -134,7 +134,7 @@ class Executor:
'offset': offset,
'limit': limit,
'total': count,
'results': [serializer(entity) for entity in entities],
'results': list([serializer(entity) for entity in entities]),
}
def _prepare_db_query(

View File

@ -30,7 +30,6 @@ def test_creating_minimal_posts(
patch('szurubooru.func.posts.update_post_flags'), \
patch('szurubooru.func.posts.update_post_thumbnail'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.snapshots.create'):
posts.create_post.return_value = (post, [])
posts.serialize_post.return_value = 'serialized post'
@ -62,7 +61,6 @@ def test_creating_minimal_posts(
posts.serialize_post.assert_called_once_with(
post, auth_user, options=[])
snapshots.create.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
def test_creating_full_posts(context_factory, post_factory, user_factory):
@ -78,7 +76,6 @@ def test_creating_full_posts(context_factory, post_factory, user_factory):
patch('szurubooru.func.posts.update_post_notes'), \
patch('szurubooru.func.posts.update_post_flags'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.snapshots.create'):
posts.create_post.return_value = (post, [])
posts.serialize_post.return_value = 'serialized post'
@ -111,7 +108,6 @@ def test_creating_full_posts(context_factory, post_factory, user_factory):
posts.serialize_post.assert_called_once_with(
post, auth_user, options=[])
snapshots.create.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
def test_anonymous_uploads(
@ -121,8 +117,7 @@ def test_anonymous_uploads(
db.session.add(post)
db.session.flush()
with patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.posts.serialize_post'), \
with patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.create_post'), \
patch('szurubooru.func.posts.update_post_source'):
config_injector({
@ -152,7 +147,6 @@ def test_creating_from_url_saves_source(
db.session.flush()
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.create_post'), \
patch('szurubooru.func.posts.update_post_source'):
@ -183,7 +177,6 @@ def test_creating_from_url_with_source_specified(
db.session.flush()
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.create_post'), \
patch('szurubooru.func.posts.update_post_source'):
@ -245,7 +238,6 @@ def test_omitting_optional_field(
patch('szurubooru.func.posts.update_post_notes'), \
patch('szurubooru.func.posts.update_post_flags'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.snapshots.create'):
posts.create_post.return_value = (post, [])
posts.serialize_post.return_value = 'serialized post'

View File

@ -14,15 +14,13 @@ def test_deleting(user_factory, post_factory, context_factory):
post = post_factory(id=1)
db.session.add(post)
db.session.flush()
with patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.snapshots.delete'):
with patch('szurubooru.func.snapshots.delete'):
result = api.post_api.delete_post(
context_factory(params={'version': 1}, user=auth_user),
{'post_id': 1})
assert result == {}
assert db.session.query(model.Post).count() == 0
snapshots.delete.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
def test_trying_to_delete_non_existing(user_factory, context_factory):

View File

@ -39,7 +39,6 @@ def test_post_updating(
patch('szurubooru.func.posts.update_post_notes'), \
patch('szurubooru.func.posts.update_post_flags'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.snapshots.modify'), \
fake_datetime('1997-01-01'):
posts.serialize_post.return_value = 'serialized post'
@ -78,7 +77,6 @@ def test_post_updating(
posts.serialize_post.assert_called_once_with(
post, auth_user, options=[])
snapshots.modify.assert_called_once_with(post, auth_user)
tags.export_to_json.assert_called_once_with()
assert post.last_edit_time == datetime(1997, 1, 1)
@ -88,7 +86,6 @@ def test_uploading_from_url_saves_source(
db.session.add(post)
db.session.flush()
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.update_post_content'), \
patch('szurubooru.func.posts.update_post_source'), \
@ -110,7 +107,6 @@ def test_uploading_from_url_with_source_specified(
db.session.add(post)
db.session.flush()
with patch('szurubooru.func.net.download'), \
patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.posts.serialize_post'), \
patch('szurubooru.func.posts.update_post_content'), \
patch('szurubooru.func.posts.update_post_source'), \

View File

@ -24,8 +24,7 @@ def test_creating_category(
with patch('szurubooru.func.tag_categories.create_category'), \
patch('szurubooru.func.tag_categories.serialize_category'), \
patch('szurubooru.func.tag_categories.update_category_name'), \
patch('szurubooru.func.snapshots.create'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.snapshots.create'):
tag_categories.create_category.return_value = category
tag_categories.update_category_name.side_effect = _update_category_name
tag_categories.serialize_category.return_value = 'serialized category'
@ -35,7 +34,6 @@ def test_creating_category(
assert result == 'serialized category'
tag_categories.create_category.assert_called_once_with('meta', 'black')
snapshots.create.assert_called_once_with(category, auth_user)
tags.export_to_json.assert_called_once_with()
@pytest.mark.parametrize('field', ['name', 'color'])

View File

@ -17,8 +17,7 @@ def test_deleting(user_factory, tag_category_factory, context_factory):
db.session.add(tag_category_factory(name='root'))
db.session.add(category)
db.session.flush()
with patch('szurubooru.func.snapshots.delete'), \
patch('szurubooru.func.tags.export_to_json'):
with patch('szurubooru.func.snapshots.delete'):
result = api.tag_category_api.delete_tag_category(
context_factory(params={'version': 1}, user=auth_user),
{'category_name': 'category'})
@ -26,7 +25,6 @@ def test_deleting(user_factory, tag_category_factory, context_factory):
assert db.session.query(model.TagCategory).count() == 1
assert db.session.query(model.TagCategory).one().name == 'root'
snapshots.delete.assert_called_once_with(category, auth_user)
tags.export_to_json.assert_called_once_with()
def test_trying_to_delete_used(

View File

@ -27,8 +27,7 @@ def test_simple_updating(user_factory, tag_category_factory, context_factory):
with patch('szurubooru.func.tag_categories.serialize_category'), \
patch('szurubooru.func.tag_categories.update_category_name'), \
patch('szurubooru.func.tag_categories.update_category_color'), \
patch('szurubooru.func.snapshots.modify'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.snapshots.modify'):
tag_categories.update_category_name.side_effect = _update_category_name
tag_categories.serialize_category.return_value = 'serialized category'
result = api.tag_category_api.update_tag_category(
@ -42,7 +41,6 @@ def test_simple_updating(user_factory, tag_category_factory, context_factory):
tag_categories.update_category_color.assert_called_once_with(
category, 'white')
snapshots.modify.assert_called_once_with(category, auth_user)
tags.export_to_json.assert_called_once_with()
@pytest.mark.parametrize('field', ['name', 'color'])
@ -56,8 +54,7 @@ def test_omitting_optional_field(
}
del params[field]
with patch('szurubooru.func.tag_categories.serialize_category'), \
patch('szurubooru.func.tag_categories.update_category_name'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.tag_categories.update_category_name'):
api.tag_category_api.update_tag_category(
context_factory(
params={**params, **{'version': 1}},
@ -95,8 +92,7 @@ def test_set_as_default(user_factory, tag_category_factory, context_factory):
db.session.add(category)
db.session.commit()
with patch('szurubooru.func.tag_categories.serialize_category'), \
patch('szurubooru.func.tag_categories.set_default_category'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.tag_categories.set_default_category'):
tag_categories.update_category_name.side_effect = _update_category_name
tag_categories.serialize_category.return_value = 'serialized category'
result = api.tag_category_api.set_tag_category_as_default(

View File

@ -15,8 +15,7 @@ def test_creating_simple_tags(tag_factory, user_factory, context_factory):
with patch('szurubooru.func.tags.create_tag'), \
patch('szurubooru.func.tags.get_or_create_tags_by_names'), \
patch('szurubooru.func.tags.serialize_tag'), \
patch('szurubooru.func.snapshots.create'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.snapshots.create'):
tags.get_or_create_tags_by_names.return_value = ([], [])
tags.create_tag.return_value = tag
tags.serialize_tag.return_value = 'serialized tag'
@ -34,7 +33,6 @@ def test_creating_simple_tags(tag_factory, user_factory, context_factory):
tags.create_tag.assert_called_once_with(
['tag1', 'tag2'], 'meta', ['sug1', 'sug2'], ['imp1', 'imp2'])
snapshots.create.assert_called_once_with(tag, auth_user)
tags.export_to_json.assert_called_once_with()
@pytest.mark.parametrize('field', ['names', 'category'])
@ -64,8 +62,7 @@ def test_omitting_optional_field(
}
del params[field]
with patch('szurubooru.func.tags.create_tag'), \
patch('szurubooru.func.tags.serialize_tag'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.tags.serialize_tag'):
tags.create_tag.return_value = tag_factory()
api.tag_api.create_tag(
context_factory(

View File

@ -14,15 +14,13 @@ def test_deleting(user_factory, tag_factory, context_factory):
tag = tag_factory(names=['tag'])
db.session.add(tag)
db.session.commit()
with patch('szurubooru.func.tags.export_to_json'), \
patch('szurubooru.func.snapshots.delete'):
with patch('szurubooru.func.snapshots.delete'):
result = api.tag_api.delete_tag(
context_factory(params={'version': 1}, user=auth_user),
{'tag_name': 'tag'})
assert result == {}
assert db.session.query(model.Tag).count() == 0
snapshots.delete.assert_called_once_with(tag, auth_user)
tags.export_to_json.assert_called_once_with()
def test_deleting_used(
@ -32,15 +30,14 @@ def test_deleting_used(
post.tags.append(tag)
db.session.add_all([tag, post])
db.session.commit()
with patch('szurubooru.func.tags.export_to_json'):
api.tag_api.delete_tag(
context_factory(
params={'version': 1},
user=user_factory(rank=model.User.RANK_REGULAR)),
{'tag_name': 'tag'})
db.session.refresh(post)
assert db.session.query(model.Tag).count() == 0
assert post.tags == []
api.tag_api.delete_tag(
context_factory(
params={'version': 1},
user=user_factory(rank=model.User.RANK_REGULAR)),
{'tag_name': 'tag'})
db.session.refresh(post)
assert db.session.query(model.Tag).count() == 0
assert post.tags == []
def test_trying_to_delete_non_existing(user_factory, context_factory):

View File

@ -25,8 +25,7 @@ def test_merging(user_factory, tag_factory, context_factory, post_factory):
assert target_tag.post_count == 0
with patch('szurubooru.func.tags.serialize_tag'), \
patch('szurubooru.func.tags.merge_tags'), \
patch('szurubooru.func.snapshots.merge'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.snapshots.merge'):
api.tag_api.merge_tags(
context_factory(
params={
@ -39,7 +38,6 @@ def test_merging(user_factory, tag_factory, context_factory, post_factory):
tags.merge_tags.called_once_with(source_tag, target_tag)
snapshots.merge.assert_called_once_with(
source_tag, target_tag, auth_user)
tags.export_to_json.assert_called_once_with()
@pytest.mark.parametrize(

View File

@ -31,8 +31,7 @@ def test_simple_updating(user_factory, tag_factory, context_factory):
patch('szurubooru.func.tags.update_tag_suggestions'), \
patch('szurubooru.func.tags.update_tag_implications'), \
patch('szurubooru.func.tags.serialize_tag'), \
patch('szurubooru.func.snapshots.modify'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.snapshots.modify'):
tags.get_or_create_tags_by_names.return_value = ([], [])
tags.serialize_tag.return_value = 'serialized tag'
result = api.tag_api.update_tag(
@ -58,7 +57,6 @@ def test_simple_updating(user_factory, tag_factory, context_factory):
tag, ['imp1', 'imp2'])
tags.serialize_tag.assert_called_once_with(tag, options=[])
snapshots.modify.assert_called_once_with(tag, auth_user)
tags.export_to_json.assert_called_once_with()
@pytest.mark.parametrize(
@ -84,8 +82,7 @@ def test_omitting_optional_field(
with patch('szurubooru.func.tags.create_tag'), \
patch('szurubooru.func.tags.update_tag_names'), \
patch('szurubooru.func.tags.update_tag_category_name'), \
patch('szurubooru.func.tags.serialize_tag'), \
patch('szurubooru.func.tags.export_to_json'):
patch('szurubooru.func.tags.serialize_tag'):
api.tag_api.update_tag(
context_factory(
params={**params, **{'version': 1}},

View File

@ -75,7 +75,11 @@ def test_serialize_post_when_empty():
def test_serialize_post(
user_factory, comment_factory, tag_factory, config_injector):
user_factory,
comment_factory,
tag_factory,
tag_category_factory,
config_injector):
config_injector({'data_url': 'http://example.com/', 'secret': 'test'})
with patch('szurubooru.func.comments.serialize_comment'), \
patch('szurubooru.func.users.serialize_micro_user'), \
@ -92,8 +96,12 @@ def test_serialize_post(
post.creation_time = datetime(1997, 1, 1)
post.last_edit_time = datetime(1998, 1, 1)
post.tags = [
tag_factory(names=['tag1', 'tag2']),
tag_factory(names=['tag3'])
tag_factory(
names=['tag1', 'tag2'],
category=tag_category_factory('test-cat1')),
tag_factory(
names=['tag3'],
category=tag_category_factory('test-cat2'))
]
post.safety = model.Post.SAFETY_SAFE
post.source = '4gag'
@ -143,7 +151,7 @@ def test_serialize_post(
db.session.flush()
result = posts.serialize_post(post, auth_user)
result['tags'].sort()
result['tags'].sort(key=lambda tag: tag['names'][0])
assert result == {
'id': 1,
@ -162,7 +170,17 @@ def test_serialize_post(
'http://example.com/'
'generated-thumbnails/1_244c8840887984c4.jpg',
'flags': ['loop'],
'tags': ['tag1', 'tag3'],
'tags': [
{
'names': ['tag1', 'tag2'],
'category': 'test-cat1', 'usages': 1,
},
{
'names': ['tag3'],
'category': 'test-cat2',
'usages': 1,
},
],
'relations': [],
'notes': [],
'user': 'post author',

View File

@ -45,15 +45,18 @@ def test_serialize_tag_when_empty():
def test_serialize_tag(post_factory, tag_factory, tag_category_factory):
tag = tag_factory(
names=['tag1', 'tag2'],
category=tag_category_factory(name='cat'))
cat = tag_category_factory(name='cat')
tag = tag_factory(names=['tag1', 'tag2'], category=cat)
tag.tag_id = 1
tag.description = 'description'
tag.suggestions = [
tag_factory(names=['sug1']), tag_factory(names=['sug2'])]
tag_factory(names=['sug1'], category=cat),
tag_factory(names=['sug2'], category=cat),
]
tag.implications = [
tag_factory(names=['impl1']), tag_factory(names=['impl2'])]
tag_factory(names=['impl1'], category=cat),
tag_factory(names=['impl2'], category=cat),
]
tag.last_edit_time = datetime(1998, 1, 1)
post1 = post_factory()
post2 = post_factory()
@ -62,8 +65,8 @@ def test_serialize_tag(post_factory, tag_factory, tag_category_factory):
db.session.add_all([tag, post1, post2])
db.session.flush()
result = tags.serialize_tag(tag)
result['suggestions'].sort()
result['implications'].sort()
result['suggestions'].sort(key=lambda relation: relation['names'][0])
result['implications'].sort(key=lambda relation: relation['names'][0])
assert result == {
'names': ['tag1', 'tag2'],
'version': 1,
@ -71,69 +74,18 @@ def test_serialize_tag(post_factory, tag_factory, tag_category_factory):
'creationTime': datetime(1996, 1, 1, 0, 0),
'lastEditTime': datetime(1998, 1, 1, 0, 0),
'description': 'description',
'suggestions': ['sug1', 'sug2'],
'implications': ['impl1', 'impl2'],
'suggestions': [
{'names': ['sug1'], 'category': 'cat', 'usages': 0},
{'names': ['sug2'], 'category': 'cat', 'usages': 0},
],
'implications': [
{'names': ['impl1'], 'category': 'cat', 'usages': 0},
{'names': ['impl2'], 'category': 'cat', 'usages': 0},
],
'usages': 2,
}
def test_export_to_json(
tmpdir,
query_counter,
config_injector,
post_factory,
tag_factory,
tag_category_factory):
config_injector({'data_dir': str(tmpdir)})
cat1 = tag_category_factory(name='cat1', color='black')
cat2 = tag_category_factory(name='cat2', color='white')
tag = tag_factory(names=['alias1', 'alias2'], category=cat2)
tag.suggestions = [
tag_factory(names=['sug1'], category=cat1),
tag_factory(names=['sug2'], category=cat1),
]
tag.implications = [
tag_factory(names=['imp1'], category=cat1),
tag_factory(names=['imp2'], category=cat1),
]
post = post_factory()
post.tags = [tag]
db.session.add_all([post, tag])
db.session.flush()
with query_counter:
tags.export_to_json()
assert len(query_counter.statements) == 5
export_path = os.path.join(str(tmpdir), 'tags.json')
assert os.path.exists(export_path)
with open(export_path, 'r') as handle:
actual_json = json.loads(handle.read())
assert actual_json['tags']
assert actual_json['categories']
actual_json['tags'].sort(key=lambda tag: tag['names'][0])
actual_json['categories'].sort(key=lambda category: category['name'])
assert actual_json == {
'tags': [
{
'names': ['alias1', 'alias2'],
'usages': 1,
'category': 'cat2',
'suggestions': ['sug1', 'sug2'],
'implications': ['imp1', 'imp2'],
},
{'names': ['imp1'], 'usages': 0, 'category': 'cat1'},
{'names': ['imp2'], 'usages': 0, 'category': 'cat1'},
{'names': ['sug1'], 'usages': 0, 'category': 'cat1'},
{'names': ['sug2'], 'usages': 0, 'category': 'cat1'},
],
'categories': [
{'name': 'cat1', 'color': 'black'},
{'name': 'cat2', 'color': 'white'},
]
}
@pytest.mark.parametrize('name_to_search,expected_to_find', [
('name', True),
('NAME', True),