|
12 | 12 | from merino.middleware.geolocation import Location |
13 | 13 | from merino.middleware.user_agent import UserAgent |
14 | 14 | from merino.optimizers.thompson import ThompsonSampler |
| 15 | +from merino.providers.suggest.adm.backends.protocol import EngagementData |
15 | 16 | from merino.providers.suggest.adm.provider import NonsponsoredSuggestion, Provider |
16 | 17 |
|
17 | 18 | from tests.unit.types import SuggestionRequestFixture |
@@ -75,6 +76,9 @@ async def test_query_with_thompson_dummy_suppresses_suggestion( |
75 | 76 | ) -> None: |
76 | 77 | """Provider with a dominant dummy should suppress the suggestion (return empty list).""" |
77 | 78 | await adm_with_thompson_dummy.initialize() |
| 79 | + adm_with_thompson_dummy.engagement_data = EngagementData( |
| 80 | + amp={"something": {}}, amp_aggregated={} |
| 81 | + ) |
78 | 82 |
|
79 | 83 | res = await adm_with_thompson_dummy.query( |
80 | 84 | srequest("firefox", GEOLOCATION, USER_AGENT, CLIENT_VARIANTS) |
@@ -216,3 +220,36 @@ async def test_query_with_thompson_single_candidate_below_threshold_returns_sugg |
216 | 220 | statsd_mock.increment.assert_called_once_with( |
217 | 221 | "providers.adm.thompson.select", tags={"outcome": "skipped"} |
218 | 222 | ) |
| 223 | + |
| 224 | + |
| 225 | +@pytest.mark.asyncio |
| 226 | +async def test_query_with_thompson_without_engagement_data_skips_sampling( |
| 227 | + srequest: SuggestionRequestFixture, |
| 228 | + adm_with_thompson_dummy: Provider, |
| 229 | + adm_parameters: dict[str, Any], |
| 230 | + statsd_mock: Any, |
| 231 | +) -> None: |
| 232 | + """Provider should skip Thompson sampling when engagement data is empty.""" |
| 233 | + await adm_with_thompson_dummy.initialize() |
| 234 | + |
| 235 | + res = await adm_with_thompson_dummy.query( |
| 236 | + srequest("firefox", GEOLOCATION, USER_AGENT, CLIENT_VARIANTS) |
| 237 | + ) |
| 238 | + |
| 239 | + assert res == [ |
| 240 | + NonsponsoredSuggestion( |
| 241 | + block_id=2, |
| 242 | + full_keyword="firefox accounts", |
| 243 | + title="Mozilla Firefox Accounts", |
| 244 | + url=HttpUrl("https://example.org/target/mozfirefoxaccounts"), |
| 245 | + categories=[], |
| 246 | + impression_url=HttpUrl("https://example.org/impression/mozilla"), |
| 247 | + click_url=HttpUrl("https://example.org/click/mozilla"), |
| 248 | + provider="adm", |
| 249 | + advertiser="Example.org", |
| 250 | + is_sponsored=False, |
| 251 | + icon="attachment-host/main-workspace/quicksuggest/icon-01", |
| 252 | + score=adm_parameters["score"], |
| 253 | + ) |
| 254 | + ] |
| 255 | + statsd_mock.increment.assert_not_called() |
0 commit comments