Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lowercase media tags in MediaStore #3345

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion catalog/dags/common/storage/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ def _enrich_tags(self, raw_tags) -> list | None:
def _format_raw_tag(self, tag):
if type(tag) == dict and tag.get("name") and tag.get("provider"):
logger.debug(f"Tag already enriched: {tag}")
tag["name"] = tag["name"].lower()
return tag
else:
logger.debug(f"Enriching tag: {tag}")
return {"name": tag, "provider": self.provider}
return {"name": tag.lower(), "provider": self.provider}

def _validate_filetype(self, filetype: str | None, url: str) -> str | None:
"""
Expand Down
44 changes: 41 additions & 3 deletions catalog/tests/dags/common/storage/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,20 +596,58 @@ def test_MediaStore_get_image_enriches_multiple_tags():
creator_url=None,
title=None,
meta_data=None,
raw_tags=["tagone", "tag2", "tag3"],
raw_tags=["tag-one", "TAG 2", "Tag3"],
category=None,
watermarked=None,
source=None,
ingestion_type=None,
)

assert actual_image.tags == [
{"name": "tagone", "provider": "test_provider"},
{"name": "tag2", "provider": "test_provider"},
{"name": "tag-one", "provider": "test_provider"},
{"name": "tag 2", "provider": "test_provider"},
{"name": "tag3", "provider": "test_provider"},
]


def test_MediaStore_get_image_lowercases_tag():
image_store = image.ImageStore("test_provider")
actual_image = image_store._get_image(
license_info=get_license_info(
license_url="https://license/url",
license_="by",
license_version="4.0",
),
foreign_landing_url=TEST_FOREIGN_LANDING_URL,
url=TEST_IMAGE_URL,
thumbnail_url=None,
filetype=None,
filesize=None,
foreign_identifier="02",
width=None,
height=None,
creator=None,
creator_url=None,
title=None,
meta_data=None,
raw_tags=[
{"name": "Tag-One", "provider": "test_provider"},
{"name": "TAG 2", "provider": "test_provider"},
{"name": "taG 3", "provider": "test_provider"},
],
category=None,
watermarked=None,
source=None,
ingestion_type=None,
)

assert actual_image.tags == [
{"name": "tag-one", "provider": "test_provider"},
{"name": "tag 2", "provider": "test_provider"},
{"name": "tag 3", "provider": "test_provider"},
]


def test_MediaStore_get_image_leaves_preenriched_tags(setup_env):
image_store = image.ImageStore("test_provider")
tags = [
Expand Down
Loading