aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/tests/api
diff options
context:
space:
mode:
authorrr-2016-07-03 15:48:39 +0200
committerrr-2016-07-03 18:30:32 +0200
commit5800f0ebc7ab9702b3315d5aeb5c4ba4645cbb7f (patch)
tree14c8b812e8bcf8ddf9985153efe1fccbbdc7d79f /server/szurubooru/tests/api
parentaf36c90618ec5ec476c0001166afa878c53cacc0 (diff)
server/tags: fix merging tags
It violated unique constraint on post_tag when a given post was already tagged with the target tag.
Diffstat (limited to 'server/szurubooru/tests/api')
-rw-r--r--server/szurubooru/tests/api/test_tag_merging.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/server/szurubooru/tests/api/test_tag_merging.py b/server/szurubooru/tests/api/test_tag_merging.py
index e213882..7b03f11 100644
--- a/server/szurubooru/tests/api/test_tag_merging.py
+++ b/server/szurubooru/tests/api/test_tag_merging.py
@@ -98,6 +98,28 @@ def test_merging_when_related(test_ctx, fake_datetime):
assert tags.try_get_tag_by_name('parent').implications == []
assert tags.try_get_tag_by_name('parent').suggestions == []
+def test_merging_when_target_exists(test_ctx, fake_datetime, post_factory):
+ source_tag = test_ctx.tag_factory(names=['source'], category_name='meta')
+ target_tag = test_ctx.tag_factory(names=['target'], category_name='meta')
+ db.session.add_all([source_tag, target_tag])
+ db.session.flush()
+ post1 = post_factory()
+ post1.tags = [source_tag, target_tag]
+ db.session.add_all([post1])
+ db.session.commit()
+ assert source_tag.post_count == 1
+ assert target_tag.post_count == 1
+ with fake_datetime('1997-12-01'):
+ result = test_ctx.api.post(
+ test_ctx.context_factory(
+ input={
+ 'remove': 'source',
+ 'mergeTo': 'target',
+ },
+ user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
+ assert tags.try_get_tag_by_name('source') is None
+ assert tags.get_tag_by_name('target').post_count == 1
+
@pytest.mark.parametrize('input,expected_exception', [
({'remove': None}, tags.TagNotFoundError),
({'remove': ''}, tags.TagNotFoundError),

© 2015 - 2026 Jakob L. Kreuze