Skip to content

Commit

Permalink
fix ytmusicapi setup, add setup test
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 9, 2023
1 parent 2c9613c commit 9aa7103
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion spotify_to_ytmusic/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import shutil
import sys
from pathlib import Path
Expand Down Expand Up @@ -29,7 +30,7 @@ def setup(file: Optional[Path] = None):

def setup_youtube():
settings = Settings()
settings["youtube"]["headers"] = ytmusicapi.setup_oauth()
settings["youtube"]["headers"] = json.dumps(ytmusicapi.setup_oauth())
settings.save()


Expand Down
19 changes: 18 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import shutil
import time
import unittest
from io import StringIO
from pathlib import Path
from unittest import mock

from spotify_to_ytmusic.main import get_args, main
from spotify_to_ytmusic.settings import Settings

TEST_PLAYLIST = "https://open.spotify.com/playlist/4UzyZJfSQ4584FaWGwepfL"

Expand Down Expand Up @@ -32,4 +35,18 @@ def test_create(self):

with mock.patch("sys.argv", ["", "remove", "test"]), mock.patch('sys.stdout', new=StringIO()) as fakeOutput, mock.patch("builtins.input", side_effect="y"):
main()
assert int(fakeOutput.getvalue().splitlines()[-1][0]) >= 2
assert int(fakeOutput.getvalue().splitlines()[-1][0]) >= 2 # assert number of lines deleted

def test_setup(self):
tmp_path = Path(__file__).parent.joinpath("settings.tmp")
example_path = Settings.filepath.parent.joinpath("settings.ini.example")
shutil.copy(example_path, tmp_path)
with mock.patch("sys.argv", ["", "setup"]), mock.patch("builtins.input", return_value="3"), mock.patch("spotify_to_ytmusic.settings.Settings.filepath", tmp_path):
main()
assert tmp_path.is_file()
tmp_path.unlink()

with mock.patch("sys.argv", ["", "setup", "--file", example_path.as_posix()]), mock.patch("spotify_to_ytmusic.settings.Settings.filepath", tmp_path):
main()
assert tmp_path.is_file()
tmp_path.unlink()

0 comments on commit 9aa7103

Please sign in to comment.