"""Integration tests for utility endpoints. Endpoints tested: - /hello (TestHello) - /feeds (TestFeeds) - /feeds_v2 (TestFeedsV2) - /highwatermark (TestHighwatermark) - /stores (TestStores) - /store-outages (TestStoreOutages) These are infrastructure/utility endpoints shared across all profile types. Every test (except /hello) parametrizes on ALL_HEADERS to verify access control. """ import pytest from analytics import config from tests.integration.endpoints.conftest import ALL_HEADERS, assert_endpoint class TestHello: """Integration tests for /hello (health check). Groups: 1. Health check — returns {"status": "ok"} (1 test) """ # ── Group 1: Health check ───────────────────────────────────── # # 1 test. No auth required. def test_hello(self): """Health check returns {"status": "ok"} with no auth required.""" payload = assert_endpoint( config.HEALTH_CHECK_URL, headers={}, items_key=None, ) assert payload == {"status": "ok"} class TestFeeds: """Integration tests for /feeds. Verifies the legacy feeds endpoint returns feed data. Groups: 1. Feed data — response contains feed items (6 tests) """ # ── Group 1: Feed data ──────────────────────────────────────── # # 6 tests (one per header). @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_feeds(self, hdrs): """Legacy feeds endpoint returns a valid response.""" assert_endpoint( config.FEEDS_URL, headers=hdrs, items_key=None, ) class TestFeedsV2: """Integration tests for /feeds_v2. Verifies feed status reporting across all auth profiles. Groups: 1. Feed statuses — response contains expected keys (6 tests) """ # ── Group 1: Feed statuses ──────────────────────────────────── # # 6 tests (one per header). @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_feeds(self, hdrs): """Feeds endpoint returns feed_statuses and high_water_marks. Each feed status item must contain store_high_water_mark, missing_dates_before_store_high_watermark, and has_streams_outage. """ payload = assert_endpoint( config.FEEDS_V2_URL, headers=hdrs, items_key=None, expect_payload_keys=["feed_statuses", "high_water_marks"], ) for feed in payload["feed_statuses"]: assert "store_high_water_mark" in feed assert "missing_dates_before_store_high_watermark" in feed assert "has_streams_outage" in feed class TestHighwatermark: """Integration tests for /highwatermark. Verifies high watermark dates for streams, videos, and downloads. Groups: 1. All types — streams, videos, downloads (18 tests) """ # ── Group 1: All types ─────────────────────────────────────── # # 6 headers × 3 type_variants = 18 tests. @pytest.mark.parametrize("hdrs", ALL_HEADERS) @pytest.mark.parametrize( "hwm_type", [ pytest.param("streams", id="streams"), pytest.param("videos", id="videos"), pytest.param("downloads", id="downloads"), ], ) def test_highwatermark(self, hdrs, hwm_type): """Highwatermark returns a date string for the given type.""" payload = assert_endpoint( config.HIGHWATERMARK_URL + f"?type={hwm_type}", headers=hdrs, items_key=None, ) assert payload class TestStores: """Integration tests for /stores. Verifies store lookup via POST with various store_ids combinations across all auth profiles. Groups: 1. Store lookup — single and multiple store_ids (18 tests) """ # ── Group 1: Store lookup ───────────────────────────────────── # # 3 body variants × 6 headers = 18 tests. @pytest.mark.parametrize( "body", [ pytest.param({"store_ids": [1]}, id="store_1"), pytest.param({"store_ids": [286]}, id="store_286"), pytest.param({"store_ids": [1, 286]}, id="stores_1_and_286"), ], ) @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_stores(self, body, hdrs): """POST /stores returns store_id and store_name for each requested store. Exercises single store, different store, and multi-store lookups. """ payload = assert_endpoint( config.STORES_URL, headers=hdrs, method="POST", json_body=body, items_key=None, ) for store in payload: assert store.get("store_id") assert store.get("store_name") class TestStoreOutages: """Integration tests for /store-outages. Verifies store outage reporting across all auth profiles. Groups: 1. Store outages — returns store_outages list (6 tests) """ # ── Group 1: Store outages ──────────────────────────────────── # # 6 tests (one per header). @pytest.mark.parametrize("hdrs", ALL_HEADERS) def test_store_outages(self, hdrs): """Store outages returns a list of current outages.""" payload = assert_endpoint( config.STORE_OUTAGES_URL, headers=hdrs, items_key=None, expect_payload_keys=["store_outages"], ) assert isinstance(payload["store_outages"], list)