mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-07-01 18:13:35 +00:00
fix: fix tag aliases (#1399)
* fix: fix tag aliases * chore: remove logger statements from tag panel test * chore: very important fix * chore: remove commented-out code
This commit is contained in:
committed by
GitHub
parent
4da6037cbd
commit
e509e247d5
@@ -22,7 +22,7 @@ def test_build_tag_panel_add_sub_tag_callback(
|
||||
panel: BuildTagPanel = BuildTagPanel(library, child)
|
||||
qtbot.addWidget(panel)
|
||||
|
||||
panel.add_parent_tag_callback(parent.id)
|
||||
panel._add_parent_tag_callback(parent.id) # pyright: ignore[reportPrivateUsage]
|
||||
|
||||
assert len(panel.parent_ids) == 1
|
||||
|
||||
@@ -33,14 +33,14 @@ def test_build_tag_panel_remove_subtag_callback(
|
||||
parent = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
child = unwrap(library.add_tag(generate_tag("xx", id=124)))
|
||||
|
||||
library.update_tag(child, {parent.id}, [], [])
|
||||
library.update_tag(child, {parent.id}, [])
|
||||
|
||||
child = unwrap(library.get_tag(child.id))
|
||||
|
||||
panel: BuildTagPanel = BuildTagPanel(library, child)
|
||||
qtbot.addWidget(panel)
|
||||
|
||||
panel.remove_parent_tag_callback(parent.id)
|
||||
panel._remove_parent_tag_callback(parent.id) # pyright: ignore[reportPrivateUsage]
|
||||
|
||||
assert len(panel.parent_ids) == 0
|
||||
|
||||
@@ -58,7 +58,7 @@ def test_build_tag_panel_add_alias_callback(
|
||||
panel: BuildTagPanel = BuildTagPanel(library, tag)
|
||||
qtbot.addWidget(panel)
|
||||
|
||||
panel.add_alias_callback()
|
||||
panel._create_alias_callback() # pyright: ignore[reportPrivateUsage]
|
||||
|
||||
assert panel.aliases_table.rowCount() == 1
|
||||
|
||||
@@ -68,7 +68,9 @@ def test_build_tag_panel_remove_alias_callback(
|
||||
):
|
||||
tag: Tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
|
||||
library.update_tag(tag, [], {"alias", "alias_2"}, {123, 124})
|
||||
alias_1 = TagAlias("alias", tag.id)
|
||||
alias_2 = TagAlias("alias_2", tag.id)
|
||||
library.update_tag(tag, [], {alias_1, alias_2})
|
||||
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
|
||||
@@ -79,12 +81,11 @@ def test_build_tag_panel_remove_alias_callback(
|
||||
qtbot.addWidget(panel)
|
||||
|
||||
alias: TagAlias = unwrap(library.get_alias(tag.id, tag.alias_ids[0]))
|
||||
panel.remove_alias_callback(alias)
|
||||
|
||||
panel.remove_alias_callback(alias.id)
|
||||
|
||||
assert len(panel.alias_ids) == 1
|
||||
assert len(panel.alias_names) == 1
|
||||
assert alias.name not in panel.alias_names
|
||||
assert len(panel.aliases) == 1
|
||||
assert alias not in panel.aliases
|
||||
assert (alias.id, alias.name) not in [(a.id, a.name) for a in panel.aliases]
|
||||
|
||||
|
||||
def test_build_tag_panel_set_parent_tags(
|
||||
@@ -109,7 +110,9 @@ def test_build_tag_panel_add_aliases(
|
||||
):
|
||||
tag: Tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
|
||||
library.update_tag(tag, [], {"alias", "alias_2"}, {123, 124})
|
||||
alias_1 = TagAlias("alias", tag.id)
|
||||
alias_2 = TagAlias("alias_2", tag.id)
|
||||
library.update_tag(tag, [], {alias_1, alias_2})
|
||||
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
|
||||
@@ -132,22 +135,13 @@ def test_build_tag_panel_add_aliases(
|
||||
assert "alias" in alias_names
|
||||
assert "alias_2" in alias_names
|
||||
|
||||
old_text = widget.text()
|
||||
widget.setText("alias_update")
|
||||
|
||||
panel.add_aliases()
|
||||
|
||||
assert old_text not in panel.alias_names
|
||||
assert "alias_update" in panel.alias_names
|
||||
assert len(panel.alias_names) == 2
|
||||
|
||||
|
||||
def test_build_tag_panel_set_aliases(
|
||||
qtbot: QtBot, library: Library, generate_tag: Callable[..., Tag]
|
||||
):
|
||||
tag: Tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
|
||||
library.update_tag(tag, [], {"alias"}, {123})
|
||||
alias_1 = TagAlias("Alias 1", tag.id)
|
||||
library.update_tag(tag, [], [alias_1])
|
||||
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
|
||||
@@ -157,8 +151,7 @@ def test_build_tag_panel_set_aliases(
|
||||
qtbot.addWidget(panel)
|
||||
|
||||
assert panel.aliases_table.rowCount() == 1
|
||||
assert len(panel.alias_names) == 1
|
||||
assert len(panel.alias_ids) == 1
|
||||
assert len(panel.aliases) == 1
|
||||
|
||||
|
||||
def test_build_tag_panel_set_tag(qtbot: QtBot, library: Library, generate_tag: Callable[..., Tag]):
|
||||
|
||||
@@ -15,7 +15,7 @@ from tagstudio.core.library.alchemy.fields import (
|
||||
TextField,
|
||||
)
|
||||
from tagstudio.core.library.alchemy.library import Library
|
||||
from tagstudio.core.library.alchemy.models import Entry, Tag
|
||||
from tagstudio.core.library.alchemy.models import Entry, Tag, TagAlias
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
|
||||
logger = structlog.get_logger()
|
||||
@@ -25,10 +25,9 @@ def test_library_add_alias(library: Library, generate_tag: Callable[..., Tag]):
|
||||
tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
|
||||
parent_ids: set[int] = set()
|
||||
alias_ids: set[int] = set()
|
||||
alias_names: set[str] = set()
|
||||
alias_names.add("test_alias")
|
||||
library.update_tag(tag, parent_ids, alias_names, alias_ids)
|
||||
aliases: set[TagAlias] = set()
|
||||
aliases.add(TagAlias("test_alias", tag.id))
|
||||
library.update_tag(tag, parent_ids, aliases)
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
alias_ids = set(tag.alias_ids)
|
||||
|
||||
@@ -39,10 +38,9 @@ def test_library_get_alias(library: Library, generate_tag: Callable[..., Tag]):
|
||||
tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
|
||||
parent_ids: set[int] = set()
|
||||
alias_ids: list[int] = []
|
||||
alias_names: set[str] = set()
|
||||
alias_names.add("test_alias")
|
||||
library.update_tag(tag, parent_ids, alias_names, alias_ids)
|
||||
aliases: set[TagAlias] = set()
|
||||
aliases.add(TagAlias("test_alias", tag.id))
|
||||
library.update_tag(tag, parent_ids, aliases)
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
alias_ids = tag.alias_ids
|
||||
|
||||
@@ -54,19 +52,19 @@ def test_library_update_alias(library: Library, generate_tag: Callable[..., Tag]
|
||||
tag: Tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
|
||||
parent_ids: set[int] = set()
|
||||
alias_ids: list[int] = []
|
||||
alias_names: set[str] = set()
|
||||
alias_names.add("test_alias")
|
||||
library.update_tag(tag, parent_ids, alias_names, alias_ids)
|
||||
aliases: set[TagAlias] = set()
|
||||
test_alias = TagAlias("test_alias", tag.id)
|
||||
aliases.add(test_alias)
|
||||
library.update_tag(tag, parent_ids, aliases)
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
alias_ids = tag.alias_ids
|
||||
|
||||
alias = unwrap(library.get_alias(tag.id, alias_ids[0]))
|
||||
assert alias.name == "test_alias"
|
||||
|
||||
alias_names.remove("test_alias")
|
||||
alias_names.add("alias_update")
|
||||
library.update_tag(tag, parent_ids, alias_names, alias_ids)
|
||||
aliases.remove(test_alias)
|
||||
aliases.add(TagAlias("alias_update", tag.id))
|
||||
library.update_tag(tag, parent_ids, aliases)
|
||||
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
assert len(tag.alias_ids) == 1
|
||||
@@ -108,7 +106,7 @@ def test_tag_self_parent(library: Library, generate_tag: Callable[..., Tag]):
|
||||
tag = unwrap(library.add_tag(generate_tag("xxx", id=123)))
|
||||
assert tag.id == 123
|
||||
|
||||
library.update_tag(tag, {tag.id}, [], [])
|
||||
library.update_tag(tag, {tag.id}, [])
|
||||
tag = unwrap(library.get_tag(tag.id))
|
||||
assert len(tag.parent_ids) == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user