...
 
Commits (2)
......@@ -91,3 +91,6 @@ async def uploads_create(ctx, library_id, paths, ref, parallel):
]
await asyncio.gather(*tasks)
logs.logger.info("Upload complete")
uploads_rm = base.get_delete_command(uploads, "api/v1/uploads/{}/")
import uuid
import pytest
import click
......@@ -163,6 +165,78 @@ def test_libraries_rm(cli_ctx, session, responses, get_requests):
assert len(get_requests("delete", url + "42/")) == 1
def test_uploads_create(cli_ctx, session, responses, get_requests, tmpdir):
tmp_file = tmpdir.join("test.mp3")
tmp_file.write_text("content", "ascii")
library_id = str(uuid.uuid4())
command = cli.uploads.uploads_create
responses.post("https://test.funkwhale/api/v1/uploads/")
responses.get("https://test.funkwhale/api/v1/libraries/{}/".format(library_id))
command.callback(
library_id=library_id,
paths=[str(tmp_file)],
parallel=1,
ref="test-import",
_async_reraise=True,
)
expected_data = {
"library": library_id,
"import_reference": "test-import",
"source": "upload://test.mp3",
}
upload_requests = get_requests("post", "https://test.funkwhale/api/v1/uploads/")
assert len(upload_requests) == 1
data = upload_requests[0].kwargs["data"]
audio_file = data.pop("audio_file")
assert data == expected_data
assert audio_file.name == str(tmp_file)
libraries_requests = get_requests(
"get", "https://test.funkwhale/api/v1/libraries/{}/".format(library_id)
)
assert len(libraries_requests) == 1
def test_uploads_ls(cli_ctx, session, responses, get_requests):
command = cli.uploads.uploads_ls
url = "https://test.funkwhale/api/v1/uploads/?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_uploads_rm(cli_ctx, session, responses, get_requests):
uuid1 = str(uuid.uuid4())
uuid2 = str(uuid.uuid4())
command = cli.uploads.uploads_rm
url = "https://test.funkwhale/api/v1/uploads/"
responses.delete(url + uuid1 + "/")
responses.delete(url + uuid2 + "/")
command.callback(id=[uuid1, uuid2], raw=False, no_input=True, _async_reraise=True)
assert len(get_requests("delete", url + uuid1 + "/")) == 1
assert len(get_requests("delete", url + uuid2 + "/")) == 1
def test_favorites_tracks_create(cli_ctx, session, responses, get_requests):
command = cli.favorites.favorites_tracks_create
url = "https://test.funkwhale/api/v1/favorites/tracks/"
......