1
0
Fork 0
mirror of synced 2024-06-17 01:34:40 +12:00
bulk-downloader-for-reddit/tests/site_downloaders/test_vreddit.py

44 lines
1.3 KiB
Python
Raw Normal View History

2022-04-26 04:53:59 +12:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2022-04-26 04:53:59 +12:00
from unittest.mock import MagicMock
import pytest
from bdfr.exceptions import NotADownloadableLinkError
from bdfr.resource import Resource
2022-07-15 17:05:07 +12:00
from bdfr.site_downloaders.vreddit import VReddit
2022-04-26 04:53:59 +12:00
@pytest.mark.online
@pytest.mark.slow
2022-12-03 18:11:17 +13:00
@pytest.mark.parametrize(
("test_url", "expected_hash"),
(("https://reddit.com/r/Unexpected/comments/z4xsuj/omg_thats_so_cute/", "1ffab5e5c0cc96db18108e4f37e8ca7f"),),
)
2022-04-26 04:53:59 +12:00
def test_find_resources_good(test_url: str, expected_hash: str):
test_submission = MagicMock()
test_submission.url = test_url
2022-07-15 17:05:07 +12:00
downloader = VReddit(test_submission)
2022-04-26 04:53:59 +12:00
resources = downloader.find_resources()
assert len(resources) == 1
assert isinstance(resources[0], Resource)
resources[0].download()
assert resources[0].hash.hexdigest() == expected_hash
@pytest.mark.online
2022-12-03 18:11:17 +13: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",
),
)
2022-04-26 04:53:59 +12:00
def test_find_resources_bad(test_url: str):
test_submission = MagicMock()
test_submission.url = test_url
2022-07-15 17:05:07 +12:00
downloader = VReddit(test_submission)
2022-04-26 04:53:59 +12:00
with pytest.raises(NotADownloadableLinkError):
downloader.find_resources()