2021-02-28 17:52:20 +13:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# coding=utf-8
|
|
|
|
|
2021-04-04 05:25:58 +12:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
2021-02-28 17:52:20 +13:00
|
|
|
import pytest
|
|
|
|
|
2021-05-15 23:35:16 +12:00
|
|
|
from bdfr.exceptions import NotADownloadableLinkError
|
2021-04-12 19:58:32 +12:00
|
|
|
from bdfr.resource import Resource
|
|
|
|
from bdfr.site_downloaders.youtube import Youtube
|
2021-02-28 17:52:20 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
2021-03-13 18:11:59 +13:00
|
|
|
@pytest.mark.slow
|
2021-04-04 05:25:58 +12:00
|
|
|
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
|
2021-10-02 15:23:13 +13:00
|
|
|
('https://www.youtube.com/watch?v=uSm2VDgRIUs', '2d60b54582df5b95ec72bb00b580d2ff'),
|
|
|
|
('https://www.youtube.com/watch?v=GcI7nxQj7HA', '5db0fc92a0a7fb9ac91e63505eea9cf0'),
|
2021-02-28 17:52:20 +13:00
|
|
|
))
|
2021-05-15 23:35:16 +12:00
|
|
|
def test_find_resources_good(test_url: str, expected_hash: str):
|
2021-04-04 05:25:58 +12:00
|
|
|
test_submission = MagicMock()
|
|
|
|
test_submission.url = test_url
|
2021-02-28 17:52:20 +13:00
|
|
|
downloader = Youtube(test_submission)
|
|
|
|
resources = downloader.find_resources()
|
|
|
|
assert len(resources) == 1
|
|
|
|
assert isinstance(resources[0], Resource)
|
2021-07-27 15:39:49 +12:00
|
|
|
resources[0].download()
|
2021-02-28 17:52:20 +13:00
|
|
|
assert resources[0].hash.hexdigest() == expected_hash
|
2021-05-15 23:35:16 +12:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
2021-07-02 16:57:10 +12:00
|
|
|
@pytest.mark.parametrize('test_url', (
|
|
|
|
'https://www.polygon.com/disney-plus/2020/5/14/21249881/gargoyles-animated-series-disney-plus-greg-weisman'
|
|
|
|
'-interview-oj-simpson-goliath-chronicles',
|
2021-05-15 23:35:16 +12:00
|
|
|
))
|
|
|
|
def test_find_resources_bad(test_url: str):
|
|
|
|
test_submission = MagicMock()
|
|
|
|
test_submission.url = test_url
|
|
|
|
downloader = Youtube(test_submission)
|
|
|
|
with pytest.raises(NotADownloadableLinkError):
|
|
|
|
downloader.find_resources()
|