Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 8, 2023
1 parent 450cc3b commit fdce6a0
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import time
import unittest
from io import StringIO
from unittest import mock

from spotify_to_ytmusic.main import get_args
from spotify_to_ytmusic.main import get_args, main

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


class TestCli(unittest.TestCase):
def test_get_args(self):
args = get_args(["all", "user", "--public"])
args = get_args(["all", "user"])
self.assertEqual(len(vars(args)), 3)
args = get_args(["create", "playlist-link"])
self.assertEqual(len(vars(args)), 7)
args = get_args(["update", "playlist-link"])
self.assertEqual(len(vars(args)), 4)
args = get_args(["update", "playlist-link", "playlist-name"])
self.assertEqual(len(vars(args)), 5)
args = get_args(["setup"])
self.assertEqual(len(vars(args)), 3)

def test_create(self):
with mock.patch("sys.argv", ["", "all", "sigmatics"]):
main()

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

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

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

0 comments on commit fdce6a0

Please sign in to comment.