Skip to content

Commit

Permalink
fix(tests): fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanVoxel committed Nov 23, 2024
1 parent 7e82534 commit a810c70
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
13 changes: 9 additions & 4 deletions tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,16 @@ def add_entry_field_type(

if value:
assert isinstance(value, list)
for tag_id in list(set(value)):
for tag_name in list(set(value)):
with Session(self.engine) as session:
tag = session.scalar(select(Tag).where(Tag.id == tag_id))
logger.info(tag)
field_model.tags.add(tag)
# TODO: Add back in tag searching with aliases fallbacks
# and context clue ranking for string searches.
for tag_name in value:
tag = session.scalar(select(Tag).where(Tag.name == tag_name))
if tag:
field_model.tags.add(tag)
else:
field_model.tags.add(Tag(name=tag_name)) # type: ignore
session.flush()

elif field.type == FieldTypeEnum.DATETIME:
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/core/library/alchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def alias_ids(self) -> list[int]:

def __init__(
self,
id: int,
id: int | None = None,
name: str | None = None,
shorthand: str | None = None,
aliases: set[TagAlias] | None = None,
Expand Down
18 changes: 6 additions & 12 deletions tagstudio/tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_library_add_file(library):

def test_create_tag(library, generate_tag):
# tag already exists
assert not library.add_tag(generate_tag("foo"))
assert not library.add_tag(generate_tag("foo", id=1000))

# new tag name
tag = library.add_tag(generate_tag("xxx", id=123))
Expand All @@ -98,7 +98,7 @@ def test_create_tag(library, generate_tag):

def test_tag_subtag_itself(library, generate_tag):
# tag already exists
assert not library.add_tag(generate_tag("foo"))
assert not library.add_tag(generate_tag("foo", id=1000))

# new tag name
tag = library.add_tag(generate_tag("xxx", id=123))
Expand Down Expand Up @@ -132,19 +132,13 @@ def test_library_search(library, generate_tag, entry_full):
def test_tag_search(library):
tag = library.tags[0]

assert library.search_tags(
FilterState(tag=tag.name.lower()),
)
assert library.search_tags(tag.name.lower())

assert library.search_tags(
FilterState(tag=tag.name.upper()),
)
assert library.search_tags(tag.name.upper())

assert library.search_tags(FilterState(tag=tag.name[2:-2]))
assert library.search_tags(tag.name[2:-2])

assert not library.search_tags(
FilterState(tag=tag.name * 2),
)
assert not library.search_tags(tag.name * 2)


def test_get_entry(library, entry_min):
Expand Down

0 comments on commit a810c70

Please sign in to comment.