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

48 lines
1.8 KiB
Python
Raw Normal View History

2021-02-27 13:35:43 +13:00
#!/usr/bin/env python3
# coding=utf-8
2021-10-20 13:51:28 +13:00
import re
2021-03-17 19:10:36 +13:00
from unittest.mock import MagicMock
2021-02-27 13:35:43 +13:00
import pytest
2021-04-12 19:58:32 +12:00
from bdfr.site_downloaders.erome import Erome
2021-02-27 13:35:43 +13:00
@pytest.mark.online
@pytest.mark.parametrize(('test_url', 'expected_urls'), (
('https://www.erome.com/a/vqtPuLXh', (
2022-09-22 18:31:42 +12:00
r'https://[a-z]\d+.erome.com/\d{3}/vqtPuLXh/KH2qBT99_480p.mp4',
)),
('https://www.erome.com/a/ORhX0FZz', (
2022-09-22 18:31:42 +12:00
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/9IYQocM9_480p.mp4',
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/9eEDc8xm_480p.mp4',
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/EvApC7Rp_480p.mp4',
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/LruobtMs_480p.mp4',
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/TJNmSUU5_480p.mp4',
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/X11Skh6Z_480p.mp4',
r'https://[a-z]\d+.erome.com/\d{3}/ORhX0FZz/bjlTkpn7_480p.mp4'
)),
2021-02-27 13:35:43 +13:00
))
def test_get_link(test_url: str, expected_urls: tuple[str]):
result = Erome. _get_links(test_url)
2021-10-20 13:51:28 +13:00
assert all([any([re.match(p, r) for r in result]) for p in expected_urls])
2021-02-27 13:35:43 +13:00
@pytest.mark.online
@pytest.mark.slow
2021-10-02 15:52:12 +13:00
@pytest.mark.parametrize(('test_url', 'expected_hashes_len'), (
('https://www.erome.com/a/vqtPuLXh', 1),
('https://www.erome.com/a/4tP3KI6F', 1),
2021-02-27 13:35:43 +13:00
))
2021-10-02 15:52:12 +13:00
def test_download_resource(test_url: str, expected_hashes_len: int):
2021-03-18 22:10:27 +13:00
# Can't compare hashes for this test, Erome doesn't return the exact same file from request to request so the hash
# will change back and forth randomly
2021-03-17 19:10:36 +13:00
mock_submission = MagicMock()
2021-02-27 13:35:43 +13:00
mock_submission.url = test_url
test_site = Erome(mock_submission)
resources = test_site.find_resources()
2021-10-02 15:52:12 +13:00
for res in resources:
res.download()
2021-02-27 13:35:43 +13:00
resource_hashes = [res.hash.hexdigest() for res in resources]
2021-10-02 15:52:12 +13:00
assert len(resource_hashes) == expected_hashes_len