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
|
2021-05-02 21:48:25 +12:00
|
|
|
from bdfr.site_downloaders.fallback_downloaders.youtubedl_fallback import YoutubeDlFallback
|
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
|
|
|
|
from bdfr.site_downloaders.redgifs import Redgifs
|
|
|
|
from bdfr.site_downloaders.self_post import SelfPost
|
|
|
|
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
|
2021-03-31 03:35:13 +13:00
|
|
|
@pytest.mark.parametrize(('test_submission_url', 'expected_class'), (
|
2021-04-04 05:25:58 +12:00
|
|
|
('https://www.reddit.com/r/TwoXChromosomes/comments/lu29zn/i_refuse_to_live_my_life'
|
|
|
|
'_in_anything_but_comfort/', SelfPost),
|
2021-03-31 03:35:13 +13:00
|
|
|
('https://i.imgur.com/bZx1SJQ.jpg', Direct),
|
|
|
|
('https://i.redd.it/affyv0axd5k61.png', Direct),
|
2021-04-04 04:41:56 +12:00
|
|
|
('https://imgur.com/3ls94yv.jpeg', Direct),
|
2021-03-31 03:35:13 +13:00
|
|
|
('https://i.imgur.com/BuzvZwb.gifv', Imgur),
|
2021-04-07 01:38:52 +12:00
|
|
|
('https://imgur.com/BuzvZwb.gifv', Imgur),
|
2021-03-31 03:35:13 +13:00
|
|
|
('https://i.imgur.com/6fNdLst.gif', Direct),
|
|
|
|
('https://imgur.com/a/MkxAzeg', 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),
|
2021-04-28 20:53:24 +12:00
|
|
|
('https://www.gifdeliverynetwork.com/repulsivefinishedandalusianhorse', Redgifs),
|
2021-03-31 03:35:13 +13:00
|
|
|
('https://youtu.be/DevfjHOhuFc', Youtube),
|
2021-04-03 04:51:00 +13:00
|
|
|
('https://m.youtube.com/watch?v=kr-FeojxzUM', Youtube),
|
2021-04-05 17:03:09 +12:00
|
|
|
('https://i.imgur.com/3SKrQfK.jpg?1', Direct),
|
|
|
|
('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),
|
2021-05-02 22:02:34 +12:00
|
|
|
('https://v.redd.it/9z1dnk3xr5k61', YoutubeDlFallback),
|
2021-05-02 21:53:01 +12:00
|
|
|
('https://streamable.com/dt46y', YoutubeDlFallback),
|
2021-05-02 21:48:25 +12:00
|
|
|
('https://vimeo.com/channels/31259/53576664', YoutubeDlFallback),
|
|
|
|
('http://video.pbs.org/viralplayer/2365173446/', YoutubeDlFallback),
|
2021-03-01 12:51:44 +13:00
|
|
|
))
|
2021-03-31 03:35:13 +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',
|
2021-03-30 20:08:08 +13:00
|
|
|
'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
|