mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Increase coverage (#218)
* Monkeypatch fetch user and use pytest.tempdir * Cover spotify_tools.grab_album() * Cover avconv conversion * Cover grab_single() * Reduce code repetition * Move grab_playlist() to spotify_tools.py * Move Spotify specific functions to spotify_tools.py * Refactoring * Return track list from write_tracks() * Fix tests * Cover more cases in generate_youtube_url() * Test for unavailable audio streams * Test for filename without spaces * handle.py 100% coverage * Improve config tests * Speed up tests * Install avconv and libfdk-aac * Some cleaning * FFmpeg with libfdk-aac, libopus * Some refactoring * Convert tmpdir to string * Cover YouTube title when downloading from list * Explicitly cover some internals.py functions
This commit is contained in:
87
test/test_without_metadata.py
Normal file
87
test/test_without_metadata.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from core import const
|
||||
from core import internals
|
||||
from core import spotify_tools
|
||||
from core import youtube_tools
|
||||
|
||||
import spotdl
|
||||
import loader
|
||||
|
||||
import os
|
||||
import builtins
|
||||
|
||||
loader.load_defaults()
|
||||
raw_song = "Tony's Videos VERY SHORT VIDEO 28.10.2016"
|
||||
|
||||
|
||||
def test_metadata():
|
||||
expect_metadata = None
|
||||
global metadata
|
||||
metadata = spotify_tools.generate_metadata(raw_song)
|
||||
assert metadata == expect_metadata
|
||||
|
||||
|
||||
class TestYouTubeURL:
|
||||
def test_only_music_category(self):
|
||||
expect_url = 'http://youtube.com/watch?v=P11ou3CXKZo'
|
||||
const.args.music_videos_only = True
|
||||
url = youtube_tools.generate_youtube_url(raw_song, metadata)
|
||||
assert url == expect_url
|
||||
|
||||
def test_all_categories(self):
|
||||
expect_url = 'http://youtube.com/watch?v=qOOcy2-tmbk'
|
||||
const.args.music_videos_only = False
|
||||
url = youtube_tools.generate_youtube_url(raw_song, metadata)
|
||||
assert url == expect_url
|
||||
|
||||
def test_args_manual(self, monkeypatch):
|
||||
expect_url = 'http://youtube.com/watch?v=qOOcy2-tmbk'
|
||||
const.args.manual = True
|
||||
monkeypatch.setattr('builtins.input', lambda x: '1')
|
||||
url = youtube_tools.generate_youtube_url(raw_song, metadata)
|
||||
assert url == expect_url
|
||||
|
||||
def test_args_manual_none(self, monkeypatch):
|
||||
expect_url = None
|
||||
monkeypatch.setattr('builtins.input', lambda x: '0')
|
||||
url = youtube_tools.generate_youtube_url(raw_song, metadata)
|
||||
const.args.manual = False
|
||||
assert url == expect_url
|
||||
|
||||
|
||||
class TestYouTubeTitle:
|
||||
def test_single_download(self):
|
||||
global content
|
||||
global title
|
||||
expect_title = "Tony's Videos VERY SHORT VIDEO 28.10.2016"
|
||||
content = youtube_tools.go_pafy(raw_song, metadata)
|
||||
title = youtube_tools.get_youtube_title(content)
|
||||
assert title == expect_title
|
||||
|
||||
def test_download_from_list(self):
|
||||
expect_title = "1. Tony's Videos VERY SHORT VIDEO 28.10.2016"
|
||||
content = youtube_tools.go_pafy(raw_song, metadata)
|
||||
title = youtube_tools.get_youtube_title(content, 1)
|
||||
assert title == expect_title
|
||||
|
||||
|
||||
def test_check_exists(tmpdir):
|
||||
expect_check = False
|
||||
const.args.folder = str(tmpdir)
|
||||
# prerequisites for determining filename
|
||||
global file_name
|
||||
file_name = internals.sanitize_title(title)
|
||||
check = spotdl.check_exists(file_name, raw_song, metadata)
|
||||
assert check == expect_check
|
||||
|
||||
|
||||
class TestDownload:
|
||||
def test_webm(self):
|
||||
# content does not have any .webm audiostream
|
||||
expect_download = False
|
||||
download = youtube_tools.download_song(file_name + '.webm', content)
|
||||
assert download == expect_download
|
||||
|
||||
def test_other(self):
|
||||
expect_download = False
|
||||
download = youtube_tools.download_song(file_name + '.fake_extension', content)
|
||||
assert download == expect_download
|
||||
Reference in New Issue
Block a user