1
0
Fork 0
mirror of synced 2024-06-02 10:24:39 +12:00

Add test for site downloader gallery

This commit is contained in:
Serene-Arc 2021-02-15 17:45:41 +10:00 committed by Ali Parlakci
parent 1b40b16970
commit bb85fb8934
2 changed files with 26 additions and 5 deletions

View file

@ -6,7 +6,7 @@ import logging
import requests
from praw.models import Submission
from bulkredditdownloader.errors import ResourceNotFound, NotADownloadableLinkError
from bulkredditdownloader.errors import NotADownloadableLinkError, ResourceNotFound
from bulkredditdownloader.site_downloaders.base_downloader import BaseDownloader
logger = logging.getLogger(__name__)
@ -33,7 +33,7 @@ class Gallery(BaseDownloader):
except KeyError:
continue
return [self._download_album(images)]
return self._download_album(images)
@staticmethod
def _get_data(link: str) -> dict:
@ -62,7 +62,6 @@ class Gallery(BaseDownloader):
def _download_album(self, images: dict):
out = []
for i, image in enumerate(images):
out.append(self._download_resource(image['url']))
for image_key in images.keys():
out.append(self._download_resource(images[image_key]['url']))
return out

View file

@ -0,0 +1,22 @@
#!/usr/bin/env python3
# coding=utf-8
import praw
import praw.models
import pytest
from bulkredditdownloader.resource import Resource
from bulkredditdownloader.site_downloaders.gallery import Gallery
@pytest.fixture()
def reddit_submission() -> praw.models.Submission:
rd = praw.Reddit(client_id='U-6gk4ZCh3IeNQ', client_secret='7CZHY6AmKweZME5s50SfDGylaPg', user_agent='test')
return rd.submission(id='ljyy27')
def test_gallery(reddit_submission: praw.models.Submission):
gallery = Gallery(reddit_submission)
results = gallery.download()
assert len(results) == 4
assert all([isinstance(result, Resource) for result in results])