1
0
Fork 0
mirror of synced 2024-06-28 11:00:40 +12:00
bulk-downloader-for-reddit/tests/site_downloaders/test_gallery.py

114 lines
3.3 KiB
Python
Raw Normal View History

2021-02-15 20:45:41 +13:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2021-02-15 20:45:41 +13:00
2021-03-17 19:27:26 +13:00
import praw
2021-02-15 20:45:41 +13:00
import pytest
2021-07-19 20:44:54 +12:00
from bdfr.exceptions import SiteDownloaderError
2021-04-12 19:58:32 +12:00
from bdfr.site_downloaders.gallery import Gallery
2021-02-15 20:45:41 +13:00
2021-03-17 23:42:35 +13:00
@pytest.mark.online
2022-12-03 18:11:17 +13:00
@pytest.mark.parametrize(
("test_ids", "expected"),
(
(
[
{"media_id": "18nzv9ch0hn61"},
{"media_id": "jqkizcch0hn61"},
{"media_id": "k0fnqzbh0hn61"},
{"media_id": "m3gamzbh0hn61"},
],
{
"https://i.redd.it/18nzv9ch0hn61.jpg",
"https://i.redd.it/jqkizcch0hn61.jpg",
"https://i.redd.it/k0fnqzbh0hn61.jpg",
"https://i.redd.it/m3gamzbh0hn61.jpg",
},
),
(
[
{"media_id": "04vxj25uqih61"},
{"media_id": "0fnx83kpqih61"},
{"media_id": "7zkmr1wqqih61"},
{"media_id": "u37k5gxrqih61"},
],
{
"https://i.redd.it/04vxj25uqih61.png",
"https://i.redd.it/0fnx83kpqih61.png",
"https://i.redd.it/7zkmr1wqqih61.png",
"https://i.redd.it/u37k5gxrqih61.png",
},
),
),
)
def test_gallery_get_links(test_ids: list[dict], expected: set[str]):
results = Gallery._get_links(test_ids)
2021-03-17 23:42:35 +13:00
assert set(results) == expected
2021-02-26 22:09:25 +13:00
@pytest.mark.online
2021-02-26 22:19:12 +13:00
@pytest.mark.reddit
2022-12-03 18:11:17 +13:00
@pytest.mark.parametrize(
("test_submission_id", "expected_hashes"),
(
(
"m6lvrh",
{
"5c42b8341dd56eebef792e86f3981c6a",
"8f38d76da46f4057bf2773a778e725ca",
"f5776f8f90491c8b770b8e0a6bfa49b3",
"fa1a43c94da30026ad19a9813a0ed2c2",
},
),
(
"ljyy27",
{
"359c203ec81d0bc00e675f1023673238",
"79262fd46bce5bfa550d878a3b898be4",
"808c35267f44acb523ce03bfa5687404",
"ec8b65bdb7f1279c4b3af0ea2bbb30c3",
},
),
(
"obkflw",
{
"65163f685fb28c5b776e0e77122718be",
"2a337eb5b13c34d3ca3f51b5db7c13e9",
},
),
(
"rb3ub6",
{ # patreon post
"748a976c6cedf7ea85b6f90e7cb685c7",
"839796d7745e88ced6355504e1f74508",
"bcdb740367d0f19f97a77e614b48a42d",
"0f230b8c4e5d103d35a773fab9814ec3",
"e5192d6cb4f84c4f4a658355310bf0f9",
"91cbe172cd8ccbcf049fcea4204eb979",
},
),
),
)
2021-03-18 14:01:34 +13:00
def test_gallery_download(test_submission_id: str, expected_hashes: set[str], reddit_instance: praw.Reddit):
2021-03-17 19:27:26 +13:00
test_submission = reddit_instance.submission(id=test_submission_id)
gallery = Gallery(test_submission)
2021-02-25 23:40:08 +13:00
results = gallery.find_resources()
2021-07-27 15:39:49 +12:00
[res.download() for res in results]
2021-03-18 14:01:34 +13:00
hashes = [res.hash.hexdigest() for res in results]
assert set(hashes) == expected_hashes
2021-07-19 20:44:54 +12:00
2022-12-03 18:11:17 +13:00
@pytest.mark.parametrize(
"test_id",
(
"n0pyzp",
"nxyahw",
),
)
2021-07-19 20:44:54 +12:00
def test_gallery_download_raises_right_error(test_id: str, reddit_instance: praw.Reddit):
test_submission = reddit_instance.submission(id=test_id)
gallery = Gallery(test_submission)
with pytest.raises(SiteDownloaderError):
gallery.find_resources()