Skip to content

Commit

Permalink
bug fix remote library sync (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino authored Apr 10, 2024
1 parent 07b23af commit d6f2e4b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion musify/libraries/remote/core/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ def sync(
results = {}
for name, pl in bar: # synchronise playlists
if name not in self.playlists: # new playlist given, create it on remote first
if dry_run:
results[name] = SyncResultRemotePlaylist(
start=0, added=len(pl), removed=0, unchanged=0, difference=len(pl), final=len(pl)
)
continue

# noinspection PyArgumentList
self.playlists[name] = self.factory.playlist.create(name=name)
results[name] = self.playlists[name].sync(items=pl, kind=kind, reload=reload, dry_run=dry_run)
Expand All @@ -460,7 +466,7 @@ def log_sync(self, results: SyncResultRemotePlaylist | Mapping[str, SyncResultRe
if not isinstance(results, Mapping):
results = {"": results}

max_width = get_max_width(self.playlists)
max_width = get_max_width(results)

self.logger.stat(f"\33[1;96mSync {self.api.source} playlists' stats: \33[0m")
for name, result in results.items():
Expand Down
9 changes: 9 additions & 0 deletions tests/libraries/remote/core/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ def assert_sync(library: RemoteLibrary, playlists: Any, api_mock: RemoteMock):
requests = [req for req in api_mock.get_requests(method="POST") if req.url.startswith(url)]
assert len(requests) > 0

@staticmethod
def test_sync_dry_run(library: RemoteLibrary, api_mock: RemoteMock):
new_playlists = copy(list(library.playlists.values()))
for i, pl in enumerate(new_playlists, 1):
pl.name = f"this is a new playlist name {i}"

library.sync(list(library.playlists.values()) + new_playlists, reload=True)
assert not api_mock.get_requests(method="POST")

# TODO: can this test run faster? runs ~5s on local machine
@pytest.mark.slow
def test_sync(self, library: RemoteLibrary, collection_merge_items: list[RemoteTrack], api_mock: RemoteMock):
Expand Down

0 comments on commit d6f2e4b

Please sign in to comment.