48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""Tests for URL extractors."""
|
|
|
|
from src.extractors import extract_media_url
|
|
from src.extractors.imgur import extract_imgur_url
|
|
|
|
|
|
class TestExtractMediaUrl:
|
|
def test_direct_image_passthrough(self):
|
|
url = "https://i.redd.it/test123.jpg"
|
|
result_url, result_type = extract_media_url(url, "image")
|
|
assert result_url == url
|
|
assert result_type == "image"
|
|
|
|
def test_unknown_domain_passthrough(self):
|
|
url = "https://example.com/image.jpg"
|
|
result_url, result_type = extract_media_url(url, "image")
|
|
assert result_url == url
|
|
assert result_type == "image"
|
|
|
|
|
|
class TestImgurExtractor:
|
|
def test_direct_imgur_url(self):
|
|
url = "https://i.imgur.com/abc123.jpg"
|
|
result_url, result_type = extract_imgur_url(url)
|
|
assert result_url == url
|
|
assert result_type == "image"
|
|
|
|
def test_gifv_to_mp4(self):
|
|
url = "https://i.imgur.com/abc123.gifv"
|
|
result_url, result_type = extract_imgur_url(url)
|
|
assert result_url == "https://i.imgur.com/abc123.mp4"
|
|
assert result_type == "video"
|
|
|
|
def test_imgur_page_url(self):
|
|
url = "https://imgur.com/abc123"
|
|
result_url, result_type = extract_imgur_url(url)
|
|
assert result_url == "https://i.imgur.com/abc123.jpg"
|
|
assert result_type == "image"
|
|
|
|
def test_imgur_album_unsupported(self):
|
|
url = "https://imgur.com/a/abc123"
|
|
result_url, _result_type = extract_imgur_url(url)
|
|
assert result_url is None
|
|
|
|
def test_imgur_gallery_unsupported(self):
|
|
url = "https://imgur.com/gallery/abc123"
|
|
result_url, _result_type = extract_imgur_url(url)
|
|
assert result_url is None
|