96 lines
2 KiB
Python
96 lines
2 KiB
Python
"""Shared test fixtures."""
|
|
|
|
import pytest
|
|
|
|
from src.config import (
|
|
BlacklistConfig,
|
|
Config,
|
|
DownloadConfig,
|
|
LoggingConfig,
|
|
RateLimitConfig,
|
|
SubredditTarget,
|
|
TargetsConfig,
|
|
UserTarget,
|
|
)
|
|
from src.database import Database
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_dir(tmp_path):
|
|
"""Provide a temporary directory."""
|
|
return tmp_path
|
|
|
|
|
|
@pytest.fixture
|
|
def db(tmp_path):
|
|
"""Provide a fresh test database."""
|
|
db_path = tmp_path / "test_media.db"
|
|
return Database(db_path=str(db_path))
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_config():
|
|
"""Provide a sample configuration."""
|
|
return Config(
|
|
targets=TargetsConfig(
|
|
subreddits=[SubredditTarget(name="pics", limit=25, sort="hot")],
|
|
users=[UserTarget(name="testuser", limit=10)],
|
|
),
|
|
download=DownloadConfig(
|
|
output_dir="./test_downloads",
|
|
media_types=["image", "video", "gif"],
|
|
min_score=10,
|
|
skip_nsfw=True,
|
|
max_file_size_mb=100,
|
|
),
|
|
rate_limit=RateLimitConfig(requests_per_minute=10, download_delay_seconds=0.1),
|
|
logging=LoggingConfig(level="DEBUG", file=None),
|
|
blacklist=BlacklistConfig(
|
|
authors=["spammer"],
|
|
subreddits=["spam_sub"],
|
|
title_keywords=["buy now"],
|
|
domains=["malware.com"],
|
|
),
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def config_file(tmp_path):
|
|
"""Provide a temporary config file."""
|
|
config_content = """
|
|
targets:
|
|
subreddits:
|
|
- name: "pics"
|
|
limit: 25
|
|
sort: "hot"
|
|
users:
|
|
- name: "testuser"
|
|
limit: 10
|
|
|
|
download:
|
|
output_dir: "./downloads"
|
|
media_types:
|
|
- "image"
|
|
- "video"
|
|
min_score: 10
|
|
skip_nsfw: true
|
|
max_file_size_mb: 100
|
|
|
|
rate_limit:
|
|
requests_per_minute: 10
|
|
download_delay_seconds: 2
|
|
|
|
logging:
|
|
level: "INFO"
|
|
file: null
|
|
|
|
blacklist:
|
|
authors:
|
|
- "spammer"
|
|
subreddits: []
|
|
title_keywords: []
|
|
domains: []
|
|
"""
|
|
config_path = tmp_path / "config.yaml"
|
|
config_path.write_text(config_content)
|
|
return str(config_path)
|