1
0
Fork 0
mirror of synced 2024-06-26 10:00:20 +12:00
bulk-downloader-for-reddit/bulkredditdownloader/tests/test_resource.py

32 lines
1 KiB
Python
Raw Normal View History

2021-02-26 22:05:19 +13:00
#!/usr/bin/env python3
# coding=utf-8
import pytest
from bulkredditdownloader.resource import Resource
@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'),
2021-03-10 17:09:27 +13:00
('https://preview.redd.it/7zkmr1wqqih61.png?width=237&format=png&auto=webp&s=19de214e634cbcad99', '.png'),
2021-02-26 22:05:19 +13:00
))
def test_resource_get_extension(test_url: str, expected: str):
test_resource = Resource(None, test_url)
result = test_resource._determine_extension()
assert result == expected
2021-02-26 22:23:45 +13:00
@pytest.mark.online
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
('https://www.iana.org/_img/2013.1/iana-logo-header.svg', '426b3ac01d3584c820f3b7f5985d6623'),
))
def test_download_online_resource(test_url: str, expected_hash: str):
test_resource = Resource(None, test_url)
test_resource.download()
assert test_resource.hash.hexdigest() == expected_hash