All test_playlistmodel tests pass
This commit is contained in:
parent
5317ecdf18
commit
a8791f925d
@ -857,7 +857,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
# @log_call
|
# @log_call
|
||||||
def move_rows_between_playlists(
|
def move_rows_between_playlists(
|
||||||
self,
|
self,
|
||||||
from_rows: list[PlaylistRow],
|
from_rows: list[int],
|
||||||
to_row_number: int,
|
to_row_number: int,
|
||||||
to_playlist_id: int,
|
to_playlist_id: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -878,7 +878,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
# and the row range must be contiguous. Process the highest rows
|
# and the row range must be contiguous. Process the highest rows
|
||||||
# first so the lower row numbers are unchanged
|
# 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
|
# Handle the moves in row_group chunks
|
||||||
|
|
||||||
@ -891,7 +891,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
to_row_number + len(row_group)
|
to_row_number + len(row_group)
|
||||||
)
|
)
|
||||||
self.signals.signal_begin_insert_rows.emit(insert_rows)
|
self.signals.signal_begin_insert_rows.emit(insert_rows)
|
||||||
ds.move_rows(from_rows=row_group,
|
ds.playlist_move_rows(from_rows=row_group,
|
||||||
from_playlist_id=self.playlist_id,
|
from_playlist_id=self.playlist_id,
|
||||||
to_row=to_row_number,
|
to_row=to_row_number,
|
||||||
to_playlist_id=to_playlist_id)
|
to_playlist_id=to_playlist_id)
|
||||||
@ -921,6 +921,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
return
|
return
|
||||||
|
|
||||||
super().endInsertRows()
|
super().endInsertRows()
|
||||||
|
self.refresh_data()
|
||||||
|
|
||||||
# @log_call
|
# @log_call
|
||||||
def move_track_add_note(
|
def move_track_add_note(
|
||||||
@ -1035,7 +1036,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
"""Populate dict for one row from database"""
|
"""Populate dict for one row from database"""
|
||||||
|
|
||||||
plrid = self.playlist_rows[row_number].playlistrow_id
|
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:
|
if not refreshed_row:
|
||||||
raise ApplicationError(f"Failed to retrieve row {self.playlist_id=}, {row_number=}")
|
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]
|
header_text = header_text[0:-1]
|
||||||
|
|
||||||
# Parse passed header text and remove the first colour match string
|
# 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:
|
def rowCount(self, index: QModelIndex = QModelIndex()) -> int:
|
||||||
"""Standard function for view"""
|
"""Standard function for view"""
|
||||||
|
|||||||
@ -161,7 +161,7 @@ class PlaylistRow:
|
|||||||
if self.track_id > 0:
|
if self.track_id > 0:
|
||||||
raise ApplicationError("Attempting to add track to row with existing track ({self=}")
|
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
|
# Need to update with track information
|
||||||
track = ds.track_by_id(track_id)
|
track = ds.track_by_id(track_id)
|
||||||
|
|||||||
@ -37,8 +37,9 @@ class TestMMMiscTracks(unittest.TestCase):
|
|||||||
|
|
||||||
for row in range(len(self.test_tracks)):
|
for row in range(len(self.test_tracks)):
|
||||||
track_path = self.test_tracks[row % len(self.test_tracks)]
|
track_path = self.test_tracks[row % len(self.test_tracks)]
|
||||||
track = ds.track_create(**get_all_track_metadata(track_path))
|
metadata = get_all_track_metadata(track_path)
|
||||||
self.model.insert_row(track_id=track.id, note=f"{row=}")
|
track = ds.track_create(metadata)
|
||||||
|
self.model.insert_row(track_id=track.track_id, note=f"{row=}")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
db.drop_all()
|
db.drop_all()
|
||||||
@ -91,14 +92,14 @@ class TestMMMiscNoPlaylist(unittest.TestCase):
|
|||||||
# insert a track into a new playlist
|
# insert a track into a new playlist
|
||||||
playlist = ds.playlist_create(self.PLAYLIST_NAME, template_id=0)
|
playlist = ds.playlist_create(self.PLAYLIST_NAME, template_id=0)
|
||||||
# Create a model
|
# Create a model
|
||||||
model = playlistmodel.PlaylistModel(playlist.id, is_template=False)
|
model = playlistmodel.PlaylistModel(playlist.playlist_id, is_template=False)
|
||||||
# test repr
|
# test repr
|
||||||
_ = str(model)
|
_ = str(model)
|
||||||
|
|
||||||
track_path = self.test_tracks[0]
|
track_path = self.test_tracks[0]
|
||||||
metadata = get_all_track_metadata(track_path)
|
metadata = get_all_track_metadata(track_path)
|
||||||
track = ds.track_create(metadata)
|
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]
|
prd = model.playlist_rows[model.rowCount() - 1]
|
||||||
# test repr
|
# test repr
|
||||||
@ -118,7 +119,7 @@ class TestMMMiscRowMove(unittest.TestCase):
|
|||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
self.playlist = ds.playlist_create(self.PLAYLIST_NAME, template_id=0)
|
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):
|
for row in range(self.ROWS_TO_CREATE):
|
||||||
self.model.insert_row(note=str(row))
|
self.model.insert_row(note=str(row))
|
||||||
|
|
||||||
@ -207,12 +208,10 @@ class TestMMMiscRowMove(unittest.TestCase):
|
|||||||
for row in range(self.ROWS_TO_CREATE):
|
for row in range(self.ROWS_TO_CREATE):
|
||||||
model_dst.insert_row(note=str(row))
|
model_dst.insert_row(note=str(row))
|
||||||
|
|
||||||
ds.playlist_move_rows(
|
model_src.move_rows_between_playlists(from_rows, to_row, playlist_dst.playlist_id)
|
||||||
from_rows, self.playlist.playlist_id, to_row, playlist_dst.playlist_id
|
|
||||||
)
|
|
||||||
|
|
||||||
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
|
assert model_src.rowCount() == self.ROWS_TO_CREATE - len(from_rows)
|
||||||
assert len(model_dst.playlist_rows) == 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(
|
assert sorted([a.row_number for a in model_src.playlist_rows.values()]) == list(
|
||||||
range(len(model_src.playlist_rows))
|
range(len(model_src.playlist_rows))
|
||||||
)
|
)
|
||||||
@ -230,9 +229,7 @@ class TestMMMiscRowMove(unittest.TestCase):
|
|||||||
for row in range(self.ROWS_TO_CREATE):
|
for row in range(self.ROWS_TO_CREATE):
|
||||||
model_dst.insert_row(note=str(row))
|
model_dst.insert_row(note=str(row))
|
||||||
|
|
||||||
ds.playlist_move_rows(
|
model_src.move_rows_between_playlists(from_rows, to_row, playlist_dst.playlist_id)
|
||||||
from_rows, self.playlist.playlist_id, to_row, playlist_dst.playlist_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check the rows of the destination model
|
# Check the rows of the destination model
|
||||||
row_notes = []
|
row_notes = []
|
||||||
@ -242,8 +239,8 @@ class TestMMMiscRowMove(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole))
|
row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole))
|
||||||
|
|
||||||
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
|
assert model_src.rowCount() == self.ROWS_TO_CREATE - len(from_rows)
|
||||||
assert len(model_dst.playlist_rows) == 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]
|
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):
|
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):
|
for row in range(self.ROWS_TO_CREATE):
|
||||||
model_dst.insert_row(note=str(row))
|
model_dst.insert_row(note=str(row))
|
||||||
|
|
||||||
ds.playlist_move_rows(
|
model_src.move_rows_between_playlists(from_rows, to_row, playlist_dst.playlist_id)
|
||||||
from_rows, self.playlist.id, playlist_dst.playlist_id, to_row
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check the rows of the destination model
|
# Check the rows of the destination model
|
||||||
row_notes = []
|
row_notes = []
|
||||||
@ -272,8 +267,8 @@ class TestMMMiscRowMove(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole))
|
row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole))
|
||||||
|
|
||||||
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
|
assert model_src.rowCount() == self.ROWS_TO_CREATE - len(from_rows)
|
||||||
assert len(model_dst.playlist_rows) == 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] == [
|
assert [int(a) for a in row_notes] == [
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user