From fec45925c695ac554c854728332d628eee55e351 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sat, 12 Feb 2022 23:18:07 +0000 Subject: [PATCH] Remove redundant functions and tests --- app/models.py | 29 +++++----- test_models.py | 148 ++++++++++++++++++++++++------------------------- 2 files changed, 89 insertions(+), 88 deletions(-) diff --git a/app/models.py b/app/models.py index 47019bc..5d8f419 100644 --- a/app/models.py +++ b/app/models.py @@ -269,21 +269,22 @@ class Playlists(Base): def __repr__(self): return f"" - 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): diff --git a/test_models.py b/test_models.py index d0345b3..3d03871 100644 --- a/test_models.py +++ b/test_models.py @@ -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):