diff --git a/pyrekordbox/db6/database.py b/pyrekordbox/db6/database.py index a67f7c0..a547e20 100644 --- a/pyrekordbox/db6/database.py +++ b/pyrekordbox/db6/database.py @@ -1289,14 +1289,6 @@ def delete_playlist(self, playlist): self.registry.on_delete(child_ids[1:]) self.registry.on_delete(moved) - # Check masterPlaylist6.xml - if self.playlist_xml is not None: - for plxml in self.playlist_xml.get_playlists(): - if plxml["Lib_Type"] != 0: - continue - pid = int(plxml["Id"], 16) - assert self.query(tables.DjmdPlaylist).filter_by(ID=pid).count() == 1 - def move_playlist(self, playlist, parent=None, seq=None): """Moves a playlist (folder) in the current parent folder or to a new one. diff --git a/tests/test_db6.py b/tests/test_db6.py index 5fcfb8a..72f9ea1 100644 --- a/tests/test_db6.py +++ b/tests/test_db6.py @@ -249,6 +249,28 @@ def test_autoincrement_local_usn(db): assert playlist.rb_local_usn == new_usn +def _check_playlist_xml(db): + # Check that playlist is in XML and update time is correct + for pl in db.get_playlist(): + plxml = db.playlist_xml.get(pl.ID) + ts = plxml["Timestamp"] + diff = pl.updated_at - ts + if abs(diff.total_seconds()) > 1: + return False + return True + + +def _check_playlist_xml_delete(db): + # Check that there are no items in the XML that are not in the db + for plxml in db.playlist_xml.get_playlists(): + if plxml["Lib_Type"] != 0: + continue + pid = int(plxml["Id"], 16) + if db.query(tables.DjmdPlaylist).filter_by(ID=pid).count() != 1: + return False + return True + + def test_add_song_to_playlist(db): usn_old = db.get_local_usn() mtime_old = db.get_playlist(ID=PID1).updated_at @@ -273,6 +295,8 @@ def test_add_song_to_playlist(db): with pytest.raises(ValueError): db.add_to_playlist(PID1, CID2, track_no=3) + assert _check_playlist_xml(db) + def test_add_song_to_playlist_trackno_end(db): old_usn = db.get_local_usn() @@ -285,6 +309,8 @@ def test_add_song_to_playlist_trackno_end(db): assert song3.TrackNo == 3 assert db.get_local_usn() == old_usn + 3 + assert _check_playlist_xml(db) + def test_add_song_to_playlist_trackno_middle(db): song1 = db.add_to_playlist(PID1, CID1) @@ -319,6 +345,8 @@ def test_add_song_to_playlist_trackno_middle(db): assert songs[2].rb_local_usn == usn_old + 2 assert db.get_local_usn() == usn_old + 2 + assert _check_playlist_xml(db) + def test_remove_song_from_playlist_end(db): # Add songs to playlist @@ -347,6 +375,8 @@ def test_remove_song_from_playlist_end(db): assert pl.updated_at == mtime_old assert db.get_local_usn() == usn_old + 1 + assert _check_playlist_xml(db) + def test_remove_song_from_playlist_middle(db): # Add songs to playlist @@ -373,6 +403,8 @@ def test_remove_song_from_playlist_middle(db): assert db.get_local_usn() == usn_old + 2 assert songs[1].rb_local_usn == usn_old + 2 + assert _check_playlist_xml(db) + def test_move_in_playlist_forward(db): # Add songs to playlist @@ -401,6 +433,8 @@ def test_move_in_playlist_forward(db): assert s3.rb_local_usn == expected_usn assert s4.rb_local_usn == usn_old + assert _check_playlist_xml(db) + def test_move_in_playlist_backward(db): # Add songs to playlist @@ -429,6 +463,8 @@ def test_move_in_playlist_backward(db): assert s3.rb_local_usn == expected_usn assert s4.rb_local_usn == usn_old + assert _check_playlist_xml(db) + def test_create_playlist(db): seqs = [pl.Seq for pl in db.get_playlist()] @@ -463,8 +499,7 @@ def test_create_playlist(db): # Check if playlist was added to xml plxml = db.playlist_xml.get(pl.ID) assert plxml is not None - ts = plxml["Timestamp"] - assert int(pl.updated_at.timestamp() * 1000) == int(ts.timestamp() * 1000) + assert _check_playlist_xml(db) def test_create_playlist_seq_middle(db): @@ -495,6 +530,8 @@ def test_create_playlist_seq_middle(db): assert pl1.rb_local_usn == old_usn + 1 assert pl2.rb_local_usn == old_usn + 3 + assert _check_playlist_xml(db) + def test_create_playlist_folder(db): seqs = [pl.Seq for pl in db.get_playlist()] @@ -525,27 +562,7 @@ def test_create_playlist_folder(db): pl = db.get_playlist(ID=pid) assert len(pl.Children) == 1 - -def test_playlist_xml_sync(db): - # Create playlist structure - folder1 = db.create_playlist_folder("dev folder") - folder2 = db.create_playlist_folder("sub folder 1", parent=folder1.ID) - db.create_playlist("sub playlist 1", parent=folder1.ID) - db.create_playlist("sub playlist 2", parent=folder1.ID) - db.create_playlist("sub sub playlist 1", parent=folder2.ID) - db.create_playlist("sub sub playlist 2", parent=folder2.ID) - db.commit() - - # Check that every playlist is synced in the masterPlaylists xml file - for pl in db.get_playlist(): - if pl.Name == "Trial playlist - Cloud Library Sync": - continue - plxml = db.playlist_xml.get(pl.ID) - # Check if playlist exists - assert plxml is not None - # Check update time - ts = plxml["Timestamp"] - assert int(pl.updated_at.timestamp() * 1000) == int(ts.timestamp() * 1000) + assert _check_playlist_xml(db) def test_delete_playlist_empty_end(db): @@ -573,6 +590,9 @@ def test_delete_playlist_empty_end(db): # Check USN is correct (+1 for deleting) assert db.get_local_usn() == usn_old + 1 + assert _check_playlist_xml(db) + assert _check_playlist_xml_delete(db) + def test_delete_playlist_empty(db): # Create playlist structure @@ -603,6 +623,9 @@ def test_delete_playlist_empty(db): assert pl.Seq == 2 assert pl.rb_local_usn == usn_old + 1 + assert _check_playlist_xml(db) + assert _check_playlist_xml_delete(db) + def test_delete_playlist_folder_empty(db): # Create playlist structure @@ -633,6 +656,9 @@ def test_delete_playlist_folder_empty(db): assert db.get_local_usn() == usn_old + 1 assert pl.rb_local_usn == usn_old + 1 + assert _check_playlist_xml(db) + assert _check_playlist_xml_delete(db) + def test_delete_playlist_non_empty(db): # Create playlist structure @@ -668,6 +694,9 @@ def test_delete_playlist_non_empty(db): # Check if USN is correct (+1 for deleting with contents) assert db.get_local_usn() == usn_old + 1 + assert _check_playlist_xml(db) + assert _check_playlist_xml_delete(db) + def test_delete_playlist_folder_non_empty(db): # Create playlist structure @@ -710,6 +739,9 @@ def test_delete_playlist_folder_non_empty(db): # Check if USN is correct (+1 for deleting with Seq update, +1 for children) assert db.get_local_usn() == usn_old + 2 + assert _check_playlist_xml(db) + assert _check_playlist_xml_delete(db) + def test_delete_playlist_folder_chained(db): # Create playlist structure @@ -762,6 +794,9 @@ def test_delete_playlist_folder_chained(db): # Check if USN is correct (+1 for deleting with Seq update, +1 for children) assert db.get_local_usn() == usn_old + 2 + assert _check_playlist_xml(db) + assert _check_playlist_xml_delete(db) + def test_move_playlist_seq(db): # Create playlist structure @@ -838,6 +873,8 @@ def test_move_playlist_seq(db): assert pl3.updated_at > mtime_old assert f2.updated_at > mtime_old + assert _check_playlist_xml(db) + def test_move_playlist_parent(db): # Create playlist structure @@ -916,6 +953,8 @@ def test_move_playlist_parent(db): assert subpl4.rb_local_usn == old_usn + 4 assert pl1.rb_local_usn == old_usn + 5 + assert _check_playlist_xml(db) + def test_rename_playlist(db): # Create playlist structure @@ -939,6 +978,8 @@ def test_rename_playlist(db): assert db.get_local_usn() == usn_old + 1 assert pl.rb_local_usn == usn_old + 1 + assert _check_playlist_xml(db) + def test_get_anlz_paths(): content = DB.get_content().first()