"""Pages du site : aide, plein écran, vidéos."""
from __future__ import annotations
import re
import psycopg
from shortstats.web import chart_catalog
from ..outils.base import seed_comments, seed_videos
from ..outils.site import ORIGIN, login
def test_help_page(app_client):
r = app_client.get("/help", follow_redirects=False)
assert r.status_code == 303 and r.headers["location"] == "/login"
login(app_client)
page = app_client.get("/help").text
assert 'aria-current="page">Aide' in page and 'id="help-q"' in page and "js/help.js" in page
# sections attendues et ancres utilisées ailleurs (page Thèmes -> /help#themes)
for anchor in ("demarrer", "diagrammes", "axes-inverses", "analyse-thematique", "plein-ecran", "calendrier",
"themes", "regex-syntaxe", "faq"):
assert f'id="{anchor}"' in page, anchor
# calendrier tiré du code : 151 étapes, une ligne par rythme
assert "à 151 étapes" in page
rows = re.findall(r"
| (Toutes les|Tous les)[^<]* | (\d+) | ", page)
assert [int(n) for _, n in rows] == [24, 16, 16, 23, 48, 24] and sum(int(n) for _, n in rows) == len(chart_catalog.STEPS)
assert "1 h à 24 h" in page and "13 mois à 36 mois" in page
assert chr(0x2014) not in page # pas de tiret cadratin
def test_fullscreen_buttons_and_nav(app_client):
login(app_client)
dash = app_client.get("/").text
assert 'data-action="full"' in dash and "Plein écran" in dash
assert '7 j' in page
assert "Vidéos · Shorts Stats" in page and "J+7" not in page and "épinglé" not in page
# filtres : état et chaîne (valeurs inconnues ignorées)
tracking = evo.get("/videos?state=j7_done").text
assert "evo00000011" not in tracking and "vid00000000" in tracking
assert "evo00000011" in evo.get("/videos?state=tracking").text
assert "Aucune vidéo pour ces critères" in evo.get("/videos?state=excluded").text
assert evo.get("/videos?state=inconnu&channel=pas-un-id").status_code == 200
with psycopg.connect(clean_db["owner"]) as conn:
other = conn.execute("SELECT channel_id FROM shortstats.channel WHERE youtube_title = 'Autre chaîne'").fetchone()[0]
only = evo.get(f"/videos?channel={other}").text
assert "evo00000000" in only and "evo00000001" not in only
def test_videos_page_shows_comment_themes(app_client, clean_db):
seed_videos(clean_db["owner"], n=4)
seed_comments(clean_db["owner"], n=4)
login(app_client)
page = app_client.get("/videos").text
# vid00000003 : 5 commentaires relevés, dont 3 « Apothecary Diaries » et 3 « applepie » (un commentaire
# relève des deux)
row = page[page.index("vid00000003"):page.index("vid00000002")]
assert "5 relevé(s)" in row
assert 'applepie 3 (60 %)' in row
assert 'Apothecary Diaries 3 (60 %)' in row
def test_video_snapshots_api(evo):
rows = evo.get("/api/videos/evo00000003/snapshots").json()
assert [r["step"] for r in rows][:3] == ["1 h", "2 h", "3 h"] and len(rows) == 12
assert set(rows[0]) == {"step", "taken_at", "age_hours", "views", "likes", "comments", "comments_read", "themes", "estimated"}
assert rows[0]["comments_read"] > 0 and {t[0] for t in rows[0]["themes"]} <= {"applepie", "Apothecary Diaries"}
assert evo.get("/api/videos/inconnue000/snapshots").status_code == 404
assert evo.get("/api/videos/pas%20valide/snapshots").status_code == 404
evo.post("/logout", headers={"Origin": ORIGIN})
assert evo.get("/api/videos/evo00000003/snapshots").status_code == 401