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

MC-1483: Update utm_source #642

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def headers(self):
For ids not in the table, null is returned.
"""
SCHEDULED_SURFACE_ID_TO_UTM_SOURCE: dict[ScheduledSurfaceId, str] = {
ScheduledSurfaceId.NEW_TAB_EN_US: "pocket-newtab-en-us",
ScheduledSurfaceId.NEW_TAB_EN_GB: "pocket-newtab-en-gb",
ScheduledSurfaceId.NEW_TAB_EN_INTL: "pocket-newtab-en-intl",
ScheduledSurfaceId.NEW_TAB_DE_DE: "pocket-newtab-de-de",
ScheduledSurfaceId.NEW_TAB_ES_ES: "pocket-newtab-es-es",
ScheduledSurfaceId.NEW_TAB_FR_FR: "pocket-newtab-fr-fr",
ScheduledSurfaceId.NEW_TAB_IT_IT: "pocket-newtab-it-it",
ScheduledSurfaceId.NEW_TAB_EN_US: "firefox-newtab-en-us",
ScheduledSurfaceId.NEW_TAB_EN_GB: "firefox-newtab-en-gb",
ScheduledSurfaceId.NEW_TAB_EN_INTL: "firefox-newtab-en-intl",
ScheduledSurfaceId.NEW_TAB_DE_DE: "firefox-newtab-de-de",
ScheduledSurfaceId.NEW_TAB_ES_ES: "firefox-newtab-es-es",
ScheduledSurfaceId.NEW_TAB_FR_FR: "firefox-newtab-fr-fr",
ScheduledSurfaceId.NEW_TAB_IT_IT: "firefox-newtab-it-it",
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async def test_curated_recommendations(repeat):
expected_recommendation = CuratedRecommendation(
scheduledCorpusItemId="de614b6b-6df6-470a-97f2-30344c56c1b3",
url=HttpUrl(
"https://getpocket.com/explore/item/milk-powder-is-the-key-to-better-cookies-brownies-and-cakes?utm_source=pocket-newtab-en-us"
"https://getpocket.com/explore/item/milk-powder-is-the-key-to-better-cookies-brownies-and-cakes?utm_source=firefox-newtab-en-us"
),
title="Milk Powder Is the Key to Better Cookies, Brownies, and Cakes",
excerpt="Consider this pantry staple your secret ingredient for making more flavorful desserts.",
Expand Down Expand Up @@ -296,7 +296,7 @@ async def test_curated_recommendations_utm_source():
assert len(corpus_items) == 80
# Assert all corpus_items have expected fields populated.
# check that utm_source is present and has the correct value in all urls
assert all("?utm_source=pocket-newtab-en-us" in item["url"] for item in corpus_items)
assert all("?utm_source=firefox-newtab-en-us" in item["url"] for item in corpus_items)
assert all(item["publisher"] for item in corpus_items)
assert all(item["imageUrl"] for item in corpus_items)

Expand Down
30 changes: 15 additions & 15 deletions tests/unit/curated_recommendations/test_corpus_api_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ def test_get_utm_source_return_none(scheduled_surface_id):
@pytest.mark.parametrize(
("scheduled_surface_id", "expected_utm_source"),
[
(ScheduledSurfaceId.NEW_TAB_EN_US, "pocket-newtab-en-us"),
(ScheduledSurfaceId.NEW_TAB_EN_GB, "pocket-newtab-en-gb"),
(ScheduledSurfaceId.NEW_TAB_EN_INTL, "pocket-newtab-en-intl"),
(ScheduledSurfaceId.NEW_TAB_DE_DE, "pocket-newtab-de-de"),
(ScheduledSurfaceId.NEW_TAB_ES_ES, "pocket-newtab-es-es"),
(ScheduledSurfaceId.NEW_TAB_FR_FR, "pocket-newtab-fr-fr"),
(ScheduledSurfaceId.NEW_TAB_IT_IT, "pocket-newtab-it-it"),
(ScheduledSurfaceId.NEW_TAB_EN_US, "firefox-newtab-en-us"),
(ScheduledSurfaceId.NEW_TAB_EN_GB, "firefox-newtab-en-gb"),
(ScheduledSurfaceId.NEW_TAB_EN_INTL, "firefox-newtab-en-intl"),
(ScheduledSurfaceId.NEW_TAB_DE_DE, "firefox-newtab-de-de"),
(ScheduledSurfaceId.NEW_TAB_ES_ES, "firefox-newtab-es-es"),
(ScheduledSurfaceId.NEW_TAB_FR_FR, "firefox-newtab-fr-fr"),
(ScheduledSurfaceId.NEW_TAB_IT_IT, "firefox-newtab-it-it"),
],
)
def test_get_utm_source(scheduled_surface_id, expected_utm_source):
Expand All @@ -160,26 +160,26 @@ def test_get_utm_source(scheduled_surface_id, expected_utm_source):
# add new utm_source
(
"https://getpocket.com/explore/item/example-article",
"pocket-newtab-en-us",
"https://getpocket.com/explore/item/example-article?utm_source=pocket-newtab-en-us",
"firefox-newtab-en-us",
"https://getpocket.com/explore/item/example-article?utm_source=firefox-newtab-en-us",
),
# add new utm_source with another query param present in url
(
"https://getpocket.com/explore/item/example-article?foo=bar",
"pocket-newtab-en-gb",
"https://getpocket.com/explore/item/example-article?foo=bar&utm_source=pocket-newtab-en-gb",
"firefox-newtab-en-gb",
"https://getpocket.com/explore/item/example-article?foo=bar&utm_source=firefox-newtab-en-gb",
),
# replace old utm_source with new one
(
"https://getpocket.com/explore/item/example-article?utm_source=old_source",
"pocket-newtab-en-intl",
"https://getpocket.com/explore/item/example-article?utm_source=pocket-newtab-en-intl",
"firefox-newtab-en-intl",
"https://getpocket.com/explore/item/example-article?utm_source=firefox-newtab-en-intl",
),
# replace old utm_source with new one & when another query param present in url
(
"https://getpocket.com/explore/item/example-article?utm_source=old_source&foo=bar",
"pocket-newtab-de-de",
"https://getpocket.com/explore/item/example-article?utm_source=pocket-newtab-de-de&foo=bar",
"firefox-newtab-de-de",
"https://getpocket.com/explore/item/example-article?utm_source=firefox-newtab-de-de&foo=bar",
),
# pass empty utm_source (when no mapping is found)
(
Expand Down