Commit 71962da2 authored by EorlBruder's avatar EorlBruder
Browse files

Added tests for generate-playlist

- don't close the stdout-stream, since the test won't
  be able to continue using it afterwards
parent a09e3e74
Pipeline #14711 passed with stage
in 55 seconds
......@@ -201,7 +201,7 @@ async def track_generate_playlist(
for track in playlist:
out.write(track + "\n")
else:
with click.get_binary_stream("stdout") as out:
for track in playlist:
out.write(bytes(track + "\n", "utf8"))
out = click.get_binary_stream("stdout")
for track in playlist:
out.write(bytes(track + "\n", "utf8"))
logs.logger.info("Export of playlist complete")
......@@ -388,6 +388,82 @@ def test_tracks_ls(cli_ctx, session, responses, get_requests):
assert len(requests) == 1
def test_tracks_generate_playlist(cli_ctx, session, responses, get_requests, capfd):
expected = "./Test-Artist - Test-Album - Test-Track.flac\n"
command = cli.tracks.track_generate_playlist
url = "https://test.funkwhale/api/v1/tracks/1/"
responses.get(
url,
payload={"uploads": [{"extension": "flac"}], "album": {"title": "Test-Album", "release_date": "2021-02-01"},
"artist": {"name": "Test-Artist"}, "title": "Test-Track"}
)
command.callback(
id="1",
format=None,
directory=None,
template="{artist} - {album} - {title}.{extension}",
base_path="./",
name="playlist",
)
requests = get_requests("get", url)
assert len(requests) == 1
out, err = capfd.readouterr()
assert out == expected
def test_tracks_generate_playlist_base_path(cli_ctx, session, responses, get_requests, capfd):
expected = "/different_base/Test-Artist - Test-Album - Test-Track.flac\n"
command = cli.tracks.track_generate_playlist
url = "https://test.funkwhale/api/v1/tracks/1/"
responses.get(
url,
payload={"uploads": [{"extension": "flac"}], "album": {"title": "Test-Album", "release_date": "2021-02-01"},
"artist": {"name": "Test-Artist"}, "title": "Test-Track"}
)
command.callback(
id="1",
format=None,
directory=None,
template="{artist} - {album} - {title}.{extension}",
base_path="/different_base/",
name="playlist",
)
requests = get_requests("get", url)
assert len(requests) == 1
out, err = capfd.readouterr()
assert out == expected
def test_tracks_generate_playlist_format(cli_ctx, session, responses, get_requests, capfd):
expected = "./Test-Artist - Test-Album - Test-Track.mp3\n"
command = cli.tracks.track_generate_playlist
url = "https://test.funkwhale/api/v1/tracks/1/"
responses.get(
url,
payload={"uploads": [{"extension": "flac"}], "album": {"title": "Test-Album", "release_date": "2021-02-01"},
"artist": {"name": "Test-Artist"}, "title": "Test-Track"}
)
command.callback(
id="1",
format="mp3",
directory=None,
template="{artist} - {album} - {title}.{extension}",
base_path="./",
name="playlist",
)
requests = get_requests("get", url)
assert len(requests) == 1
out, err = capfd.readouterr()
assert out == expected
def test_artists_ls(cli_ctx, session, responses, get_requests):
command = cli.artists.artists_ls
url = "https://test.funkwhale/api/v1/artists/?ordering=-creation_date&page=1&page_size=5&q=hello"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment