1
0
Fork 0
mirror of synced 2024-05-17 10:42:39 +12:00
bulk-downloader-for-reddit/tests/site_downloaders/test_download_factory.py

94 lines
3.9 KiB
Python
Raw Normal View History

2021-02-11 12:09:37 +13:00
#!/usr/bin/env python3
# coding=utf-8
2021-03-01 12:51:44 +13:00
import praw
2021-02-11 12:09:37 +13:00
import pytest
2021-04-12 19:58:32 +12:00
from bdfr.exceptions import NotADownloadableLinkError
from bdfr.site_downloaders.base_downloader import BaseDownloader
from bdfr.site_downloaders.direct import Direct
from bdfr.site_downloaders.download_factory import DownloadFactory
from bdfr.site_downloaders.erome import Erome
from bdfr.site_downloaders.fallback_downloaders.ytdlp_fallback import YtdlpFallback
2021-04-12 19:58:32 +12:00
from bdfr.site_downloaders.gallery import Gallery
from bdfr.site_downloaders.gfycat import Gfycat
from bdfr.site_downloaders.imgur import Imgur
2021-06-25 19:47:49 +12:00
from bdfr.site_downloaders.pornhub import PornHub
2021-04-12 19:58:32 +12:00
from bdfr.site_downloaders.redgifs import Redgifs
from bdfr.site_downloaders.self_post import SelfPost
2022-07-15 17:05:07 +12:00
from bdfr.site_downloaders.vreddit import VReddit
2021-04-12 19:58:32 +12:00
from bdfr.site_downloaders.youtube import Youtube
2021-02-11 12:09:37 +13:00
2021-05-02 21:48:25 +12:00
@pytest.mark.online
@pytest.mark.parametrize(('test_submission_url', 'expected_class'), (
('https://www.reddit.com/r/TwoXChromosomes/comments/lu29zn/i_refuse_to_live_my_life'
'_in_anything_but_comfort/', SelfPost),
2022-09-20 19:33:51 +12:00
('https://i.imgur.com/bZx1SJQ.jpg', Imgur),
('https://i.redd.it/affyv0axd5k61.png', Direct),
2022-09-20 19:33:51 +12:00
('https://imgur.com/3ls94yv.jpeg', Imgur),
('https://i.imgur.com/BuzvZwb.gifv', Imgur),
2021-04-07 01:38:52 +12:00
('https://imgur.com/BuzvZwb.gifv', Imgur),
2022-09-20 19:33:51 +12:00
('https://i.imgur.com/6fNdLst.gif', Imgur),
('https://imgur.com/a/MkxAzeg', Imgur),
2021-11-15 14:03:12 +13:00
('https://i.imgur.com/OGeVuAe.giff', Imgur),
('https://www.reddit.com/gallery/lu93m7', Gallery),
('https://gfycat.com/concretecheerfulfinwhale', Gfycat),
('https://www.erome.com/a/NWGw0F09', Erome),
('https://youtube.com/watch?v=Gv8Wz74FjVA', Youtube),
('https://redgifs.com/watch/courageousimpeccablecanvasback', Redgifs),
('https://www.gifdeliverynetwork.com/repulsivefinishedandalusianhorse', Redgifs),
('https://youtu.be/DevfjHOhuFc', Youtube),
('https://m.youtube.com/watch?v=kr-FeojxzUM', Youtube),
2022-09-20 19:33:51 +12:00
('https://i.imgur.com/3SKrQfK.jpg?1', Imgur),
('https://dynasty-scans.com/system/images_images/000/017/819/original/80215103_p0.png?1612232781', Direct),
2021-04-08 13:24:55 +12:00
('https://m.imgur.com/a/py3RW0j', Imgur),
2022-07-15 17:05:07 +12:00
('https://v.redd.it/9z1dnk3xr5k61', VReddit),
('https://streamable.com/dt46y', YtdlpFallback),
('https://vimeo.com/channels/31259/53576664', YtdlpFallback),
('http://video.pbs.org/viralplayer/2365173446/', YtdlpFallback),
2021-06-25 19:47:49 +12:00
('https://www.pornhub.com/view_video.php?viewkey=ph5a2ee0461a8d0', PornHub),
2021-12-19 16:44:24 +13:00
('https://www.patreon.com/posts/minecart-track-59346560', Gallery),
2022-07-15 17:05:07 +12:00
('https://v.redd.it/9z1dnk3xr5k61', VReddit)
2021-03-01 12:51:44 +13:00
))
def test_factory_lever_good(test_submission_url: str, expected_class: BaseDownloader, reddit_instance: praw.Reddit):
result = DownloadFactory.pull_lever(test_submission_url)
2021-03-01 12:51:44 +13:00
assert result is expected_class
2021-02-11 12:09:37 +13:00
2021-03-01 12:51:44 +13:00
@pytest.mark.parametrize('test_url', (
'random.com',
'bad',
'https://www.google.com/',
'https://www.google.com',
'https://www.google.com/test',
'https://www.google.com/test/',
2021-03-01 12:51:44 +13:00
))
def test_factory_lever_bad(test_url: str):
with pytest.raises(NotADownloadableLinkError):
DownloadFactory.pull_lever(test_url)
2021-04-18 23:24:11 +12:00
@pytest.mark.parametrize(('test_url', 'expected'), (
('www.test.com/test.png', 'test.com/test.png'),
('www.test.com/test.png?test_value=random', 'test.com/test.png'),
('https://youtube.com/watch?v=Gv8Wz74FjVA', 'youtube.com/watch'),
('https://i.imgur.com/BuzvZwb.gifv', 'i.imgur.com/BuzvZwb.gifv'),
))
2021-05-25 20:51:00 +12:00
def test_sanitise_url(test_url: str, expected: str):
2021-05-25 20:51:24 +12:00
result = DownloadFactory.sanitise_url(test_url)
2021-04-18 23:24:11 +12:00
assert result == expected
2021-05-25 20:59:32 +12:00
@pytest.mark.parametrize(('test_url', 'expected'), (
('www.example.com/test.asp', True),
('www.example.com/test.html', True),
('www.example.com/test.js', True),
('www.example.com/test.xhtml', True),
('www.example.com/test.mp4', False),
('www.example.com/test.png', False),
))
def test_is_web_resource(test_url: str, expected: bool):
result = DownloadFactory.is_web_resource(test_url)
assert result == expected