All test_playlistmodel tests pass

This commit is contained in:
Keith Edmunds 2025-04-13 10:17:58 +01:00
parent 5317ecdf18
commit a8791f925d
3 changed files with 25 additions and 29 deletions

View File

@ -857,7 +857,7 @@ class PlaylistModel(QAbstractTableModel):
# @log_call
def move_rows_between_playlists(
self,
from_rows: list[PlaylistRow],
from_rows: list[int],
to_row_number: int,
to_playlist_id: int,
) -> None:
@ -878,7 +878,7 @@ class PlaylistModel(QAbstractTableModel):
# and the row range must be contiguous. Process the highest rows
# first so the lower row numbers are unchanged
row_groups = self._reversed_contiguous_row_groups([a.row_number for a in from_rows])
row_groups = self._reversed_contiguous_row_groups(from_rows)
# Handle the moves in row_group chunks
@ -891,10 +891,10 @@ class PlaylistModel(QAbstractTableModel):
to_row_number + len(row_group)
)
self.signals.signal_begin_insert_rows.emit(insert_rows)
ds.move_rows(from_rows=row_group,
from_playlist_id=self.playlist_id,
to_row=to_row_number,
to_playlist_id=to_playlist_id)
ds.playlist_move_rows(from_rows=row_group,
from_playlist_id=self.playlist_id,
to_row=to_row_number,
to_playlist_id=to_playlist_id)
self.signals.signal_end_insert_rows.emit(to_playlist_id)
super().endRemoveRows()
@ -921,6 +921,7 @@ class PlaylistModel(QAbstractTableModel):
return
super().endInsertRows()
self.refresh_data()
# @log_call
def move_track_add_note(
@ -1035,7 +1036,7 @@ class PlaylistModel(QAbstractTableModel):
"""Populate dict for one row from database"""
plrid = self.playlist_rows[row_number].playlistrow_id
refreshed_row = ds.get_playlist_row(plrid)
refreshed_row = ds.playlistrow_by_id(plrid)
if not refreshed_row:
raise ApplicationError(f"Failed to retrieve row {self.playlist_id=}, {row_number=}")
@ -1161,7 +1162,7 @@ class PlaylistModel(QAbstractTableModel):
header_text = header_text[0:-1]
# Parse passed header text and remove the first colour match string
return ds.remove_colour_substring(header_text)
return ds.notecolours_remove_colour_substring(header_text)
def rowCount(self, index: QModelIndex = QModelIndex()) -> int:
"""Standard function for view"""

View File

@ -161,7 +161,7 @@ class PlaylistRow:
if self.track_id > 0:
raise ApplicationError("Attempting to add track to row with existing track ({self=}")
ds.add_track_to_header(playlistrow_id=self.playlistrow_id, track_id=track_id)
ds.track_add_to_header(playlistrow_id=self.playlistrow_id, track_id=track_id)
# Need to update with track information
track = ds.track_by_id(track_id)

View File

@ -37,8 +37,9 @@ class TestMMMiscTracks(unittest.TestCase):
for row in range(len(self.test_tracks)):
track_path = self.test_tracks[row % len(self.test_tracks)]
track = ds.track_create(**get_all_track_metadata(track_path))
self.model.insert_row(track_id=track.id, note=f"{row=}")
metadata = get_all_track_metadata(track_path)
track = ds.track_create(metadata)
self.model.insert_row(track_id=track.track_id, note=f"{row=}")
def tearDown(self):
db.drop_all()
@ -91,14 +92,14 @@ class TestMMMiscNoPlaylist(unittest.TestCase):
# insert a track into a new playlist
playlist = ds.playlist_create(self.PLAYLIST_NAME, template_id=0)
# Create a model
model = playlistmodel.PlaylistModel(playlist.id, is_template=False)
model = playlistmodel.PlaylistModel(playlist.playlist_id, is_template=False)
# test repr
_ = str(model)
track_path = self.test_tracks[0]
metadata = get_all_track_metadata(track_path)
track = ds.track_create(metadata)
model.insert_row(track_id=track.id)
model.insert_row(track_id=track.track_id)
prd = model.playlist_rows[model.rowCount() - 1]
# test repr
@ -118,7 +119,7 @@ class TestMMMiscRowMove(unittest.TestCase):
db.create_all()
self.playlist = ds.playlist_create(self.PLAYLIST_NAME, template_id=0)
self.model = playlistmodel.PlaylistModel(self.playlist.id, is_template=False)
self.model = playlistmodel.PlaylistModel(self.playlist.playlist_id, is_template=False)
for row in range(self.ROWS_TO_CREATE):
self.model.insert_row(note=str(row))
@ -207,12 +208,10 @@ class TestMMMiscRowMove(unittest.TestCase):
for row in range(self.ROWS_TO_CREATE):
model_dst.insert_row(note=str(row))
ds.playlist_move_rows(
from_rows, self.playlist.playlist_id, to_row, playlist_dst.playlist_id
)
model_src.move_rows_between_playlists(from_rows, to_row, playlist_dst.playlist_id)
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
assert len(model_dst.playlist_rows) == self.ROWS_TO_CREATE + len(from_rows)
assert model_src.rowCount() == self.ROWS_TO_CREATE - len(from_rows)
assert model_dst.rowCount() == self.ROWS_TO_CREATE + len(from_rows)
assert sorted([a.row_number for a in model_src.playlist_rows.values()]) == list(
range(len(model_src.playlist_rows))
)
@ -230,9 +229,7 @@ class TestMMMiscRowMove(unittest.TestCase):
for row in range(self.ROWS_TO_CREATE):
model_dst.insert_row(note=str(row))
ds.playlist_move_rows(
from_rows, self.playlist.playlist_id, to_row, playlist_dst.playlist_id
)
model_src.move_rows_between_playlists(from_rows, to_row, playlist_dst.playlist_id)
# Check the rows of the destination model
row_notes = []
@ -242,8 +239,8 @@ class TestMMMiscRowMove(unittest.TestCase):
)
row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole))
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
assert len(model_dst.playlist_rows) == self.ROWS_TO_CREATE + len(from_rows)
assert model_src.rowCount() == self.ROWS_TO_CREATE - len(from_rows)
assert model_dst.rowCount() == self.ROWS_TO_CREATE + len(from_rows)
assert [int(a) for a in row_notes] == [0, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def test_move_multiple_rows_between_playlists_to_end(self):
@ -260,9 +257,7 @@ class TestMMMiscRowMove(unittest.TestCase):
for row in range(self.ROWS_TO_CREATE):
model_dst.insert_row(note=str(row))
ds.playlist_move_rows(
from_rows, self.playlist.id, playlist_dst.playlist_id, to_row
)
model_src.move_rows_between_playlists(from_rows, to_row, playlist_dst.playlist_id)
# Check the rows of the destination model
row_notes = []
@ -272,8 +267,8 @@ class TestMMMiscRowMove(unittest.TestCase):
)
row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole))
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
assert len(model_dst.playlist_rows) == self.ROWS_TO_CREATE + len(from_rows)
assert model_src.rowCount() == self.ROWS_TO_CREATE - len(from_rows)
assert model_dst.rowCount() == self.ROWS_TO_CREATE + len(from_rows)
assert [int(a) for a in row_notes] == [
0,
1,