All tests passing
This commit is contained in:
parent
805053b795
commit
fe660524a0
@ -97,9 +97,9 @@ class NoteColours(Base):
|
||||
|
||||
for rec in (
|
||||
session.query(NoteColours)
|
||||
.filter(NoteColours.enabled.is_(True))
|
||||
.order_by(NoteColours.order)
|
||||
.all()
|
||||
.filter(NoteColours.enabled.is_(True))
|
||||
.order_by(NoteColours.order)
|
||||
.all()
|
||||
):
|
||||
if rec.is_regex:
|
||||
flags = re.UNICODE
|
||||
@ -130,8 +130,7 @@ class Notes(Base):
|
||||
note: str = Column(String(256), index=False)
|
||||
|
||||
def __init__(
|
||||
self, session: Session, playlist_id: int, row: int,
|
||||
text: str) -> None:
|
||||
self, session: Session, playlist_id: int, row: int, text: str) -> None:
|
||||
"""Create note"""
|
||||
|
||||
DEBUG(f"Notes.__init__({playlist_id=}, {row=}, {text=})")
|
||||
@ -294,8 +293,8 @@ class Playlists(Base):
|
||||
|
||||
return (
|
||||
session.query(cls)
|
||||
.filter(cls.loaded.is_(False))
|
||||
.order_by(cls.last_used.desc())
|
||||
.filter(cls.loaded.is_(False))
|
||||
.order_by(cls.last_used.desc())
|
||||
).all()
|
||||
|
||||
@classmethod
|
||||
@ -306,8 +305,8 @@ class Playlists(Base):
|
||||
|
||||
return (
|
||||
session.query(cls)
|
||||
.filter(cls.loaded.is_(True))
|
||||
.order_by(cls.last_used.desc())
|
||||
.filter(cls.loaded.is_(True))
|
||||
.order_by(cls.last_used.desc())
|
||||
).all()
|
||||
|
||||
def mark_open(self, session: Session) -> None:
|
||||
@ -355,7 +354,7 @@ class PlaylistTracks(Base):
|
||||
|
||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||
playlist_id: int = Column(Integer, ForeignKey('playlists.id'),
|
||||
primary_key=True)
|
||||
primary_key=True)
|
||||
track_id: int = Column(Integer, ForeignKey('tracks.id'), primary_key=True)
|
||||
row: int = Column(Integer, nullable=False)
|
||||
tracks: RelationshipProperty = relationship("Tracks")
|
||||
@ -370,7 +369,7 @@ class PlaylistTracks(Base):
|
||||
)
|
||||
# Ensure row numbers are unique within each playlist
|
||||
__table_args__ = (UniqueConstraint
|
||||
('row', 'playlist_id', name="uniquerow"),
|
||||
('row', 'playlist_id', name="uniquerow"),
|
||||
)
|
||||
|
||||
def __init__(
|
||||
@ -425,8 +424,8 @@ class PlaylistTracks(Base):
|
||||
PlaylistTracks.row.in_(rows)
|
||||
).update({'playlist_id': to_playlist_id,
|
||||
'row': PlaylistTracks.row + offset},
|
||||
False
|
||||
)
|
||||
False
|
||||
)
|
||||
|
||||
|
||||
class Settings(Base):
|
||||
@ -476,11 +475,11 @@ class Tracks(Base):
|
||||
mtime: float = Column(Float, index=True)
|
||||
lastplayed: datetime = Column(DateTime, index=True, default=None)
|
||||
playlists: RelationshipProperty = relationship("PlaylistTracks",
|
||||
back_populates="tracks",
|
||||
lazy="joined")
|
||||
back_populates="tracks",
|
||||
lazy="joined")
|
||||
playdates: RelationshipProperty = relationship("Playdates",
|
||||
back_populates="tracks",
|
||||
lazy="joined")
|
||||
back_populates="tracks",
|
||||
lazy="joined")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -589,10 +588,10 @@ class Tracks(Base):
|
||||
audio: AudioSegment = get_audio_segment(self.path)
|
||||
self.duration = len(audio)
|
||||
self.fade_at = round(fade_point(audio) / 1000,
|
||||
Config.MILLISECOND_SIGFIGS) * 1000
|
||||
Config.MILLISECOND_SIGFIGS) * 1000
|
||||
self.mtime = os.path.getmtime(self.path)
|
||||
self.silence_at = round(trailing_silence(audio) / 1000,
|
||||
Config.MILLISECOND_SIGFIGS) * 1000
|
||||
Config.MILLISECOND_SIGFIGS) * 1000
|
||||
self.start_gap = leading_silence(audio)
|
||||
session.add(self)
|
||||
session.flush()
|
||||
@ -614,16 +613,16 @@ class Tracks(Base):
|
||||
|
||||
return (
|
||||
session.query(cls)
|
||||
.filter(cls.artist.ilike(f"%{text}%"))
|
||||
.order_by(cls.title)
|
||||
.filter(cls.artist.ilike(f"%{text}%"))
|
||||
.order_by(cls.title)
|
||||
).all()
|
||||
|
||||
@classmethod
|
||||
def search_titles(cls, session: Session, text: str) -> List["Tracks"]:
|
||||
return (
|
||||
session.query(cls)
|
||||
.filter(cls.title.ilike(f"%{text}%"))
|
||||
.order_by(cls.title)
|
||||
.filter(cls.title.ilike(f"%{text}%"))
|
||||
.order_by(cls.title)
|
||||
).all()
|
||||
|
||||
@staticmethod
|
||||
|
||||
@ -122,7 +122,7 @@ def test_playdates_add_playdate(session):
|
||||
track_path = "/a/b/c"
|
||||
track = Tracks(session, track_path)
|
||||
|
||||
playdate = Playdates(session, track)
|
||||
playdate = Playdates(session, track.id)
|
||||
assert playdate
|
||||
|
||||
last_played = Playdates.last_played(session, track.id)
|
||||
@ -136,7 +136,7 @@ def test_playdates_remove_track(session):
|
||||
track_path = "/a/b/c"
|
||||
track = Tracks(session, track_path)
|
||||
|
||||
playdate = Playdates(session, track)
|
||||
playdate = Playdates(session, track.id)
|
||||
Playdates.remove_track(session, track.id)
|
||||
|
||||
last_played = Playdates.last_played(session, track.id)
|
||||
@ -475,7 +475,7 @@ def test_tracks_update_lastplayed(session):
|
||||
track1 = Tracks(session, track1_path)
|
||||
|
||||
assert track1.lastplayed is None
|
||||
track1.update_lastplayed(session)
|
||||
track1.update_lastplayed(session, track1.id)
|
||||
assert track1.lastplayed is not None
|
||||
|
||||
|
||||
|
||||
@ -61,11 +61,9 @@ def test_save_and_restore(qtbot, session):
|
||||
# Add a track
|
||||
track_path = "/a/b/c"
|
||||
track = models.Tracks(session, track_path)
|
||||
# Inserting the track will also save the playlist
|
||||
playlist_tab.insert_track(session, track)
|
||||
|
||||
# Save playlist
|
||||
playlist_tab.save_playlist(session)
|
||||
|
||||
# We need to commit the session before re-querying
|
||||
session.commit()
|
||||
|
||||
@ -86,15 +84,20 @@ def test_meta_all_clear(qtbot, session):
|
||||
playlist_tab = playlists.PlaylistTab(None, session, playlist.id)
|
||||
|
||||
# Add some tracks
|
||||
# Need to commit session after each one so that new row is found
|
||||
# for subsequent inserts
|
||||
track1_path = "/a/b/c"
|
||||
track1 = models.Tracks(session, track1_path)
|
||||
playlist_tab.insert_track(session, track1)
|
||||
session.commit()
|
||||
track2_path = "/d/e/f"
|
||||
track2 = models.Tracks(session, track2_path)
|
||||
playlist_tab.insert_track(session, track2)
|
||||
session.commit()
|
||||
track3_path = "/h/i/j"
|
||||
track3 = models.Tracks(session, track3_path)
|
||||
playlist_tab.insert_track(session, track3)
|
||||
session.commit()
|
||||
|
||||
assert playlist_tab._get_current_track_row() is None
|
||||
assert playlist_tab._get_next_track_row() is None
|
||||
@ -113,12 +116,15 @@ def test_meta(qtbot, session):
|
||||
track1_path = "/a/b/c"
|
||||
track1 = models.Tracks(session, track1_path)
|
||||
playlist_tab.insert_track(session, track1)
|
||||
session.commit()
|
||||
track2_path = "/d/e/f"
|
||||
track2 = models.Tracks(session, track2_path)
|
||||
playlist_tab.insert_track(session, track2)
|
||||
session.commit()
|
||||
track3_path = "/h/i/j"
|
||||
track3 = models.Tracks(session, track3_path)
|
||||
playlist_tab.insert_track(session, track3)
|
||||
session.commit()
|
||||
|
||||
assert len(playlist_tab._get_unreadable_track_rows()) == 3
|
||||
|
||||
@ -191,9 +197,11 @@ def test_clear_next(qtbot, session):
|
||||
track1_path = "/a/b/c"
|
||||
track1 = models.Tracks(session, track1_path)
|
||||
playlist_tab.insert_track(session, track1)
|
||||
session.commit()
|
||||
track2_path = "/d/e/f"
|
||||
track2 = models.Tracks(session, track2_path)
|
||||
playlist_tab.insert_track(session, track2)
|
||||
session.commit()
|
||||
|
||||
playlist_tab._set_next_track_row(1)
|
||||
assert playlist_tab._get_next_track_row() == 1
|
||||
@ -216,9 +224,11 @@ def test_get_selected_row(qtbot, monkeypatch, session):
|
||||
track1_path = "/a/b/c"
|
||||
track1 = models.Tracks(session, track1_path)
|
||||
playlist_tab.insert_track(session, track1)
|
||||
session.commit()
|
||||
track2_path = "/d/e/f"
|
||||
track2 = models.Tracks(session, track2_path)
|
||||
playlist_tab.insert_track(session, track2)
|
||||
session.commit()
|
||||
|
||||
qtbot.addWidget(playlist_tab)
|
||||
with qtbot.waitExposed(window):
|
||||
@ -254,6 +264,7 @@ def test_set_next(qtbot, monkeypatch, session):
|
||||
assert track1_title
|
||||
|
||||
playlist_tab.insert_track(session, track1)
|
||||
session.commit()
|
||||
track2 = models.Tracks.get_by_filename(session, "mom.mp3")
|
||||
playlist_tab.insert_track(session, track2)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user