diff options
| author | Shyam Sunder | 2020-04-02 16:17:26 -0400 |
|---|---|---|
| committer | Shyam Sunder | 2020-04-03 13:11:54 -0400 |
| commit | 99a69333e656fcbf7acf55f8593cf2a70781fc6d (patch) | |
| tree | 1b858da2bdb7f5af9e39ee95358b569649ddd016 /server/szurubooru/tests | |
| parent | 08e62ec8853d7564ac718471be7fd32739a0bf90 (diff) | |
server/posts/upload: Add youtube-dl functionality
allows for video-based posts to be created by using youtube-dl
on the server. Access is controlled with the 'uploads:use_downloader'
permission.
Diffstat (limited to 'server/szurubooru/tests')
| -rw-r--r-- | server/szurubooru/tests/api/test_post_creating.py | 24 | ||||
| -rw-r--r-- | server/szurubooru/tests/api/test_post_updating.py | 7 | ||||
| -rw-r--r-- | server/szurubooru/tests/func/test_net.py | 26 | ||||
| -rw-r--r-- | server/szurubooru/tests/rest/test_context.py | 3 |
4 files changed, 52 insertions, 8 deletions
diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py index 9d94a92..dc4d51c 100644 --- a/server/szurubooru/tests/api/test_post_creating.py +++ b/server/szurubooru/tests/api/test_post_creating.py @@ -11,6 +11,7 @@ def inject_config(config_injector): 'posts:create:anonymous': model.User.RANK_REGULAR, 'posts:create:identified': model.User.RANK_REGULAR, 'tags:create': model.User.RANK_REGULAR, + 'uploads:use_downloader': model.User.RANK_REGULAR, }, 'allow_broken_uploads': False, }) @@ -122,7 +123,10 @@ def test_anonymous_uploads( patch('szurubooru.func.posts.create_post'), \ patch('szurubooru.func.posts.update_post_source'): config_injector({ - 'privileges': {'posts:create:anonymous': model.User.RANK_REGULAR}, + 'privileges': { + 'posts:create:anonymous': model.User.RANK_REGULAR, + 'uploads:use_downloader': model.User.RANK_POWER, + }, }) posts.create_post.return_value = [post, []] api.post_api.create_post( @@ -152,7 +156,10 @@ def test_creating_from_url_saves_source( patch('szurubooru.func.posts.create_post'), \ patch('szurubooru.func.posts.update_post_source'): config_injector({ - 'privileges': {'posts:create:identified': model.User.RANK_REGULAR}, + 'privileges': { + 'posts:create:identified': model.User.RANK_REGULAR, + 'uploads:use_downloader': model.User.RANK_POWER, + }, }) net.download.return_value = b'content' posts.create_post.return_value = [post, []] @@ -164,7 +171,8 @@ def test_creating_from_url_saves_source( 'contentUrl': 'example.com', }, user=auth_user)) - net.download.assert_called_once_with('example.com') + net.download.assert_called_once_with( + 'example.com', use_video_downloader=False) posts.create_post.assert_called_once_with( b'content', ['tag1', 'tag2'], auth_user) posts.update_post_source.assert_called_once_with(post, 'example.com') @@ -182,7 +190,10 @@ def test_creating_from_url_with_source_specified( patch('szurubooru.func.posts.create_post'), \ patch('szurubooru.func.posts.update_post_source'): config_injector({ - 'privileges': {'posts:create:identified': model.User.RANK_REGULAR}, + 'privileges': { + 'posts:create:identified': model.User.RANK_REGULAR, + 'uploads:use_downloader': model.User.RANK_REGULAR, + }, }) net.download.return_value = b'content' posts.create_post.return_value = [post, []] @@ -195,7 +206,8 @@ def test_creating_from_url_with_source_specified( 'source': 'example2.com', }, user=auth_user)) - net.download.assert_called_once_with('example.com') + net.download.assert_called_once_with( + 'example.com', use_video_downloader=True) posts.create_post.assert_called_once_with( b'content', ['tag1', 'tag2'], auth_user) posts.update_post_source.assert_called_once_with(post, 'example2.com') @@ -261,6 +273,7 @@ def test_errors_not_spending_ids( }, 'privileges': { 'posts:create:identified': model.User.RANK_REGULAR, + 'uploads:use_downloader': model.User.RANK_POWER, }, 'secret': 'test', }) @@ -325,6 +338,7 @@ def test_trying_to_create_tags_without_privileges( 'posts:create:anonymous': model.User.RANK_REGULAR, 'posts:create:identified': model.User.RANK_REGULAR, 'tags:create': model.User.RANK_ADMINISTRATOR, + 'uploads:use_downloader': model.User.RANK_POWER, }, }) with pytest.raises(errors.AuthError), \ diff --git a/server/szurubooru/tests/api/test_post_updating.py b/server/szurubooru/tests/api/test_post_updating.py index 229ecef..887f54f 100644 --- a/server/szurubooru/tests/api/test_post_updating.py +++ b/server/szurubooru/tests/api/test_post_updating.py @@ -18,6 +18,7 @@ def inject_config(config_injector): 'posts:edit:flags': model.User.RANK_REGULAR, 'posts:edit:thumbnail': model.User.RANK_REGULAR, 'tags:create': model.User.RANK_MODERATOR, + 'uploads:use_downloader': model.User.RANK_REGULAR, }, 'allow_broken_uploads': False, }) @@ -97,7 +98,8 @@ def test_uploading_from_url_saves_source( params={'contentUrl': 'example.com', 'version': 1}, user=user_factory(rank=model.User.RANK_REGULAR)), {'post_id': post.post_id}) - net.download.assert_called_once_with('example.com') + net.download.assert_called_once_with( + 'example.com', use_video_downloader=True) posts.update_post_content.assert_called_once_with(post, b'content') posts.update_post_source.assert_called_once_with(post, 'example.com') @@ -121,7 +123,8 @@ def test_uploading_from_url_with_source_specified( 'version': 1}, user=user_factory(rank=model.User.RANK_REGULAR)), {'post_id': post.post_id}) - net.download.assert_called_once_with('example.com') + net.download.assert_called_once_with( + 'example.com', use_video_downloader=True) posts.update_post_content.assert_called_once_with(post, b'content') posts.update_post_source.assert_called_once_with(post, 'example2.com') diff --git a/server/szurubooru/tests/func/test_net.py b/server/szurubooru/tests/func/test_net.py index fb149b0..43f7c28 100644 --- a/server/szurubooru/tests/func/test_net.py +++ b/server/szurubooru/tests/func/test_net.py @@ -1,4 +1,7 @@ +import pytest +from szurubooru.errors import ThirdPartyError from szurubooru.func import net +from szurubooru.func.util import get_sha1 def test_download(config_injector): @@ -47,3 +50,26 @@ def test_download(config_injector): actual_content = net.download(url) assert actual_content == expected_content + + +def test_video_download(tmpdir, config_injector): + config_injector({ + 'user_agent': None, + 'data_dir': str(tmpdir.mkdir('data')) + }) + url = 'https://www.youtube.com/watch?v=C0DPdy98e4c' + expected_sha1 = '508f89ee85bc6186e18cfaa4f4d0279bcf2418ab' + + actual_content = net.download(url, use_video_downloader=True) + 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' + + with pytest.raises(ThirdPartyError): + net.download(url, use_video_downloader=True) diff --git a/server/szurubooru/tests/rest/test_context.py b/server/szurubooru/tests/rest/test_context.py index 681d9d7..34cf7ac 100644 --- a/server/szurubooru/tests/rest/test_context.py +++ b/server/szurubooru/tests/rest/test_context.py @@ -25,7 +25,8 @@ def test_get_file_from_url(): ctx = rest.Context( env={}, method=None, url=None, params={'keyUrl': 'example.com'}) assert ctx.get_file('key') == b'content' - net.download.assert_called_once_with('example.com') + net.download.assert_called_once_with( + 'example.com', use_video_downloader=False) with pytest.raises(errors.ValidationError): assert ctx.get_file('non-existing') |