chore: checkpoint baseline (routers, tests, pyproject)
This commit is contained in:
parent
a58498a315
commit
986f1dfef4
37 changed files with 2527 additions and 1664 deletions
47
tests/test_downloader.py
Normal file
47
tests/test_downloader.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"""Tests for downloader module."""
|
||||
|
||||
import hashlib
|
||||
|
||||
from src.config import DownloadConfig, RateLimitConfig
|
||||
from src.downloader import Downloader
|
||||
|
||||
|
||||
class TestDownloader:
|
||||
def test_compute_hash(self, tmp_path):
|
||||
config = DownloadConfig(output_dir=str(tmp_path))
|
||||
rate = RateLimitConfig(download_delay_seconds=0)
|
||||
downloader = Downloader(config, rate)
|
||||
|
||||
test_file = tmp_path / "test.txt"
|
||||
test_file.write_bytes(b"hello world")
|
||||
|
||||
file_hash = downloader.compute_hash(str(test_file))
|
||||
expected = hashlib.md5(b"hello world").hexdigest()
|
||||
assert file_hash == expected
|
||||
|
||||
def test_get_extension_from_url(self, tmp_path):
|
||||
config = DownloadConfig(output_dir=str(tmp_path))
|
||||
rate = RateLimitConfig(download_delay_seconds=0)
|
||||
downloader = Downloader(config, rate)
|
||||
|
||||
assert downloader._get_extension("https://example.com/image.jpg", None) == ".jpg"
|
||||
assert downloader._get_extension("https://example.com/image.png", None) == ".png"
|
||||
assert downloader._get_extension("https://example.com/video.mp4", None) == ".mp4"
|
||||
|
||||
def test_get_extension_from_content_type(self, tmp_path):
|
||||
config = DownloadConfig(output_dir=str(tmp_path))
|
||||
rate = RateLimitConfig(download_delay_seconds=0)
|
||||
downloader = Downloader(config, rate)
|
||||
|
||||
assert downloader._get_extension("https://example.com/blah", "image/jpeg") == ".jpg"
|
||||
assert downloader._get_extension("https://example.com/blah", "image/png") == ".png"
|
||||
assert downloader._get_extension("https://example.com/blah", "video/mp4") == ".mp4"
|
||||
|
||||
def test_sanitize_name(self, tmp_path):
|
||||
config = DownloadConfig(output_dir=str(tmp_path))
|
||||
rate = RateLimitConfig(download_delay_seconds=0)
|
||||
downloader = Downloader(config, rate)
|
||||
|
||||
assert downloader._sanitize_name("normal_name") == "normal_name"
|
||||
assert downloader._sanitize_name("has spaces!@#") == "has_spaces___"
|
||||
assert downloader._sanitize_name("with-dash") == "with-dash"
|
||||
Loading…
Add table
Add a link
Reference in a new issue