- tests/test_auth.py: enable/disable via env, valid/invalid creds - tests/test_rate_limit.py: bucket math + window expiry - tests/test_router_media.py: path traversal (file/thumb), paginated subreddits/authors, blacklist preview shape, DELETE flow, cleanup-by-type 400 paths - tests/test_router_stats.py: cache TTL, .json exclusion, missing dir - tests/test_router_favorites.py: paginated favorites/authors, no N+1 (query count), favorites_only filter - tests/test_router_config.py: CRUD subreddits/users/blacklist - tests/test_config_manager.py: case-insensitive dedupe, blacklist removes from collection, domain normalization - tests/test_extractors_imgur.py: i.imgur direct, gifv->mp4, albums/galleries -> None src/database.py: resolve RMC_DB_PATH lazily in Database() so tests can monkeypatch the env per case (no more module-import capture) Result: 135 passed (was 77). Coverage 55% global; 100% on auth/imgur, 96% rate_limit, 84% stats router, 80% config_manager.
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Tests for the Imgur URL extractor."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from src.extractors.imgur import extract_imgur_url
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"url,expected_url,expected_type",
|
|
[
|
|
("https://i.imgur.com/abc123.jpg", "https://i.imgur.com/abc123.jpg", "image"),
|
|
("https://i.imgur.com/abc123.png", "https://i.imgur.com/abc123.png", "image"),
|
|
(
|
|
"https://i.imgur.com/abc123.gifv",
|
|
"https://i.imgur.com/abc123.mp4",
|
|
"video",
|
|
),
|
|
("https://imgur.com/abc123", "https://i.imgur.com/abc123.jpg", "image"),
|
|
("https://imgur.com/abc123.jpg", "https://i.imgur.com/abc123.jpg", "image"),
|
|
],
|
|
)
|
|
def test_extract_imgur_url_variants(url, expected_url, expected_type):
|
|
result, media_type = extract_imgur_url(url)
|
|
assert result == expected_url
|
|
assert media_type == expected_type
|
|
|
|
|
|
def test_album_returns_none():
|
|
result, _ = extract_imgur_url("https://imgur.com/a/abc123")
|
|
assert result is None
|
|
|
|
|
|
def test_gallery_returns_none():
|
|
result, _ = extract_imgur_url("https://imgur.com/gallery/abc123")
|
|
assert result is None
|
|
|
|
|
|
def test_path_with_no_id_returns_none():
|
|
result, _ = extract_imgur_url("https://imgur.com/")
|
|
assert result is None
|