2021-06-25 19:47:49 +12:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2021-11-05 16:23:55 +13:00
|
|
|
from bdfr.exceptions import SiteDownloaderError
|
2021-06-25 19:47:49 +12:00
|
|
|
from bdfr.resource import Resource
|
|
|
|
from bdfr.site_downloaders.pornhub import PornHub
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
|
|
|
@pytest.mark.slow
|
2022-12-03 18:11:17 +13:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("test_url", "expected_hash"),
|
|
|
|
(("https://www.pornhub.com/view_video.php?viewkey=ph6074c59798497", "ad52a0f4fce8f99df0abed17de1d04c7"),),
|
|
|
|
)
|
2022-11-09 09:37:21 +13:00
|
|
|
def test_hash_resources_good(test_url: str, expected_hash: str):
|
2021-06-25 19:47:49 +12:00
|
|
|
test_submission = MagicMock()
|
|
|
|
test_submission.url = test_url
|
|
|
|
downloader = PornHub(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-06-25 19:47:49 +12:00
|
|
|
assert resources[0].hash.hexdigest() == expected_hash
|
2021-11-05 16:23:55 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.online
|
2022-12-03 18:11:17 +13:00
|
|
|
@pytest.mark.parametrize("test_url", ("https://www.pornhub.com/view_video.php?viewkey=ph5ede121f0d3f8",))
|
2021-11-05 16:23:55 +13:00
|
|
|
def test_find_resources_good(test_url: str):
|
|
|
|
test_submission = MagicMock()
|
|
|
|
test_submission.url = test_url
|
|
|
|
downloader = PornHub(test_submission)
|
|
|
|
with pytest.raises(SiteDownloaderError):
|
|
|
|
downloader.find_resources()
|