Skip to content

Commit

Permalink
Fix #534: Fix the fallback Wallhaven non-API downloading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlevi committed Jun 16, 2022
1 parent b0a04ae commit 79102ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/TestWallhavenDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
### END LICENSE

import os
import tempfile
import unittest
from unittest.mock import MagicMock, PropertyMock
from unittest.mock import MagicMock

from tests.TestDownloader import test_download_one_for
from variety.plugins.builtin.downloaders.WallhavenSource import WallhavenSource
from variety.Util import Util


class TestWallhavenDownloader(unittest.TestCase):
Expand All @@ -30,6 +32,21 @@ def test_download_one(self):
source.set_variety(mock)
test_download_one_for(self, source.create_downloader("landscape"))

def test_legacy_fallback_download_one(self):
source = WallhavenSource()
mock = MagicMock()
mock.options.wallhaven_api_key = ""
source.set_variety(mock)

with tempfile.TemporaryDirectory() as tmpdir:
dl = source.create_downloader("https://wallhaven.cc/user/lewdpatriot/favorites/935888")
dl.update_download_folder(tmpdir)
for _ in range(5):
f = dl.download_one()
if f and os.path.isfile(f) and Util.is_image(f, check_contents=True):
return
self.fail("Tried download_one 5 times, all failed")

def test_fill_queue(self):
source = WallhavenSource()
mock = MagicMock()
Expand Down
6 changes: 6 additions & 0 deletions variety/plugins/builtin/downloaders/WallhavenDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def __init__(self, source, location, api_key):
self.legacy_downloader = WallhavenLegacyDownloader(source, location)
self.parse_location()

def update_download_folder(self, global_download_folder):
target_folder = super().update_download_folder(global_download_folder)
self.legacy_downloader.target_folder = target_folder
self.legacy_downloader.state = self.state
return target_folder

def parse_location(self):
if not self.config.startswith(("http://", "https://")):
# interpret location as keywords
Expand Down

0 comments on commit 79102ee

Please sign in to comment.