1
0
Fork 0
mirror of synced 2024-06-02 02:14:37 +12:00
bulk-downloader-for-reddit/tests/test_resource.py

41 lines
1.3 KiB
Python
Raw Normal View History

2021-02-26 22:05:19 +13:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2021-02-26 22:05:19 +13:00
from unittest.mock import MagicMock
2021-02-26 22:05:19 +13:00
2021-04-18 23:24:11 +12:00
import pytest
2021-04-12 19:58:32 +12:00
from bdfr.resource import Resource
2021-02-26 22:05:19 +13:00
2022-12-03 18:11:17 +13:00
@pytest.mark.parametrize(
("test_url", "expected"),
(
("test.png", ".png"),
("another.mp4", ".mp4"),
("test.jpeg", ".jpeg"),
("http://www.random.com/resource.png", ".png"),
("https://www.resource.com/test/example.jpg", ".jpg"),
("hard.png.mp4", ".mp4"),
("https://preview.redd.it/7zkmr1wqqih61.png?width=237&format=png&auto=webp&s=19de214e634cbcad99", ".png"),
("test.jpg#test", ".jpg"),
("test.jpg?width=247#test", ".jpg"),
("https://www.test.com/test/test2/example.png?random=test#thing", ".png"),
),
)
2021-02-26 22:05:19 +13:00
def test_resource_get_extension(test_url: str, expected: str):
2021-07-27 15:39:49 +12:00
test_resource = Resource(MagicMock(), test_url, lambda: None)
2021-02-26 22:05:19 +13:00
result = test_resource._determine_extension()
assert result == expected
2021-02-26 22:23:45 +13:00
@pytest.mark.online
2022-12-03 18:11:17 +13:00
@pytest.mark.parametrize(
("test_url", "expected_hash"),
(("https://www.iana.org/_img/2013.1/iana-logo-header.svg", "426b3ac01d3584c820f3b7f5985d6623"),),
)
2021-02-26 22:23:45 +13:00
def test_download_online_resource(test_url: str, expected_hash: str):
test_resource = Resource(MagicMock(), test_url, Resource.retry_download(test_url))
2021-07-27 15:39:49 +12:00
test_resource.download()
2021-02-26 22:23:45 +13:00
assert test_resource.hash.hexdigest() == expected_hash