2021-02-26 22:45:03 +13:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
from unittest.mock import Mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from bulkredditdownloader.resource import Resource
|
|
|
|
from bulkredditdownloader.site_downloaders.gif_delivery_network import GifDeliveryNetwork
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.parametrize(('test_url', 'expected'), (
|
2021-03-18 00:02:25 +13:00
|
|
|
('https://www.gifdeliverynetwork.com/regalshoddyhorsechestnutleafminer',
|
|
|
|
'https://thumbs2.redgifs.com/RegalShoddyHorsechestnutleafminer.mp4'),
|
|
|
|
('https://www.gifdeliverynetwork.com/maturenexthippopotamus',
|
|
|
|
'https://thumbs2.redgifs.com/MatureNextHippopotamus.mp4'),
|
|
|
|
('https://thumbs2.redgifs.com/MatureNextHippopotamus.mp4',
|
|
|
|
'https://thumbs2.redgifs.com/MatureNextHippopotamus.mp4'),
|
2021-02-26 22:45:03 +13:00
|
|
|
))
|
|
|
|
def test_get_link(test_url: str, expected: str):
|
|
|
|
result = GifDeliveryNetwork._get_link(test_url)
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
|
2021-03-18 00:02:25 +13:00
|
|
|
('https://www.gifdeliverynetwork.com/maturenexthippopotamus', '9bec0a9e4163a43781368ed5d70471df'),
|
|
|
|
('https://www.gifdeliverynetwork.com/regalshoddyhorsechestnutleafminer', '8afb4e2c090a87140230f2352bf8beba'),
|
2021-02-26 22:45:03 +13:00
|
|
|
))
|
|
|
|
def test_download_resource(test_url: str, expected_hash: str):
|
2021-03-18 00:02:25 +13:00
|
|
|
mock_submission = Mock()
|
2021-02-26 22:45:03 +13:00
|
|
|
mock_submission.url = test_url
|
|
|
|
test_site = GifDeliveryNetwork(mock_submission)
|
|
|
|
resources = test_site.find_resources()
|
|
|
|
assert len(resources) == 1
|
|
|
|
assert isinstance(resources[0], Resource)
|
|
|
|
resources[0].download()
|
|
|
|
assert resources[0].hash.hexdigest() == expected_hash
|