aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/tests
diff options
context:
space:
mode:
authorShyam Sunder2020-04-03 15:32:25 -0400
committerShyam Sunder2020-04-03 15:32:25 -0400
commit2c6434b08d9e38a1879cd66533b9a2c5d2c09c4f (patch)
tree969b5011c51fb4738fef3830fe7a466279e549ec /server/szurubooru/tests
parent99a69333e656fcbf7acf55f8593cf2a70781fc6d (diff)
server/posts/upload: limit filesize for uploads through youtube-dl
This will be controlled by the config parameter 'max_dl_filesize'. TODO: In a future commit, the regular downloader should also respect this parameter.
Diffstat (limited to 'server/szurubooru/tests')
-rw-r--r--server/szurubooru/tests/func/test_net.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/server/szurubooru/tests/func/test_net.py b/server/szurubooru/tests/func/test_net.py
index 43f7c28..a3b075d 100644
--- a/server/szurubooru/tests/func/test_net.py
+++ b/server/szurubooru/tests/func/test_net.py
@@ -1,13 +1,19 @@
import pytest
-from szurubooru.errors import ThirdPartyError
+from szurubooru import errors
from szurubooru.func import net
from szurubooru.func.util import get_sha1
-def test_download(config_injector):
+@pytest.fixture(autouse=True)
+def inject_config(tmpdir, config_injector):
config_injector({
- 'user_agent': None
+ 'user_agent': None,
+ 'max_dl_filesize': 1.0E+6,
+ 'data_dir': str(tmpdir.mkdir('data')),
})
+
+
+def test_download():
url = 'http://info.cern.ch/hypertext/WWW/TheProject.html'
expected_content = (
@@ -52,11 +58,15 @@ def test_download(config_injector):
assert actual_content == expected_content
-def test_video_download(tmpdir, config_injector):
- config_injector({
- 'user_agent': None,
- 'data_dir': str(tmpdir.mkdir('data'))
- })
+def test_too_large_download():
+ pytest.xfail('Download limit not implemented yet')
+ url = 'https://samples.ffmpeg.org/MPEG-4/video.mp4'
+
+ with pytest.raises(errors.DownloadTooLargeError):
+ net.download(url)
+
+
+def test_video_download():
url = 'https://www.youtube.com/watch?v=C0DPdy98e4c'
expected_sha1 = '508f89ee85bc6186e18cfaa4f4d0279bcf2418ab'
@@ -64,12 +74,15 @@ def test_video_download(tmpdir, config_injector):
assert get_sha1(actual_content) == expected_sha1
-def test_failed_video_download(tmpdir, config_injector):
- config_injector({
- 'user_agent': None,
- 'data_dir': str(tmpdir.mkdir('data'))
- })
- url = 'http://info.cern.ch/hypertext/WWW/TheProject.html'
+def test_failed_video_download():
+ url = 'https://samples.ffmpeg.org/flac/short.flac'
+
+ with pytest.raises(errors.ThirdPartyError):
+ net.download(url, use_video_downloader=True)
+
+
+def test_too_large_video_download():
+ url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
- with pytest.raises(ThirdPartyError):
+ with pytest.raises(errors.DownloadTooLargeError):
net.download(url, use_video_downloader=True)

© 2015 - 2026 Jakob L. Kreuze