import re import pytest import httpx from ntr_fetcher.soundcloud import SoundCloudClient FAKE_HTML = """ """ FAKE_HTML_EXPIRING = """ """ @pytest.mark.asyncio async def test_extract_client_id(httpx_mock): httpx_mock.add_response(url="https://soundcloud.com", text=FAKE_HTML) client = SoundCloudClient() client_id = await client._extract_client_id() assert client_id == "test_client_id_abc123" @pytest.mark.asyncio async def test_extract_client_id_caches(httpx_mock): httpx_mock.add_response(url="https://soundcloud.com", text=FAKE_HTML) client = SoundCloudClient() id1 = await client._extract_client_id() id2 = await client._extract_client_id() assert id1 == id2 assert len(httpx_mock.get_requests()) == 1 @pytest.mark.asyncio async def test_extract_client_id_bad_html(httpx_mock): httpx_mock.add_response(url="https://soundcloud.com", text="no hydration here") client = SoundCloudClient() with pytest.raises(ValueError, match="client_id"): await client._extract_client_id()