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