"""Integration tests for TADAS endpoints. Endpoints tested: - /tadas-trends (TestTadasTrends) - /tadas/trend-globalsoundrecording-by-isrc/ (TestTadasTrendByIsrc) - /tadas/data-availability (TestTadasDataAvailability) TADAS trends endpoints are employee-only: non-employee profiles receive empty responses ({trends: [], count: 0}). Data availability has no auth. """ import pytest from analytics import config from analytics.config import BASE_URL from tests.integration.endpoints.conftest import ( ALL_HEADERS, INSIGHTS_EMPLOYEE, assert_endpoint, ) class TestTadasTrends: """Integration tests for /tadas-trends. Employee-only endpoint. Non-employees receive {trends: [], count: 0}. Groups: 1. Employee access — returns trends and count (1 test) 2. Non-employee — returns empty trends (5 tests) 3. With filters — market and date filters (3 tests) """ # ── Group 1: Employee access ────────────────────────────────────── # # 1 test. def test_employee_sees_trends(self): """Employee gets trends data with count.""" payload = assert_endpoint( config.TADAS_TRENDS_URL + "?limit=10&offset=0", headers=INSIGHTS_EMPLOYEE, items_key=None, expect_payload_keys=["trends", "count"], ) assert isinstance(payload["trends"], list) assert isinstance(payload["count"], int) # ── Group 2: All profiles ──────────────────────────────────────── # # 6 tests (all headers). Non-employees get empty trends. @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_all_profiles(self, hdrs): """All profiles get HTTP 200. Non-employees get empty trends.""" payload = assert_endpoint( config.TADAS_TRENDS_URL + "?limit=10&offset=0", headers=hdrs, items_key=None, expect_payload_keys=["trends"], ) if hdrs != INSIGHTS_EMPLOYEE: assert payload["trends"] == [] assert payload["count"] == 0 # ── Group 3: With filters ───────────────────────────────────────── # # 2 tests. def test_with_market_filter(self): """Employee with market filter returns valid response.""" assert_endpoint( config.TADAS_TRENDS_URL + "?limit=10&offset=0&markets=US", headers=INSIGHTS_EMPLOYEE, items_key=None, expect_payload_keys=["trends", "count"], ) def test_with_date_filter(self): """Employee with release date filter returns valid response.""" assert_endpoint( config.TADAS_TRENDS_URL + "?limit=10&offset=0" "&release_start_date=2023-01-01&release_end_date=2023-12-31", headers=INSIGHTS_EMPLOYEE, items_key=None, expect_payload_keys=["trends", "count"], ) def test_with_rep_owner_filter(self): """Employee with rep_owner filter returns valid response.""" assert_endpoint( config.TADAS_TRENDS_URL + "?limit=10&offset=0&rep_owner=AWAL", headers=INSIGHTS_EMPLOYEE, items_key=None, expect_payload_keys=["trends", "count"], ) class TestTadasTrendByIsrc: """Integration tests for /tadas/trend-globalsoundrecording-by-isrc/. Employee-only endpoint. Non-employees receive {trends: []}. Groups: 1. Employee access — returns trends for ISRC (1 test) 2. Non-employee — returns empty trends (5 tests) 3. With market filter — narrows trend data (1 test) """ ISRC = "QMDA62184373" def _url(self, extra=""): return ( config.TADAS_TREND_GLOBALSOUNDRECORDING_BY_ISRC_URL.replace( "", self.ISRC ) + extra ) # ── Group 1: Employee access ────────────────────────────────────── # # 1 test. def test_employee_sees_trend(self): """Employee gets trend data for the ISRC.""" payload = assert_endpoint( self._url(), headers=INSIGHTS_EMPLOYEE, items_key=None, expect_payload_keys=["trends"], ) assert isinstance(payload["trends"], list) # ── Group 2: All profiles ──────────────────────────────────────── # # 6 tests (all headers). Non-employees get empty trends. @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_all_profiles(self, hdrs): """All profiles get HTTP 200. Non-employees get empty trends.""" payload = assert_endpoint( self._url(), headers=hdrs, items_key=None, expect_payload_keys=["trends"], ) if hdrs != INSIGHTS_EMPLOYEE: assert payload["trends"] == [] # ── Group 3: With market filter ─────────────────────────────────── # # 1 test. def test_with_market_filter(self): """Employee with market filter returns valid response.""" assert_endpoint( self._url("?markets=US"), headers=INSIGHTS_EMPLOYEE, items_key=None, expect_payload_keys=["trends"], ) class TestTadasDataAvailability: """Integration tests for /tadas/data-availability. No auth required. Returns TADAS data availability dates. Groups: 1. No auth — returns data availability (1 test) 2. All profiles — works with any auth (6 tests) """ # ── Group 1: No auth ────────────────────────────────────────────── # # 1 test. def test_no_auth(self): """Data availability works without auth headers.""" payload = assert_endpoint( f"{BASE_URL}/tadas/data-availability", headers={}, items_key=None, ) assert payload # ── Group 2: All profiles ───────────────────────────────────────── # # 6 tests (one per header). @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_all_profiles(self, hdrs): """Data availability returns valid response for all auth profiles.""" payload = assert_endpoint( f"{BASE_URL}/tadas/data-availability", headers=hdrs, items_key=None, ) assert payload