2021-02-27 11:26:42 +13:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
from unittest.mock import Mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2021-04-12 19:58:32 +12:00
|
|
|
from bdfr.resource import Resource
|
|
|
|
from bdfr.site_downloaders.redgifs import Redgifs
|
2021-02-27 11:26:42 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.parametrize(('test_url', 'expected'), (
|
2021-03-11 00:10:20 +13:00
|
|
|
('https://redgifs.com/watch/frighteningvictorioussalamander',
|
|
|
|
'https://thumbs2.redgifs.com/FrighteningVictoriousSalamander.mp4'),
|
|
|
|
('https://redgifs.com/watch/springgreendecisivetaruca',
|
|
|
|
'https://thumbs2.redgifs.com/SpringgreenDecisiveTaruca.mp4'),
|
2021-07-27 15:12:50 +12:00
|
|
|
('https://www.redgifs.com/watch/palegoldenrodrawhalibut',
|
|
|
|
'https://thumbs2.redgifs.com/PalegoldenrodRawHalibut.mp4'),
|
2021-02-27 11:26:42 +13:00
|
|
|
))
|
|
|
|
def test_get_link(test_url: str, expected: str):
|
|
|
|
result = Redgifs._get_link(test_url)
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
|
2021-03-11 00:10:20 +13:00
|
|
|
('https://redgifs.com/watch/frighteningvictorioussalamander', '4007c35d9e1f4b67091b5f12cffda00a'),
|
|
|
|
('https://redgifs.com/watch/springgreendecisivetaruca', '8dac487ac49a1f18cc1b4dabe23f0869'),
|
2021-06-30 13:59:38 +12:00
|
|
|
('https://redgifs.com/watch/leafysaltydungbeetle', '076792c660b9c024c0471ef4759af8bd'),
|
2021-07-27 15:12:50 +12:00
|
|
|
('https://www.redgifs.com/watch/palegoldenrodrawhalibut', '46d5aa77fe80c6407de1ecc92801c10e'),
|
2021-02-27 11:26:42 +13:00
|
|
|
))
|
|
|
|
def test_download_resource(test_url: str, expected_hash: str):
|
2021-03-31 14:07:02 +13:00
|
|
|
mock_submission = Mock()
|
2021-02-27 11:26:42 +13:00
|
|
|
mock_submission.url = test_url
|
|
|
|
test_site = Redgifs(mock_submission)
|
|
|
|
resources = test_site.find_resources()
|
|
|
|
assert len(resources) == 1
|
|
|
|
assert isinstance(resources[0], Resource)
|
2021-07-27 15:39:49 +12:00
|
|
|
resources[0].download()
|
2021-02-27 11:26:42 +13:00
|
|
|
assert resources[0].hash.hexdigest() == expected_hash
|