|
46 | 46 | ) |
47 | 47 | from merino.curated_recommendations.protocol import CuratedRecommendation |
48 | 48 | from merino.main import app |
| 49 | +from merino.providers.manifest import get_provider as get_manifest_provider |
| 50 | +from merino.providers.manifest.backends.protocol import Domain |
49 | 51 | from tests.integration.api.conftest import fakespot_feed |
50 | 52 |
|
51 | 53 |
|
@@ -121,6 +123,16 @@ def extended_expiration_corpus_backend( |
121 | 123 | ) |
122 | 124 |
|
123 | 125 |
|
| 126 | +@pytest.fixture(autouse=True) |
| 127 | +def setup_manifest_provider(manifest_provider): |
| 128 | + """Set up the manifest provider dependency""" |
| 129 | + app.dependency_overrides[get_manifest_provider] = lambda: manifest_provider |
| 130 | + yield |
| 131 | + # Clean up after test |
| 132 | + if get_manifest_provider in app.dependency_overrides: |
| 133 | + del app.dependency_overrides[get_manifest_provider] |
| 134 | + |
| 135 | + |
124 | 136 | @pytest.fixture(name="corpus_provider") |
125 | 137 | def provider( |
126 | 138 | corpus_backend: CorpusApiBackend, |
@@ -1529,3 +1541,69 @@ def mock_post_by_days_ago(*args, **kwargs): |
1529 | 1541 | else: |
1530 | 1542 | # Check that only today's items are returned if in control or not in the experiment. |
1531 | 1543 | assert set(days_ago_counter.keys()) == {0} |
| 1544 | + |
| 1545 | + |
| 1546 | +@pytest.mark.asyncio |
| 1547 | +async def test_curated_recommendations_enriched_with_icons( |
| 1548 | + manifest_provider, |
| 1549 | + corpus_http_client, |
| 1550 | + fixture_request_data, |
| 1551 | +): |
| 1552 | + """Test the enrichment of a curated recommendation with an added icon-url.""" |
| 1553 | + manifest_provider.manifest_data.domains = [ |
| 1554 | + Domain( |
| 1555 | + rank=2, |
| 1556 | + title="Microsoft – AI, Cloud, Productivity, Computing, Gaming & Apps", |
| 1557 | + url="https://www.microsoft.com", |
| 1558 | + domain="microsoft.com", |
| 1559 | + icon="https://merino-images.services.mozilla.com/favicons/microsoft-icon.png", |
| 1560 | + categories=["Business", "Information Technology"], |
| 1561 | + serp_categories=[0], |
| 1562 | + ) |
| 1563 | + ] |
| 1564 | + |
| 1565 | + manifest_provider.lookup_table = {"microsoft.com": 0} |
| 1566 | + |
| 1567 | + mocked_response = { |
| 1568 | + "data": { |
| 1569 | + "scheduledSurface": { |
| 1570 | + "items": [ |
| 1571 | + { |
| 1572 | + "id": "scheduledSurfaceItemId-ABC", |
| 1573 | + "corpusItem": { |
| 1574 | + "id": "corpusItemId-XYZ", |
| 1575 | + "url": "https://www.microsoft.com/some-article?utm_source=firefox-newtab-en-us", |
| 1576 | + "title": "Some MS Article", |
| 1577 | + "excerpt": "All about Microsoft something", |
| 1578 | + "topic": "tech", |
| 1579 | + "publisher": "ExamplePublisher", |
| 1580 | + "isTimeSensitive": False, |
| 1581 | + "imageUrl": "https://somewhere.com/test.jpg", |
| 1582 | + }, |
| 1583 | + } |
| 1584 | + ] |
| 1585 | + } |
| 1586 | + } |
| 1587 | + } |
| 1588 | + corpus_http_client.post.return_value = Response( |
| 1589 | + status_code=200, |
| 1590 | + json=mocked_response, |
| 1591 | + request=fixture_request_data, |
| 1592 | + ) |
| 1593 | + |
| 1594 | + async with AsyncClient(app=app, base_url="http://test") as ac: |
| 1595 | + response = await ac.post( |
| 1596 | + "/api/v1/curated-recommendations", |
| 1597 | + json={"locale": "en-US"}, |
| 1598 | + ) |
| 1599 | + assert response.status_code == 200 |
| 1600 | + |
| 1601 | + data = response.json() |
| 1602 | + items = data["data"] |
| 1603 | + assert len(items) == 1 |
| 1604 | + |
| 1605 | + item = items[0] |
| 1606 | + assert item["url"] == "https://www.microsoft.com/some-article?utm_source=firefox-newtab-en-us" |
| 1607 | + |
| 1608 | + assert "icon" in item |
| 1609 | + assert item["icon"] == "https://merino-images.services.mozilla.com/favicons/microsoft-icon.png" |
0 commit comments