aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-07-20 05:51:44 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-07-20 05:51:44 -0400
commit2a63a9c9b7032a76894c48ac4d9cea732fcaee49 (patch)
tree3d5f633ff69cd393036a3dabc4d4533c8484f9ad /test
parent195c45911e79c33cf0bb986721365fb06df5a153 (diff)
New upstream version 1.9.0upstream/1.9.0
Diffstat (limited to 'test')
-rw-r--r--test/test_downloader.py75
-rw-r--r--test/test_results.py12
2 files changed, 79 insertions, 8 deletions
diff --git a/test/test_downloader.py b/test/test_downloader.py
index 3f301b0..caed983 100644
--- a/test/test_downloader.py
+++ b/test/test_downloader.py
@@ -8,13 +8,16 @@
# published by the Free Software Foundation.
import re
+import sys
import base64
import os.path
import tempfile
-import unittest
import threading
import http.server
+import unittest
+from unittest.mock import Mock, MagicMock, patch
+
import gallery_dl.downloader as downloader
import gallery_dl.extractor as extractor
import gallery_dl.config as config
@@ -23,6 +26,73 @@ from gallery_dl.output import NullOutput
from gallery_dl.util import PathFormat
+class MockDownloaderModule(Mock):
+ __downloader__ = "mock"
+
+
+class TestDownloaderModule(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ # allow import of ytdl downloader module without youtube_dl installed
+ sys.modules["youtube_dl"] = MagicMock()
+
+ @classmethod
+ def tearDownClass(cls):
+ del sys.modules["youtube_dl"]
+
+ def tearDown(self):
+ downloader._cache.clear()
+
+ def test_find(self):
+ cls = downloader.find("http")
+ self.assertEqual(cls.__name__, "HttpDownloader")
+ self.assertEqual(cls.scheme , "http")
+
+ cls = downloader.find("https")
+ self.assertEqual(cls.__name__, "HttpDownloader")
+ self.assertEqual(cls.scheme , "http")
+
+ cls = downloader.find("text")
+ self.assertEqual(cls.__name__, "TextDownloader")
+ self.assertEqual(cls.scheme , "text")
+
+ cls = downloader.find("ytdl")
+ self.assertEqual(cls.__name__, "YoutubeDLDownloader")
+ self.assertEqual(cls.scheme , "ytdl")
+
+ self.assertEqual(downloader.find("ftp"), None)
+ self.assertEqual(downloader.find("foo"), None)
+ self.assertEqual(downloader.find(1234) , None)
+ self.assertEqual(downloader.find(None) , None)
+
+ @patch("importlib.import_module")
+ def test_cache(self, import_module):
+ import_module.return_value = MockDownloaderModule()
+ downloader.find("http")
+ downloader.find("text")
+ downloader.find("ytdl")
+ self.assertEqual(import_module.call_count, 3)
+ downloader.find("http")
+ downloader.find("text")
+ downloader.find("ytdl")
+ self.assertEqual(import_module.call_count, 3)
+
+ @patch("importlib.import_module")
+ def test_cache_http(self, import_module):
+ import_module.return_value = MockDownloaderModule()
+ downloader.find("http")
+ downloader.find("https")
+ self.assertEqual(import_module.call_count, 1)
+
+ @patch("importlib.import_module")
+ def test_cache_https(self, import_module):
+ import_module.return_value = MockDownloaderModule()
+ downloader.find("https")
+ downloader.find("http")
+ self.assertEqual(import_module.call_count, 1)
+
+
class TestDownloaderBase(unittest.TestCase):
@classmethod
@@ -134,9 +204,6 @@ class TestTextDownloader(TestDownloaderBase):
def test_text_offset(self):
self._run_test("text:foobar", "foo", "foobar", "txt", "txt")
- def test_text_extension(self):
- self._run_test("text:foobar", None, "foobar", None, "txt")
-
def test_text_empty(self):
self._run_test("text:", None, "", "txt", "txt")
diff --git a/test/test_results.py b/test/test_results.py
index 8f03f03..41390a8 100644
--- a/test/test_results.py
+++ b/test/test_results.py
@@ -27,6 +27,7 @@ TRAVIS_SKIP = {
# temporary issues, etc.
BROKEN = {
"komikcast",
+ "konachan",
"mangapark",
}
@@ -161,9 +162,10 @@ class ResultJob(job.DownloadJob):
self.hash_keyword = hashlib.sha1()
self.hash_archive = hashlib.sha1()
self.hash_content = hashlib.sha1()
+
if content:
self.fileobj = TestPathfmt(self.hash_content)
- self.get_downloader("http")._check_extension = lambda a, b: None
+ self.get_downloader("http").check_extension = lambda a, b: None
self.format_directory = TestFormatter(
"".join(self.extractor.directory_fmt))
@@ -217,6 +219,7 @@ class TestPathfmt():
self.hashobj = hashobj
self.path = ""
self.size = 0
+ self.keywords = {}
self.has_extension = True
def __enter__(self):
@@ -279,9 +282,10 @@ def setup_test_config():
config.set(("extractor", "password"), name)
config.set(("extractor", "nijie", "username"), email)
config.set(("extractor", "seiga", "username"), email)
- config.set(("extractor", "danbooru", "username"), None)
- config.set(("extractor", "twitter" , "username"), None)
- config.set(("extractor", "mangoxo" , "password"), "VZ8DL3983u")
+ config.set(("extractor", "danbooru" , "username"), None)
+ config.set(("extractor", "instagram", "username"), None)
+ config.set(("extractor", "twitter" , "username"), None)
+ config.set(("extractor", "mangoxo" , "password"), "VZ8DL3983u")
config.set(("extractor", "deviantart", "client-id"), "7777")
config.set(("extractor", "deviantart", "client-secret"),