Remove redundant functions and tests

This commit is contained in:
Keith Edmunds 2022-02-12 23:18:07 +00:00
parent fcebe2f220
commit fec45925c6
2 changed files with 89 additions and 88 deletions

View File

@ -269,21 +269,22 @@ class Playlists(Base):
def __repr__(self): def __repr__(self):
return f"<Playlists(id={self.id}, name={self.name}>" return f"<Playlists(id={self.id}, name={self.name}>"
def add_track(self, session, track, row=None): # Not used
""" # def add_track(self, session, track, row=None):
Add track to playlist at given row. # """
If row=None, add to end of playlist # Add track to playlist at given row.
""" # If row=None, add to end of playlist
# """
if not row: # if not row:
row = PlaylistTracks.new_row(session, self.id) # row = PlaylistTracks.new_row(session, self.id)
DEBUG(f"Playlists:add_track({session=}, {track=}, {row=})") # DEBUG(f"Playlists:add_track({session=}, {track=}, {row=})")
glue = PlaylistTracks(row=row) # glue = PlaylistTracks(row=row)
glue.track_id = track.id # glue.track_id = track.id
self.tracks.append(glue) # self.tracks.append(glue)
session.commit() # session.commit()
def close(self, session): def close(self, session):
"""Record playlist as no longer loaded""" """Record playlist as no longer loaded"""
@ -323,8 +324,8 @@ class Playlists(Base):
.order_by(cls.last_used.desc()) .order_by(cls.last_used.desc())
).all() ).all()
def get_notes(self): #def get_notes(self):
return [a.note for a in self.notes] # return [a.note for a in self.notes]
@classmethod @classmethod
def get_playlist_by_id(cls, session, playlist_id): def get_playlist_by_id(cls, session, playlist_id):

View File

@ -42,65 +42,65 @@ def test_notecolours_get_by_id(session):
assert record.colour == "abcdef" assert record.colour == "abcdef"
def test_notes_add_note(session): # def test_notes_add_note(session):
"""Add and retrieve a note""" # """Add and retrieve a note"""
#
# We need to have a playlist to add the note to # # We need to have a playlist to add the note to
pl = Playlists() # pl = Playlists()
pl.name = "Test playlist" # pl.name = "Test playlist"
session.add(pl) # session.add(pl)
session.commit() # session.commit()
#
note_text = "Here we are" # note_text = "Here we are"
Notes.add_note(session, pl.id, 1, note_text) # Notes.add_note(session, pl.id, 1, note_text)
#
# We retrieve notes via playlist # # We retrieve notes via playlist
playlist = Playlists.get_playlist_by_id(session, pl.id) # playlist = Playlists.get_playlist_by_id(session, pl.id)
notes = playlist.get_notes() # notes = playlist.get_notes()
assert len(notes) == 1 # assert len(notes) == 1
assert notes[0] == note_text # assert notes[0] == note_text
def test_notes_delete_note(session): # def test_notes_delete_note(session):
"""Add and delete a note""" # """Add and delete a note"""
#
# We need to have a playlist to add the note to # # We need to have a playlist to add the note to
pl = Playlists() # pl = Playlists()
pl.name = "Test playlist" # pl.name = "Test playlist"
session.add(pl) # session.add(pl)
session.commit() # session.commit()
#
note_text = "Here we are" # note_text = "Here we are"
rec = Notes.add_note(session, pl.id, 1, note_text) # rec = Notes.add_note(session, pl.id, 1, note_text)
#
Notes.delete_note(session, rec.id) # Notes.delete_note(session, rec.id)
#
# We retrieve notes via playlist # # We retrieve notes via playlist
playlist = Playlists.get_playlist_by_id(session, pl.id) # playlist = Playlists.get_playlist_by_id(session, pl.id)
notes = playlist.get_notes() # notes = playlist.get_notes()
assert len(notes) == 0 # assert len(notes) == 0
def test_notes_update_note(session): # def test_notes_update_note(session):
"""Add and update a note""" # """Add and update a note"""
#
# We need to have a playlist to add the note to # # We need to have a playlist to add the note to
pl = Playlists() # pl = Playlists()
pl.name = "Test playlist" # pl.name = "Test playlist"
session.add(pl) # session.add(pl)
session.commit() # session.commit()
#
original_text = "Here we are" # original_text = "Here we are"
replacement_text = "There we go" # replacement_text = "There we go"
rec = Notes.add_note(session, pl.id, 1, original_text) # rec = Notes.add_note(session, pl.id, 1, original_text)
#
Notes.update_note(session, rec.id, 1, text=replacement_text) # Notes.update_note(session, rec.id, 1, text=replacement_text)
#
# We retrieve notes via playlist # # We retrieve notes via playlist
playlist = Playlists.get_playlist_by_id(session, pl.id) # playlist = Playlists.get_playlist_by_id(session, pl.id)
notes = playlist.get_notes() # notes = playlist.get_notes()
assert len(notes) == 1 # assert len(notes) == 1
assert notes[0] == replacement_text # assert notes[0] == replacement_text
def test_playdates_add_playdate(session): def test_playdates_add_playdate(session):
@ -136,25 +136,25 @@ def test_playdates_remove_track(session):
assert last_played is None assert last_played is None
def test_playlist_add_track(session): # def test_playlist_add_track(session):
"""Test adding track to playlist""" # """Test adding track to playlist"""
#
# We need a track # # We need a track
track_path = "/a/b/c" # track_path = "/a/b/c"
track = Tracks.get_or_create(session, track_path) # track = Tracks.get_or_create(session, track_path)
# Need to commit because track record is updated in Playdates.add_playdate() # # Need to commit because track record is updated in Playdates.add_playdate()
session.commit() # session.commit()
#
playlist = Playlists() # playlist = Playlists()
playlist.name = "Test playlist" # playlist.name = "Test playlist"
session.add(playlist) # session.add(playlist)
session.commit() # session.commit()
#
playlist.add_track(session, track) # playlist.add_track(session, track)
#
tracks = playlist.get_tracks() # tracks = playlist.get_tracks()
assert len(tracks) == 1 # assert len(tracks) == 1
assert tracks[0].path == track_path # assert tracks[0].path == track_path
def test_playlist_close(session): def test_playlist_close(session):