Verified Commit 3d7fd19c authored by Agate's avatar Agate 💬

Added tests for libraries commands

parent 962ff7c6
......@@ -519,7 +519,7 @@ libraries_ls = get_ls_command(
"type": "LIBRARY",
},
)
libraries_delete = get_delete_command(libraries, "api/v1/libraries/{}/")
libraries_rm = get_delete_command(libraries, "api/v1/libraries/{}/")
@libraries.command("create")
......
import pytest
import aiohttp
from aioresponses import aioresponses
from aioresponses import aioresponses, compat as aioresponses_compat
import asynctest
......@@ -13,6 +13,15 @@ def responses():
yield m
@pytest.fixture
def get_requests(responses):
def get_calls(method, url):
url = aioresponses_compat.normalize_url(url)
return responses.requests[(method.upper(), url)]
return get_calls
@pytest.fixture
async def session(loop):
async with aiohttp.ClientSession() as session:
......
......@@ -79,3 +79,52 @@ def test_lazy_credential(mocker):
# result is cached
str(credential)
assert get_password.call_count == 1
def test_libraries_create(cli_ctx, session, responses, get_requests):
command = cli.libraries_create
url = "https://test.funkwhale/api/v1/libraries/"
responses.post(url)
command.callback(name="test", visibility="public", raw=False, _async_reraise=True)
requests = get_requests("post", url)
assert len(requests) == 1
assert requests[0].kwargs["data"] == {"name": "test", "visibility": "public"}
def test_libraries_ls(cli_ctx, session, responses, get_requests):
command = cli.libraries_ls
url = "https://test.funkwhale/api/v1/libraries/?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_libraries_rm(cli_ctx, session, responses, get_requests):
command = cli.libraries_rm
url = "https://test.funkwhale/api/v1/libraries/"
responses.delete(url + "1/")
responses.delete(url + "42/")
command.callback(id=[1, 42], raw=False, no_input=True, _async_reraise=True)
assert len(get_requests("delete", url + "1/")) == 1
assert len(get_requests("delete", url + "42/")) == 1
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