-
Notifications
You must be signed in to change notification settings - Fork 16
DISCO-3202 - Enrich the curated-recommendations endpoint with icon-urls #784
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,8 @@ | |||||
| ) | ||||||
| from merino.curated_recommendations.protocol import CuratedRecommendation | ||||||
| from merino.main import app | ||||||
| from merino.providers.manifest import get_provider as get_manifest_provider | ||||||
| from merino.providers.manifest.backends.protocol import Domain | ||||||
| from tests.integration.api.conftest import fakespot_feed | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -121,6 +123,15 @@ def extended_expiration_corpus_backend( | |||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @pytest.fixture(autouse=True) | ||||||
| def setup_manifest_provider(manifest_provider): | ||||||
| """Set up the manifest provider dependency""" | ||||||
| app.dependency_overrides[get_manifest_provider] = lambda: manifest_provider | ||||||
| yield | ||||||
| if get_manifest_provider in app.dependency_overrides: | ||||||
| del app.dependency_overrides[get_manifest_provider] | ||||||
gruberb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
|
|
||||||
| @pytest.fixture(name="corpus_provider") | ||||||
| def provider( | ||||||
| corpus_backend: CorpusApiBackend, | ||||||
|
|
@@ -140,7 +151,7 @@ def provider( | |||||
|
|
||||||
|
|
||||||
| @pytest.fixture(autouse=True) | ||||||
| def setup_providers(corpus_provider): | ||||||
| def setup_suggest_providers(corpus_provider): | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """Set up the curated recommendations provider""" | ||||||
| app.dependency_overrides[get_provider] = lambda: corpus_provider | ||||||
|
|
||||||
|
|
@@ -1529,3 +1540,75 @@ def mock_post_by_days_ago(*args, **kwargs): | |||||
| else: | ||||||
| # Check that only today's items are returned if in control or not in the experiment. | ||||||
| assert set(days_ago_counter.keys()) == {0} | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.asyncio | ||||||
| async def test_curated_recommendations_enriched_with_icons( | ||||||
| manifest_provider, | ||||||
| corpus_http_client, | ||||||
| fixture_request_data, | ||||||
| ): | ||||||
| """Test the enrichment of a curated recommendation with an added icon-url.""" | ||||||
| # Set up the manifest data first | ||||||
| manifest_provider.manifest_data.domains = [ | ||||||
| Domain( | ||||||
| rank=2, | ||||||
| title="Microsoft – AI, Cloud, Productivity, Computing, Gaming & Apps", | ||||||
| url="https://www.microsoft.com", | ||||||
| domain="microsoft", | ||||||
| icon="https://merino-images.services.mozilla.com/favicons/microsoft-icon.png", | ||||||
| categories=["Business", "Information Technology"], | ||||||
| serp_categories=[0], | ||||||
| ) | ||||||
| ] | ||||||
| manifest_provider.domain_lookup_table = {"microsoft": 0} | ||||||
|
|
||||||
| mocked_response = { | ||||||
| "data": { | ||||||
| "scheduledSurface": { | ||||||
| "items": [ | ||||||
| { | ||||||
| "id": "scheduledSurfaceItemId-ABC", | ||||||
| "corpusItem": { | ||||||
| "id": "corpusItemId-XYZ", | ||||||
| "url": "https://www.microsoft.com/some-article?utm_source=firefox-newtab-en-us", | ||||||
| "title": "Some MS Article", | ||||||
| "excerpt": "All about Microsoft something", | ||||||
| "topic": "tech", | ||||||
| "publisher": "ExamplePublisher", | ||||||
| "isTimeSensitive": False, | ||||||
| "imageUrl": "https://somewhere.com/test.jpg", | ||||||
| }, | ||||||
| } | ||||||
| ] | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| corpus_http_client.post.return_value = Response( | ||||||
| status_code=200, | ||||||
| json=mocked_response, | ||||||
| request=fixture_request_data, | ||||||
| ) | ||||||
|
|
||||||
| async with AsyncClient(app=app, base_url="http://test") as ac: | ||||||
| response = await ac.post( | ||||||
| "/api/v1/curated-recommendations", | ||||||
| json={"locale": "en-US"}, | ||||||
| ) | ||||||
| assert response.status_code == 200 | ||||||
|
|
||||||
| data = response.json() | ||||||
| items = data["data"] | ||||||
| assert len(items) == 1 | ||||||
|
|
||||||
| item = items[0] | ||||||
| assert item["url"] == "https://www.microsoft.com/some-article?utm_source=firefox-newtab-en-us" | ||||||
|
|
||||||
| assert "iconUrl" in item | ||||||
| assert ( | ||||||
| item["iconUrl"] == "https://merino-images.services.mozilla.com/favicons/microsoft-icon.png" | ||||||
| ) | ||||||
|
|
||||||
| # Clean up | ||||||
| if get_provider in app.dependency_overrides: | ||||||
| del app.dependency_overrides[get_provider] | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.