Skip to content

Commit

Permalink
fix spotify setup issue (closes #55)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 22, 2023
1 parent e4151e8 commit 334b21f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions spotify_to_ytmusic/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def setup_youtube():
def setup_spotify():
settings = Settings()
credentials = {
"client_credentials": input(
"Paste your client credentials from the Spotify developer dashboard:"
"client_id": input(
"Paste your client id from the Spotify developer dashboard:"
),
"client_secrets": input("Paste your client secret from the Spotify developer dashboard:"),
"client_secret": input("Paste your client secret from the Spotify developer dashboard:"),
}
settings["spotify"].update(credentials)
settings.save()
Expand Down
17 changes: 13 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import shutil
import time
import unittest
Expand Down Expand Up @@ -27,16 +28,16 @@ def test_create(self):
main()

with mock.patch(
"sys.argv", ["", "create", TEST_PLAYLIST, "-n", "test", "-i", "test-playlist", "-d"]
"sys.argv", ["", "create", TEST_PLAYLIST, "-n", "spotify_to_ytmusic", "-i", "test-playlist", "-d"]
):
main()

time.sleep(2)
with mock.patch("sys.argv", ["", "update", TEST_PLAYLIST, "test"]):
with mock.patch("sys.argv", ["", "update", TEST_PLAYLIST, "spotify_to_ytmusic"]):
main()

time.sleep(2)
with mock.patch("sys.argv", ["", "remove", "test"]), mock.patch(
with mock.patch("sys.argv", ["", "remove", "spotify\_to\_ytmusic"]), mock.patch(
"sys.stdout", new=StringIO()
) as fakeOutput, mock.patch("builtins.input", side_effect="y"):
main()
Expand All @@ -48,9 +49,17 @@ 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"):
with mock.patch("sys.argv", ["", "setup"]), mock.patch(
"builtins.input", return_value="3"
), mock.patch(
"ytmusicapi.auth.oauth.YTMusicOAuth.get_token_from_code",
return_value=json.loads(Settings()["youtube"]["headers"]),
):
main()
assert tmp_path.is_file()
settings = Settings()
assert settings["spotify"]["client_id"] == "3"
assert settings["spotify"]["client_secret"] == "3"
tmp_path.unlink()

with mock.patch("sys.argv", ["", "setup", "--file", example_path.as_posix()]), mock.patch(
Expand Down

0 comments on commit 334b21f

Please sign in to comment.