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):
return f"<Playlists(id={self.id}, name={self.name}>"
def add_track(self, session, track, row=None):
"""
Add track to playlist at given row.
If row=None, add to end of playlist
"""
# 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
# """
if not row:
row = PlaylistTracks.new_row(session, self.id)
# if not row:
# 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.track_id = track.id
self.tracks.append(glue)
session.commit()
# glue = PlaylistTracks(row=row)
# glue.track_id = track.id
# self.tracks.append(glue)
# session.commit()
def close(self, session):
"""Record playlist as no longer loaded"""
@ -323,8 +324,8 @@ class Playlists(Base):
.order_by(cls.last_used.desc())
).all()
def get_notes(self):
return [a.note for a in self.notes]
#def get_notes(self):
# return [a.note for a in self.notes]
@classmethod
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"
def test_notes_add_note(session):
"""Add and retrieve a note"""
# We need to have a playlist to add the note to
pl = Playlists()
pl.name = "Test playlist"
session.add(pl)
session.commit()
note_text = "Here we are"
Notes.add_note(session, pl.id, 1, note_text)
# We retrieve notes via playlist
playlist = Playlists.get_playlist_by_id(session, pl.id)
notes = playlist.get_notes()
assert len(notes) == 1
assert notes[0] == note_text
# def test_notes_add_note(session):
# """Add and retrieve a note"""
#
# # We need to have a playlist to add the note to
# pl = Playlists()
# pl.name = "Test playlist"
# session.add(pl)
# session.commit()
#
# note_text = "Here we are"
# Notes.add_note(session, pl.id, 1, note_text)
#
# # We retrieve notes via playlist
# playlist = Playlists.get_playlist_by_id(session, pl.id)
# notes = playlist.get_notes()
# assert len(notes) == 1
# assert notes[0] == note_text
def test_notes_delete_note(session):
"""Add and delete a note"""
# We need to have a playlist to add the note to
pl = Playlists()
pl.name = "Test playlist"
session.add(pl)
session.commit()
note_text = "Here we are"
rec = Notes.add_note(session, pl.id, 1, note_text)
Notes.delete_note(session, rec.id)
# We retrieve notes via playlist
playlist = Playlists.get_playlist_by_id(session, pl.id)
notes = playlist.get_notes()
assert len(notes) == 0
# def test_notes_delete_note(session):
# """Add and delete a note"""
#
# # We need to have a playlist to add the note to
# pl = Playlists()
# pl.name = "Test playlist"
# session.add(pl)
# session.commit()
#
# note_text = "Here we are"
# rec = Notes.add_note(session, pl.id, 1, note_text)
#
# Notes.delete_note(session, rec.id)
#
# # We retrieve notes via playlist
# playlist = Playlists.get_playlist_by_id(session, pl.id)
# notes = playlist.get_notes()
# assert len(notes) == 0
def test_notes_update_note(session):
"""Add and update a note"""
# We need to have a playlist to add the note to
pl = Playlists()
pl.name = "Test playlist"
session.add(pl)
session.commit()
original_text = "Here we are"
replacement_text = "There we go"
rec = Notes.add_note(session, pl.id, 1, original_text)
Notes.update_note(session, rec.id, 1, text=replacement_text)
# We retrieve notes via playlist
playlist = Playlists.get_playlist_by_id(session, pl.id)
notes = playlist.get_notes()
assert len(notes) == 1
assert notes[0] == replacement_text
# def test_notes_update_note(session):
# """Add and update a note"""
#
# # We need to have a playlist to add the note to
# pl = Playlists()
# pl.name = "Test playlist"
# session.add(pl)
# session.commit()
#
# original_text = "Here we are"
# replacement_text = "There we go"
# rec = Notes.add_note(session, pl.id, 1, original_text)
#
# Notes.update_note(session, rec.id, 1, text=replacement_text)
#
# # We retrieve notes via playlist
# playlist = Playlists.get_playlist_by_id(session, pl.id)
# notes = playlist.get_notes()
# assert len(notes) == 1
# assert notes[0] == replacement_text
def test_playdates_add_playdate(session):
@ -136,25 +136,25 @@ def test_playdates_remove_track(session):
assert last_played is None
def test_playlist_add_track(session):
"""Test adding track to playlist"""
# We need a track
track_path = "/a/b/c"
track = Tracks.get_or_create(session, track_path)
# Need to commit because track record is updated in Playdates.add_playdate()
session.commit()
playlist = Playlists()
playlist.name = "Test playlist"
session.add(playlist)
session.commit()
playlist.add_track(session, track)
tracks = playlist.get_tracks()
assert len(tracks) == 1
assert tracks[0].path == track_path
# def test_playlist_add_track(session):
# """Test adding track to playlist"""
#
# # We need a track
# track_path = "/a/b/c"
# track = Tracks.get_or_create(session, track_path)
# # Need to commit because track record is updated in Playdates.add_playdate()
# session.commit()
#
# playlist = Playlists()
# playlist.name = "Test playlist"
# session.add(playlist)
# session.commit()
#
# playlist.add_track(session, track)
#
# tracks = playlist.get_tracks()
# assert len(tracks) == 1
# assert tracks[0].path == track_path
def test_playlist_close(session):