Skip to content

Commit

Permalink
fix: Remove hardcoded chrome image URIs from top picks
Browse files Browse the repository at this point in the history
  • Loading branch information
ncloudioj committed Feb 3, 2025
1 parent a34b517 commit 7a1d7e5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 105 deletions.
10 changes: 5 additions & 5 deletions dev/top_picks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"url": "https://www.google.com",
"title": "Google",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/google-com@2x.png",
"icon": "",
"serp_categories": [
18
]
Expand Down Expand Up @@ -62,7 +62,7 @@
],
"url": "https://www.youtube.com",
"title": "YouTube",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/youtube-com@2x.png",
"icon": "",
"serp_categories": [
0
]
Expand All @@ -75,7 +75,7 @@
],
"url": "https://twitter.com",
"title": "Twitter",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/twitter-com@2x.png",
"icon": "",
"serp_categories": [
16
]
Expand Down Expand Up @@ -182,7 +182,7 @@
],
"url": "https://www.bing.com",
"title": "Bing",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/bing-com@2x.svg",
"icon": "",
"serp_categories": [
18
]
Expand Down Expand Up @@ -10089,4 +10089,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The `/manifest` endpoint returns a curated list of websites with associated meta
],
"url": "https://www.google.com/",
"title": "Google",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/google-com@2x.png"
"icon": ""
},
{
"rank": 2,
Expand Down
6 changes: 1 addition & 5 deletions merino/jobs/navigational_suggestions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
from merino.jobs.navigational_suggestions.domain_metadata_uploader import (
DomainMetadataUploader,
)
from merino.jobs.navigational_suggestions.utils import (
update_top_picks_with_firefox_favicons,
)
from merino.providers.suggest.base import Category
from merino.utils.blocklists import TOP_PICKS_BLOCKLIST

Expand Down Expand Up @@ -158,9 +155,8 @@ def prepare_domain_metadata(
uploaded_favicons = domain_metadata_uploader.upload_favicons(favicons)
logger.info("domain favicons uploaded to GCS")

# construct top pick contents, update them with firefox packaged favicons and upload to gcs
# construct top pick contents
top_picks = _construct_top_picks(domain_data, uploaded_favicons, domain_metadata)
update_top_picks_with_firefox_favicons(top_picks)

# Create diff class for comparison of Top Picks Files
old_top_picks: dict[str, list[dict[str, str]]] | None = (
Expand Down
22 changes: 0 additions & 22 deletions merino/jobs/navigational_suggestions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@

TIMEOUT: int = 10

# Some high resolution domain favicons that are internally packaged in Firefox
FIREFOX_PACKAGED_FAVICONS: dict[str, str] = {
"google": "chrome://activity-stream/content/data/content/tippytop/images/google-com@2x.png",
"bing": "chrome://activity-stream/content/data/content/tippytop/images/bing-com@2x.svg",
"youtube": "chrome://activity-stream/content/data/content/tippytop/images/youtube-com@2x.png",
"twitter": "chrome://activity-stream/content/data/content/tippytop/images/twitter-com@2x.png",
}

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -74,17 +66,3 @@ def requests_get(url: str) -> requests.Response | None:
timeout=TIMEOUT,
)
return response if response.status_code == 200 else None


def update_top_picks_with_firefox_favicons(
top_picks: dict[str, list[dict[str, str]]],
) -> None:
"""Update top picks with high resolution favicons that are internally packaged in firefox
for some of the selected domains for which favicon scraping didn't return anything
"""
domains_metadata: list[dict[str, str]] = top_picks["domains"]
for domain_metadata in domains_metadata:
domain = domain_metadata["domain"]
firefox_favicon: str | None = FIREFOX_PACKAGED_FAVICONS.get(domain)
if firefox_favicon:
domain_metadata["icon"] = firefox_favicon
2 changes: 1 addition & 1 deletion tests/integration/api/v1/manifest/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def mock_manifest_2025() -> dict:
"serp_categories": [0],
"url": "https://www.spotify.com",
"title": "Spotify",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/google-com@2x.png",
"icon": "",
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def fixture_blob_json() -> str:
"serp_categories": [0],
"url": "https://www.google.com/",
"title": "Google",
"icon": "chrome://activity-stream/content/data/content/tippytop/images/google-com@2x.png",
"icon": "",
},
{
"rank": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,9 @@
from merino.jobs.navigational_suggestions.utils import (
REQUEST_HEADERS,
FaviconDownloader,
update_top_picks_with_firefox_favicons,
)


def test_update_top_picks_with_firefox_favicons_favicon_added_for_special_domains():
"""Test that top picks is updated with firefox favicon for special domains
when scraped available to top picks
"""
input_top_picks = {
"domains": [
{
"rank": 1,
"domain": "google",
"categories": ["Search Engines"],
"url": "https://www.google.com",
"title": "Google",
"icon": "",
},
]
}

updated_top_picks = {
"domains": [
{
"rank": 1,
"domain": "google",
"categories": ["Search Engines"],
"url": "https://www.google.com",
"title": "Google",
"icon": (
"chrome://activity-stream/content/data/content/tippytop/"
"images/google-com@2x.png"
),
},
]
}

update_top_picks_with_firefox_favicons(input_top_picks)
assert input_top_picks == updated_top_picks


def test_update_top_picks_with_firefox_favicons_favicon_not_added_for_non_special_domains():
"""Test that top picks is not updated with firefox favicon for non special domains"""
input_top_picks = {
"domains": [
{
"rank": 2,
"domain": "facebook",
"categories": ["Social Networks"],
"url": "https://www.facebook.com",
"title": "Facebook \u2013 log in or sign up",
"icon": "",
},
]
}

updated_top_picks = {
"domains": [
{
"rank": 2,
"domain": "facebook",
"categories": ["Social Networks"],
"url": "https://www.facebook.com",
"title": "Facebook \u2013 log in or sign up",
"icon": "",
},
]
}

update_top_picks_with_firefox_favicons(input_top_picks)
assert input_top_picks == updated_top_picks


def test_favicon_downloader(requests_mock):
"""Test FaviconDownloader using requests_mock"""
requests_mock.register_uri(
Expand Down

0 comments on commit 7a1d7e5

Please sign in to comment.