1
0
Fork 0
mirror of synced 2024-06-02 10:24:39 +12:00
bulk-downloader-for-reddit/bulkredditdownloader/tests/site_downloaders/test_gallery.py

61 lines
2.4 KiB
Python
Raw Normal View History

2021-02-15 20:45:41 +13:00
#!/usr/bin/env python3
# coding=utf-8
2021-03-17 19:27:26 +13:00
import praw
2021-02-15 20:45:41 +13:00
import pytest
from bulkredditdownloader.site_downloaders.gallery import Gallery
2021-03-17 23:42:35 +13:00
@pytest.mark.online
@pytest.mark.parametrize(('test_url', 'expected'), (
('https://www.reddit.com/gallery/m6lvrh', {
2021-03-18 14:01:34 +13:00
'https://preview.redd.it/18nzv9ch0hn61.jpg?width=4160&'
'format=pjpg&auto=webp&s=470a825b9c364e0eace0036882dcff926f821de8',
'https://preview.redd.it/jqkizcch0hn61.jpg?width=4160&'
'format=pjpg&auto=webp&s=ae4f552a18066bb6727676b14f2451c5feecf805',
'https://preview.redd.it/k0fnqzbh0hn61.jpg?width=4160&'
'format=pjpg&auto=webp&s=c6a10fececdc33983487c16ad02219fd3fc6cd76',
'https://preview.redd.it/m3gamzbh0hn61.jpg?width=4160&'
'format=pjpg&auto=webp&s=0dd90f324711851953e24873290b7f29ec73c444'
2021-03-17 23:42:35 +13:00
}),
('https://www.reddit.com/gallery/ljyy27', {
2021-03-18 14:01:34 +13:00
'https://preview.redd.it/04vxj25uqih61.png?width=92&'
'format=png&auto=webp&s=6513f3a5c5128ee7680d402cab5ea4fb2bbeead4',
'https://preview.redd.it/0fnx83kpqih61.png?width=241&'
'format=png&auto=webp&s=655e9deb6f499c9ba1476eaff56787a697e6255a',
'https://preview.redd.it/7zkmr1wqqih61.png?width=237&'
'format=png&auto=webp&s=19de214e634cbcad9959f19570c616e29be0c0b0',
'https://preview.redd.it/u37k5gxrqih61.png?width=443&'
'format=png&auto=webp&s=e74dae31841fe4a2545ffd794d3b25b9ff0eb862'
2021-03-17 23:42:35 +13:00
}),
))
def test_gallery_get_links(test_url: str, expected: set[str]):
results = Gallery._get_links(test_url)
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
2021-03-18 14:01:34 +13:00
@pytest.mark.parametrize(('test_submission_id', 'expected_hashes'), (
('m6lvrh', {
'6c8a892ae8066cbe119218bcaac731e1',
'93ce177f8cb7994906795f4615114d13',
'9a293adf19354f14582608cf22124574',
'b73e2c3daee02f99404644ea02f1ae65'
}),
('ljyy27', {
'1bc38bed88f9c4770e22a37122d5c941',
'2539a92b78f3968a069df2dffe2279f9',
'37dea50281c219b905e46edeefc1a18d',
'ec4924cf40549728dcf53dd40bc7a73c'
}),
2021-03-17 19:27:26 +13:00
))
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()
[res.download(120) 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