|
7 | 7 |
|
8 | 8 | from __future__ import annotations |
9 | 9 |
|
| 10 | +import logging |
10 | 11 | from typing import Any |
11 | 12 |
|
12 | 13 | from adcp.compat.legacy import get_legacy_adapter |
@@ -119,6 +120,66 @@ def test_create_media_buy_brand_manifest_inline_object_brand_wins_when_both_pres |
119 | 120 | assert "brand_manifest" not in out |
120 | 121 |
|
121 | 122 |
|
| 123 | +# --------------------------------------------------------------------------- |
| 124 | +# create_media_buy: brand_manifest non-standard-path warning (issue #683) |
| 125 | +# --------------------------------------------------------------------------- |
| 126 | + |
| 127 | +_MB_HELPERS_LOGGER = "adcp.compat.legacy.v2_5._media_buy_helpers" |
| 128 | + |
| 129 | + |
| 130 | +def test_create_media_buy_cdn_url_warns(caplog, monkeypatch) -> None: # type: ignore[no-untyped-def] |
| 131 | + """CDN brand_manifest with non-standard path emits a WARNING about the |
| 132 | + information loss so operators can debug downstream 404s.""" |
| 133 | + import adcp.compat.legacy.v2_5._media_buy_helpers as _mbh |
| 134 | + |
| 135 | + monkeypatch.setattr(_mbh, "_brand_manifest_path_warned", set()) |
| 136 | + with caplog.at_level(logging.WARNING, logger=_MB_HELPERS_LOGGER): |
| 137 | + out = v2_5_cmb.adapt_request( |
| 138 | + {"brand_manifest": "https://cdn.acmecorp.com/brand-manifest.json"} |
| 139 | + ) |
| 140 | + assert out["brand"] == {"domain": "cdn.acmecorp.com"} |
| 141 | + records = [r for r in caplog.records if r.name == _MB_HELPERS_LOGGER] |
| 142 | + assert len(records) == 1 |
| 143 | + msg = records[0].getMessage() |
| 144 | + assert "non-standard path" in msg |
| 145 | + assert "cdn.acmecorp.com" in msg |
| 146 | + |
| 147 | + |
| 148 | +def test_create_media_buy_well_known_path_no_warning(caplog, monkeypatch) -> None: # type: ignore[no-untyped-def] |
| 149 | + """Standard /.well-known/brand.json path does NOT warn.""" |
| 150 | + import adcp.compat.legacy.v2_5._media_buy_helpers as _mbh |
| 151 | + |
| 152 | + monkeypatch.setattr(_mbh, "_brand_manifest_path_warned", set()) |
| 153 | + with caplog.at_level(logging.WARNING, logger=_MB_HELPERS_LOGGER): |
| 154 | + v2_5_cmb.adapt_request( |
| 155 | + {"brand_manifest": "https://acme.com/.well-known/brand.json"} |
| 156 | + ) |
| 157 | + assert not any(r.name == _MB_HELPERS_LOGGER for r in caplog.records) |
| 158 | + |
| 159 | + |
| 160 | +def test_create_media_buy_bare_domain_no_warning(caplog, monkeypatch) -> None: # type: ignore[no-untyped-def] |
| 161 | + """Bare domain brand_manifest (no scheme) does not false-positive.""" |
| 162 | + import adcp.compat.legacy.v2_5._media_buy_helpers as _mbh |
| 163 | + |
| 164 | + monkeypatch.setattr(_mbh, "_brand_manifest_path_warned", set()) |
| 165 | + with caplog.at_level(logging.WARNING, logger=_MB_HELPERS_LOGGER): |
| 166 | + v2_5_cmb.adapt_request({"brand_manifest": "acme.com"}) |
| 167 | + assert not any(r.name == _MB_HELPERS_LOGGER for r in caplog.records) |
| 168 | + |
| 169 | + |
| 170 | +def test_create_media_buy_cdn_url_warns_once_dedup(caplog, monkeypatch) -> None: # type: ignore[no-untyped-def] |
| 171 | + """Same CDN URL repeated across requests only logs one warning (dedup).""" |
| 172 | + import adcp.compat.legacy.v2_5._media_buy_helpers as _mbh |
| 173 | + |
| 174 | + monkeypatch.setattr(_mbh, "_brand_manifest_path_warned", set()) |
| 175 | + url = "https://cdn.acmecorp.com/brand-manifest.json" |
| 176 | + with caplog.at_level(logging.WARNING, logger=_MB_HELPERS_LOGGER): |
| 177 | + v2_5_cmb.adapt_request({"brand_manifest": url}) |
| 178 | + v2_5_cmb.adapt_request({"brand_manifest": url}) |
| 179 | + records = [r for r in caplog.records if r.name == _MB_HELPERS_LOGGER] |
| 180 | + assert len(records) == 1 |
| 181 | + |
| 182 | + |
122 | 183 | # --------------------------------------------------------------------------- |
123 | 184 | # Package request: creative_ids → creative_assignments (both tools) |
124 | 185 | # --------------------------------------------------------------------------- |
|
0 commit comments