51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
"""Outils des tests du collecteur : configuration, client YouTube simulé, vidéos."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
import psycopg
|
|
|
|
from shortstats.config import CollectorConfig
|
|
from shortstats.youtube import YouTubeClient
|
|
|
|
from .fake_youtube import CHANNEL
|
|
|
|
NOW = datetime(2026, 10, 31, 12, 0, tzinfo=timezone.utc)
|
|
|
|
BS = "\\"
|
|
|
|
U_E9 = BS + "u" + "00e9"
|
|
|
|
TEXTS = [
|
|
"Super chat !", "Le château", "CHAT noir", "chat noir", "applepie", "Apple Pie", "saison 2", "Saison deux",
|
|
"épisode12", "ÉP 3", "merci beaucoup", "Un grand merci", "merci\n", "merci \n", "merci\nà tous", "bravo\nmerci",
|
|
"ligne\nbravo\nfin", "version 1.5", "1x5", "123", "été", "ÉTÉ", "Un été", "aab", "?!?", "non merci",
|
|
"TV", "tv", "chien et chat", "la la", "la\nla", "tab\there", "", "x\ty", "fin", "fin\n", "fin\n\n", "a\nb",
|
|
"c'est la fin", "chat\r\nnoir", "wow...", "wow...\n", "xxy", "été", "Café!", "1234", "\U0001f600",
|
|
]
|
|
|
|
|
|
def iso(dt: datetime) -> str:
|
|
return dt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
|
|
def make_cfg(url, **over):
|
|
base = dict(database_url=url, api_key="test-key", shorts_playlist_prefix="UUSH",
|
|
shorts_max_duration_s=None, max_attempts=2, run_retention_days=90)
|
|
base.update(over)
|
|
return CollectorConfig(**base)
|
|
|
|
|
|
def client(fake):
|
|
return YouTubeClient("test-key", "https://yt.test/youtube/v3", transport=fake.transport())
|
|
|
|
|
|
def insert_video(url, vid, published, status="pending", channel=CHANNEL):
|
|
with psycopg.connect(url, autocommit=True) as conn:
|
|
conn.execute("""INSERT INTO shortstats.video (video_id, channel_id, published_at, status)
|
|
VALUES (%s, %s, %s, %s)""", (vid, channel, published, status))
|
|
|
|
|
|
def calls(fake, path):
|
|
return [c for c in fake.calls if c[0] == path]
|