61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture()
|
|
def temp_db(monkeypatch):
|
|
td = tempfile.mkdtemp()
|
|
db_path = Path(td) / "test.db"
|
|
monkeypatch.setattr("app.config.settings.sqlite_path", db_path)
|
|
monkeypatch.setattr("app.config.settings.data_dir", Path(td))
|
|
from app import db
|
|
|
|
db.init_db()
|
|
return db
|
|
|
|
|
|
@pytest.fixture()
|
|
def yt_group(temp_db):
|
|
from app import db
|
|
|
|
return db.create_channel_group(
|
|
name="Test YT",
|
|
platform="youtube",
|
|
channel_url="https://www.youtube.com/channel/UCtest123456789012345678",
|
|
urls=["https://www.youtube.com/watch?v=extra1"],
|
|
enabled=True,
|
|
)
|
|
|
|
|
|
@pytest.fixture()
|
|
def douyin_room(temp_db):
|
|
from app import db
|
|
|
|
return db.create_room("https://live.douyin.com/999888777666", note="test", enabled=True)
|
|
|
|
|
|
@pytest.fixture()
|
|
def active_yt_session(temp_db, yt_group):
|
|
from app import db
|
|
|
|
sess = db.start_session(
|
|
room_pk=yt_group["id"],
|
|
room_id="yt:UCtest123456789012345678",
|
|
source_url="https://www.youtube.com/watch?v=live1",
|
|
anchor_name="Test YT",
|
|
metadata={"platform": "youtube"},
|
|
)
|
|
db.touch_channel_group(
|
|
yt_group["id"],
|
|
last_status="live",
|
|
next_check_at=0,
|
|
active_session_id=sess["id"],
|
|
channel_id="UCtest123456789012345678",
|
|
)
|
|
return sess
|