"""Números dos posts (dashboard): leitura de contagens, YouTube público, linha do TikTok Studio e API do Instagram.""" from __future__ import annotations from app.platforms.session import stats as session_stats from app.platforms.stats import parse_count, youtube_from_html def test_parse_count_reads_how_networks_show_numbers(): assert parse_count("1.499") == 1499 and parse_count("1,499") == 1499 and parse_count("31") == 31 assert parse_count("1,2 mil") == 1200 and parse_count("5,2\xa0mil") == 5200 and parse_count("1.2K") == 1200 assert parse_count("3,4 mi") == 3_400_000 and parse_count("3.4M") == 3_400_000 and parse_count("0") == 0 assert parse_count("Todos") is None and parse_count("") is None and parse_count("17 de nov, 15:50") is None def test_youtube_public_page(): html = '..."videoDetails":{"viewCount":"1234"}..."likeCount":"56"..."contextualInfo":{"runs":[{"text":"7"}]}' stats = youtube_from_html("abc123", html) assert (stats.views, stats.likes, stats.comments) == (1234, 56, 7) assert youtube_from_html("abc123", "consent") is None def test_tiktok_studio_row(): # Texto real de uma linha do Studio (17/11/2026). text = ("00:26\nA conversa sobre descanso vira... #skipnho 🎥 Créditos: https://twitch.tv/skipnho\n17 de nov, 15:50\n" "Todos\n2\n1\n0") stats = session_stats.tiktok_row_stats("https://www.tiktok.com/@vortplay/video/7709214727859146005", text) assert (stats.remote_id, stats.views, stats.likes, stats.comments) == ("7709214727859146005", 2, 1, 0) assert session_stats.tiktok_row_stats("https://www.tiktok.com/@vortplay/video/1", "Processando\nTodos") is None def test_instagram_graphql_media(): payload = {"data": {"edges": [{"node": {"media": {"code": "Df2gT_ztuds", "play_count": 1499, "view_count": None, "like_count": 25, "comment_count": 1}}}, {"node": {"media": {"code": "Df2m7MGNR0T", "play_count": 31, "like_count": 2, "comment_count": 0}}}, {"node": {"code": "semNumero"}}]}} found = {} session_stats.instagram_media(payload, found) assert set(found) == {"Df2gT_ztuds", "Df2m7MGNR0T"} assert (found["Df2gT_ztuds"].views, found["Df2gT_ztuds"].likes, found["Df2gT_ztuds"].comments) == (1499, 25, 1)