Verified Commit 50135cba authored by Agate's avatar Agate 💬

Added uploads tests

parent 00853243
import uuid
import pytest
import click
......@@ -163,6 +165,64 @@ 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_favorites_tracks_create(cli_ctx, session, responses, get_requests):
command = cli.favorites.favorites_tracks_create
url = "https://test.funkwhale/api/v1/favorites/tracks/"
......
Markdown is supported
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