1
0
Fork 0
mirror of synced 2024-06-02 18:34:37 +12:00
bulk-downloader-for-reddit/tests/site_downloaders/test_youtube.py

40 lines
1.3 KiB
Python
Raw Normal View History

2021-02-28 17:52:20 +13:00
#!/usr/bin/env python3
# coding=utf-8
from unittest.mock import MagicMock
2021-02-28 17:52:20 +13:00
import pytest
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
@pytest.mark.parametrize(('test_url', 'expected_hash'), (
2021-04-12 21:00:12 +12:00
('https://www.youtube.com/watch?v=uSm2VDgRIUs', 'f70b704b4b78b9bb5cd032bfc26e4971'),
2021-04-05 18:12:05 +12:00
('https://www.youtube.com/watch?v=m-tKnjFwleU', '30314930d853afff8ebc7d8c36a5b833'),
2021-02-28 17:52:20 +13:00
))
def test_find_resources_good(test_url: str, expected_hash: str):
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)
resources[0].download(120)
2021-02-28 17:52:20 +13:00
assert resources[0].hash.hexdigest() == expected_hash
@pytest.mark.online
@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'),
))
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()