"""Transfer-ownership tests for /sound-recording//top-placements. ROLLUP grain, table-swap only. The PORT-5 work wrapped the ``playlist_rollup`` CTE's FROM with ``transfer_product_ownership_table_name`` — when the flag is on, ``STREAMS_BY_PLAYLIST_ROLLUP`` is swapped for its ``_PRODUCT_TRANSFER`` Pattern B drop-in variant. The legacy ``permission_checks`` macro still gates which placement rows surface (``private_placements`` CTE), so the row-presence semantics are unchanged between FF on and off. The dbt Pattern B drop-in is, by construction, **metric-neutral**: both the legacy ``_ROLLUP`` and the ``_PRODUCT_TRANSFER`` view aggregate to playlist grain and produce the same per-playlist totals once upstream data is stable. So the assertion is that the response is byte-equal on FF-ON and FF-OFF for every viewer. The endpoint's defaults filter to ``playlist_type=CURATED``, which has no coverage on product 5244974's ISRCs in FACTS.QA. The test overrides to ``playlist_type=USER_GENERATED&playlist_type=EDITORIAL`` to surface rows. """ from __future__ import annotations import pytest import requests from tests.integration.config import QA_BASE_URL from tests.integration.transfer_ownership.conftest import ( ISRC, TRANSFER_PROFILE_PAIRS, assert_ff_pair_equal, ) # Override the endpoint's default playlist_type filter. Product 5244974's # ISRCs only have USER_GENERATED and EDITORIAL placements in FACTS.QA — no # CURATED, which is the endpoint's default. Without the override the # response is empty for every viewer and the FF-pair assertion is trivial. _TYPE_OVERRIDE = "playlist_type=USER_GENERATED&playlist_type=EDITORIAL" URL = f"{QA_BASE_URL}/sound-recording/{ISRC}/top-placements?{_TYPE_OVERRIDE}&limit=200" def _payload(headers: dict) -> dict: response = requests.get(URL, headers=headers) assert ( response.status_code == 200 ), f"GET {URL} -> {response.status_code}: {response.text}" return response.json()["data"] class TestTopPlacementsTableSwap: """The ``_PRODUCT_TRANSFER`` rollup swap must be metric-neutral. Every viewer must get the byte-identical response with the flag on and off — Pattern B drop-in equivalence. If this fails, either the dbt rollup variant has drifted from the legacy table, or the SQL template is reading a different column set under the swap. """ @pytest.mark.parametrize("pair", TRANSFER_PROFILE_PAIRS) def test_metric_neutral(self, pair): ff_on = _payload(pair.ff_on) ff_off = _payload(pair.ff_off) assert_ff_pair_equal( ff_on, ff_off, label=f"{pair.key} /sound-recording/{ISRC}/top-placements", )