Merge branch '1105-scan-ui' into 'develop'
Fix #1105: Can now launch server import from the UI Closes #1105 See merge request funkwhale/funkwhale!1192
This commit is contained in:
commit
b7f1c02c6f
17 changed files with 476 additions and 6 deletions
|
|
@ -1382,3 +1382,39 @@ def test_update_track_metadata(factories):
|
|||
assert str(track.artist.mbid) == data["musicbrainz_artistid"]
|
||||
assert track.album.artist.name == "Edvard Grieg"
|
||||
assert str(track.album.artist.mbid) == "013c8e5b-d72a-4cd3-8dee-6c64d6125823"
|
||||
|
||||
|
||||
def test_fs_import_not_pending(factories):
|
||||
with pytest.raises(ValueError):
|
||||
tasks.fs_import(
|
||||
library_id=factories["music.Library"]().pk,
|
||||
path="path",
|
||||
import_reference="test",
|
||||
)
|
||||
|
||||
|
||||
def test_fs_import(factories, cache, mocker, settings):
|
||||
_handle = mocker.spy(tasks.import_files.Command, "_handle")
|
||||
cache.set("fs-import:status", "pending")
|
||||
library = factories["music.Library"](actor__local=True)
|
||||
tasks.fs_import(library_id=library.pk, path="path", import_reference="test")
|
||||
assert _handle.call_args[1] == {
|
||||
"recursive": True,
|
||||
"path": [settings.MUSIC_DIRECTORY_PATH + "/path"],
|
||||
"library_id": str(library.uuid),
|
||||
"update_cache": True,
|
||||
"in_place": True,
|
||||
"reference": "test",
|
||||
"watch": False,
|
||||
"interactive": False,
|
||||
"batch_size": 1000,
|
||||
"async_": False,
|
||||
"prune": True,
|
||||
"broadcast": False,
|
||||
"outbox": False,
|
||||
"exit_on_failure": False,
|
||||
"replace": False,
|
||||
"verbosity": 1,
|
||||
}
|
||||
assert cache.get("fs-import:status") == "finished"
|
||||
assert "Pruning dangling tracks" in cache.get("fs-import:logs")[-1]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
|
||||
import pathlib
|
||||
import pytest
|
||||
|
||||
from funkwhale_api.music import utils
|
||||
|
|
@ -91,3 +91,21 @@ def test_increment_downloads_count_already_tracked(
|
|||
|
||||
assert upload.downloads_count == 0
|
||||
assert upload.track.downloads_count == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected",
|
||||
[
|
||||
("", [{"name": "Magic", "dir": True}, {"name": "System", "dir": True}]),
|
||||
("Magic", [{"name": "file.mp3", "dir": False}]),
|
||||
("System", [{"name": "file.ogg", "dir": False}]),
|
||||
],
|
||||
)
|
||||
def test_get_dirs_and_files(path, expected, tmpdir):
|
||||
root_path = pathlib.Path(tmpdir)
|
||||
(root_path / "Magic").mkdir()
|
||||
(root_path / "Magic" / "file.mp3").touch()
|
||||
(root_path / "System").mkdir()
|
||||
(root_path / "System" / "file.ogg").touch()
|
||||
|
||||
assert utils.browse_dir(root_path, path) == expected
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import datetime
|
|||
import io
|
||||
import magic
|
||||
import os
|
||||
import pathlib
|
||||
import urllib.parse
|
||||
import uuid
|
||||
|
||||
|
|
@ -1514,3 +1515,68 @@ def test_listen_to_track_with_scoped_token(factories, api_client):
|
|||
response = api_client.get(url, {"token": token})
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_fs_import_get(factories, superuser_api_client, mocker, settings):
|
||||
browse_dir = mocker.patch.object(
|
||||
views.utils, "browse_dir", return_value={"hello": "world"}
|
||||
)
|
||||
url = reverse("api:v1:libraries-fs-import")
|
||||
|
||||
expected = {
|
||||
"root": settings.MUSIC_DIRECTORY_PATH,
|
||||
"path": "",
|
||||
"content": {"hello": "world"},
|
||||
"import": None,
|
||||
}
|
||||
response = superuser_api_client.get(url, {"path": ""})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.data == expected
|
||||
browse_dir.assert_called_once_with(expected["root"], expected["path"])
|
||||
|
||||
|
||||
def test_fs_import_post(
|
||||
factories, superuser_api_client, cache, mocker, settings, tmpdir
|
||||
):
|
||||
actor = superuser_api_client.user.create_actor()
|
||||
library = factories["music.Library"](actor=actor)
|
||||
settings.MUSIC_DIRECTORY_PATH = tmpdir
|
||||
(pathlib.Path(tmpdir) / "test").mkdir()
|
||||
fs_import = mocker.patch(
|
||||
"funkwhale_api.music.tasks.fs_import.delay", return_value={"hello": "world"}
|
||||
)
|
||||
url = reverse("api:v1:libraries-fs-import")
|
||||
|
||||
response = superuser_api_client.post(
|
||||
url, {"path": "test", "library": library.uuid, "import_reference": "test"}
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
fs_import.assert_called_once_with(
|
||||
path="test", library_id=library.pk, import_reference="test"
|
||||
)
|
||||
assert cache.get("fs-import:status") == "pending"
|
||||
|
||||
|
||||
def test_fs_import_post_already_running(
|
||||
factories, superuser_api_client, cache, mocker, settings, tmpdir
|
||||
):
|
||||
url = reverse("api:v1:libraries-fs-import")
|
||||
cache.set("fs-import:status", "pending")
|
||||
|
||||
response = superuser_api_client.post(url, {"path": "test"})
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_fs_import_cancel_already_running(
|
||||
factories, superuser_api_client, cache, mocker, settings, tmpdir
|
||||
):
|
||||
url = reverse("api:v1:libraries-fs-import")
|
||||
cache.set("fs-import:status", "pending")
|
||||
|
||||
response = superuser_api_client.delete(url)
|
||||
|
||||
assert response.status_code == 204
|
||||
assert cache.get("fs-import:status") == "canceled"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue