Put commit()s where needed, move some info to debug logging
This commit is contained in:
parent
16e3c8235e
commit
76021aa1c6
@ -78,7 +78,7 @@ class NoteColours(dbtables.NoteColoursTable):
|
||||
self.order = order
|
||||
|
||||
session.add(self)
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
@classmethod
|
||||
def get_all(cls, session: Session) -> Sequence["NoteColours"]:
|
||||
@ -162,7 +162,7 @@ class Playlists(dbtables.PlaylistsTable):
|
||||
def __init__(self, session: Session, name: str):
|
||||
self.name = name
|
||||
session.add(self)
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def clear_tabs(session: Session, playlist_ids: List[int]) -> None:
|
||||
@ -201,7 +201,7 @@ class Playlists(dbtables.PlaylistsTable):
|
||||
"""
|
||||
|
||||
self.deleted = True
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
@classmethod
|
||||
def get_all(cls, session: Session) -> Sequence["Playlists"]:
|
||||
@ -268,7 +268,7 @@ class Playlists(dbtables.PlaylistsTable):
|
||||
"""
|
||||
|
||||
self.name = new_name
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def save_as_template(
|
||||
@ -381,7 +381,7 @@ class PlaylistRows(dbtables.PlaylistRowsTable):
|
||||
PlaylistRows.plr_rownum > maxrow,
|
||||
)
|
||||
)
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def delete_row(session: Session, playlist_id: int, row_number: int) -> None:
|
||||
@ -575,7 +575,7 @@ class Settings(dbtables.SettingsTable):
|
||||
def __init__(self, session: Session, name: str):
|
||||
self.name = name
|
||||
session.add(self)
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
@classmethod
|
||||
def all_as_dict(cls, session):
|
||||
@ -605,7 +605,7 @@ class Settings(dbtables.SettingsTable):
|
||||
for key, value in data.items():
|
||||
assert hasattr(self, key)
|
||||
setattr(self, key, value)
|
||||
session.flush()
|
||||
session.commit()
|
||||
|
||||
|
||||
class Tracks(dbtables.TracksTable):
|
||||
|
||||
@ -123,7 +123,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
log.info(f"PlaylistModel.__init__({playlist_id=})")
|
||||
log.debug(f"PlaylistModel.__init__({playlist_id=})")
|
||||
|
||||
self.playlist_id = playlist_id
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -548,7 +548,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
If not given, return row number to add to end of model.
|
||||
"""
|
||||
|
||||
log.info(f"_get_new_row_number({proposed_row_number=})")
|
||||
log.debug(f"_get_new_row_number({proposed_row_number=})")
|
||||
|
||||
if proposed_row_number is None or proposed_row_number > len(self.playlist_rows):
|
||||
# We are adding to the end of the list
|
||||
@ -845,7 +845,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
Move the playlist rows given to to_row and below.
|
||||
"""
|
||||
|
||||
log.info(f"move_rows({from_rows=}, {to_row_number=}")
|
||||
log.debug(f"move_rows({from_rows=}, {to_row_number=}")
|
||||
|
||||
# Build a {current_row_number: new_row_number} dictionary
|
||||
row_map: dict[int, int] = {}
|
||||
@ -1107,7 +1107,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
Signal handler for when row ordering has changed
|
||||
"""
|
||||
|
||||
log.info("reset_track_sequence_row_numbers()")
|
||||
log.debug("reset_track_sequence_row_numbers()")
|
||||
|
||||
# Check the track_sequence next, now and previous plrs and
|
||||
# update the row number
|
||||
|
||||
@ -28,47 +28,47 @@ from app.models import ( # noqa: E402
|
||||
)
|
||||
|
||||
|
||||
# class TestMMMiscTracks(unittest.TestCase):
|
||||
# def setUp(self):
|
||||
# PLAYLIST_NAME = "tracks playlist"
|
||||
# self.test_tracks = [
|
||||
# "testdata/isa.mp3",
|
||||
# "testdata/isa_with_gap.mp3",
|
||||
# "testdata/loser.mp3",
|
||||
# "testdata/lovecats-10seconds.mp3",
|
||||
# "testdata/lovecats.mp3",
|
||||
# "testdata/mom.mp3",
|
||||
# "testdata/sitting.mp3",
|
||||
# ]
|
||||
class TestMMMiscTracks(unittest.TestCase):
|
||||
def setUp(self):
|
||||
PLAYLIST_NAME = "tracks playlist"
|
||||
self.test_tracks = [
|
||||
"testdata/isa.mp3",
|
||||
"testdata/isa_with_gap.mp3",
|
||||
"testdata/loser.mp3",
|
||||
"testdata/lovecats-10seconds.mp3",
|
||||
"testdata/lovecats.mp3",
|
||||
"testdata/mom.mp3",
|
||||
"testdata/sitting.mp3",
|
||||
]
|
||||
|
||||
# db.create_all()
|
||||
db.create_all()
|
||||
|
||||
# # Create a playlist and model
|
||||
# with db.Session() as session:
|
||||
# self.playlist = Playlists(session, PLAYLIST_NAME)
|
||||
# self.model = playlistmodel.PlaylistModel(self.playlist.id)
|
||||
# Create a playlist and model
|
||||
with db.Session() as session:
|
||||
self.playlist = Playlists(session, PLAYLIST_NAME)
|
||||
self.model = playlistmodel.PlaylistModel(self.playlist.id)
|
||||
|
||||
# for row in range(len(self.test_tracks)):
|
||||
# track_path = self.test_tracks[row % len(self.test_tracks)]
|
||||
# metadata = get_file_metadata(track_path)
|
||||
# track = Tracks(session, **metadata)
|
||||
# self.model.insert_row(
|
||||
# proposed_row_number=row, track_id=track.id, note=f"{row=}"
|
||||
# )
|
||||
for row in range(len(self.test_tracks)):
|
||||
track_path = self.test_tracks[row % len(self.test_tracks)]
|
||||
metadata = get_file_metadata(track_path)
|
||||
track = Tracks(session, **metadata)
|
||||
self.model.insert_row(
|
||||
proposed_row_number=row, track_id=track.id, note=f"{row=}"
|
||||
)
|
||||
|
||||
# session.commit()
|
||||
session.commit()
|
||||
|
||||
# def tearDown(self):
|
||||
# db.drop_all()
|
||||
def tearDown(self):
|
||||
db.drop_all()
|
||||
|
||||
# def test_7_row_playlist(self):
|
||||
# # Test auto-created playlist
|
||||
def test_7_row_playlist(self):
|
||||
# Test auto-created playlist
|
||||
|
||||
# assert self.model.rowCount() == 7
|
||||
# assert max(self.model.playlist_rows.keys()) == 6
|
||||
# for row in range(self.model.rowCount()):
|
||||
# assert row in self.model.playlist_rows
|
||||
# assert self.model.playlist_rows[row].plr_rownum == row
|
||||
assert self.model.rowCount() == 7
|
||||
assert max(self.model.playlist_rows.keys()) == 6
|
||||
for row in range(self.model.rowCount()):
|
||||
assert row in self.model.playlist_rows
|
||||
assert self.model.playlist_rows[row].plr_rownum == row
|
||||
|
||||
|
||||
class TestMMMiscRowMove(unittest.TestCase):
|
||||
@ -82,7 +82,6 @@ class TestMMMiscRowMove(unittest.TestCase):
|
||||
self.playlist = Playlists(session, PLAYLIST_NAME)
|
||||
self.model = playlistmodel.PlaylistModel(self.playlist.id)
|
||||
for row in range(ROWS_TO_CREATE):
|
||||
print(f"{row=}")
|
||||
self.model.insert_row(proposed_row_number=row, note=str(row))
|
||||
|
||||
session.commit()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user