Skip to content
Snippets Groups Projects
Verified Commit ff402d75 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added tests for favorites

parent 3d7fd19c
No related branches found
No related tags found
No related merge requests found
......@@ -860,15 +860,15 @@ def favorites(ctx):
@favorites.group("tracks")
@click.pass_context
def tracks_favorites(ctx):
def favorites_tracks(ctx):
pass
@tracks_favorites.command("create")
@favorites_tracks.command("create")
@click.argument("id", nargs=-1, required=True)
@click.pass_context
@async_command
async def tracks_favorites_create(ctx, id):
async def favorites_tracks_create(ctx, id):
click.echo("Adding {} tracks to favorites…".format(len(id)))
async with ctx.obj["remote"]:
......@@ -881,11 +881,11 @@ async def tracks_favorites_create(ctx, id):
click.echo("Track {} added to favorites".format(i))
@tracks_favorites.command("rm")
@favorites_tracks.command("rm")
@click.argument("id", nargs=-1, required=True)
@click.pass_context
@async_command
async def tracks_favorites_rm(ctx, id):
async def favorites_tracks_rm(ctx, id):
click.echo("Removing {} tracks to favorites…".format(len(id)))
async with ctx.obj["remote"]:
......@@ -899,7 +899,7 @@ async def tracks_favorites_rm(ctx, id):
favorites_tracks_ls = get_ls_command( # noqa
tracks_favorites,
favorites_tracks,
"api/v1/favorites/tracks/",
output_conf={
"labels": ["Track ID", "Track", "Artist", "Favorite Date"],
......
......@@ -128,3 +128,54 @@ def test_libraries_rm(cli_ctx, session, responses, get_requests):
assert len(get_requests("delete", url + "1/")) == 1
assert len(get_requests("delete", url + "42/")) == 1
def test_favorites_tracks_create(cli_ctx, session, responses, get_requests):
command = cli.favorites_tracks_create
url = "https://test.funkwhale/api/v1/favorites/tracks/"
responses.post(url, repeat=True)
command.callback(id=[1, 42], _async_reraise=True)
requests = get_requests("post", url)
assert len(requests) == 2
assert requests[0].kwargs["data"] == {"track": 1}
assert requests[1].kwargs["data"] == {"track": 42}
def test_favorites_tracks_ls(cli_ctx, session, responses, get_requests):
command = cli.favorites_tracks_ls
url = "https://test.funkwhale/api/v1/favorites/tracks/?ordering=-creation_date&page=1&page_size=5&q=hello"
responses.get(
url, payload={"results": [], "next": None, "previous": None, "count": 0}
)
command.callback(
raw=False,
page=1,
page_size=5,
ordering="-creation_date",
filter="favorites=true",
query=["hello"],
column=None,
format=None,
no_headers=False,
ids=False,
limit=1,
)
requests = get_requests("get", url)
assert len(requests) == 1
def test_favorites_tracks_rm(cli_ctx, session, responses, get_requests):
command = cli.favorites_tracks_rm
url = "https://test.funkwhale/api/v1/favorites/tracks/remove/"
responses.delete(url, repeat=True)
command.callback(id=[1, 42], _async_reraise=True)
requests = get_requests("delete", url)
assert len(requests) == 2
assert requests[0].kwargs["data"] == {"track": 1}
assert requests[1].kwargs["data"] == {"track": 42}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment