def test_004_update_playlist(self): cursor = self.conn.cursor() PlaylistTable.get_all(cursor, "name") playlists = cursor.fetchall() playlist = PlaylistTable.get(cursor, playlists[0].id) playlist.name = "Test Playlist" filenames = [ self.get_filename(self.kilas, 0), self.get_filename(self.edge, 0), ] playlist.filenames = filenames PlaylistTable.update(cursor, playlist.serialize()) rating = Rating("playlist", playlist.id, 5) PlaylistTable.set_rating(cursor, rating) playlist = PlaylistTable.get(cursor, playlists[0].id) self.assertEqual(playlist.name, "Test Playlist") self.assertEqual(playlist.length, 2) entries = PlaylistEntryTable.get_entries(cursor, playlists[0].id) self.assertEqual(len(entries), 2) self.assertEqual(entries[0].filename, filenames[0]) self.assertEqual(playlist.rating, 5) cursor.close()
def test_008_search(self): cursor = self.conn.cursor() directory = self.directory_service.get_directory( "root/Edge of the Sun") self.directory_service.aggregate(directory) recording = self.directory_service.create_recording( directory, directory.text[0]) recording.official = True LibrarySearchView.create_recording(cursor, recording.serialize()) album_rating = Rating("recording-rating", recording.id, 5) RecordingTable.set_rating(cursor, album_rating) artist_search = deepcopy(self.default_query) artist_search["match"].append({"artist": "Built To Spill"}) RecordingSummaryView.search(cursor, artist_search) artist_result = cursor.fetchall() self.assertEqual(len(artist_result), 1) title_search = deepcopy(self.default_query) title_search["match"].append({"recording": "Keep It Like A Secret"}) RecordingSummaryView.search(cursor, title_search) title_result = cursor.fetchall() self.assertEqual(len(title_result), 1) track_search = deepcopy(self.default_query) track_search["match"].append({"title": "Carry the Zero"}) RecordingSummaryView.search(cursor, track_search) track_result = cursor.fetchall() self.assertEqual(len(track_result), 1) rating_search = deepcopy(self.default_query) rating_search["match"].append({"recording_rating": 5}) RecordingSummaryView.search(cursor, rating_search) rating_result = cursor.fetchall() self.assertEqual(len(rating_result), 1) exclude_artist = deepcopy(self.default_query) exclude_artist["exclude"].append({"artist": "Calexico"}) RecordingSummaryView.search(cursor, exclude_artist) exclude_artist_result = cursor.fetchall() self.assertEqual(len(exclude_artist_result), 1) rating_search = deepcopy(self.default_query) rating_search["exclude"].append({"recording_rating": 3}) RecordingSummaryView.search(cursor, rating_search) rating_result = cursor.fetchall() self.assertEqual(len(rating_result), 1) rating_search = deepcopy(self.default_query) rating_search["unrated"] = True RecordingSummaryView.search(cursor, rating_search) rating_result = cursor.fetchall() self.assertEqual(len(rating_result), 2) cursor.close()
def test_008_search_tracks(self): cursor = self.conn.cursor() title_search = deepcopy(self.default_track_query) title_search["match"].append({"title": "The Plan"}) PlaylistTrackView.search(cursor, title_search) title_results = cursor.fetchall() self.assertEqual(len(title_results), 1) recording_search = deepcopy(self.default_track_query) recording_search["match"].append( {"recording": "Keep It Like a Secret"}) PlaylistTrackView.search(cursor, recording_search) recording_results = cursor.fetchall() self.assertEqual(len(recording_results), 3) for track in recording_results: TrackTable.set_rating(cursor, Rating("track", track.filename, 5)) rating_search = deepcopy(self.default_track_query) rating_search["match"].append({"rating": 5}) PlaylistTrackView.search(cursor, rating_search) rating_results = cursor.fetchall() self.assertEqual(len(rating_results), 3) recording_id = recording_results[0].recording_id recording = LibrarySearchView.get_recording(cursor, recording_id) recording.official = True LibrarySearchView.update_recording(cursor, recording.serialize()) official_search = deepcopy(self.default_track_query) official_search["nonofficial"] = False PlaylistTrackView.search(cursor, official_search) official_results = cursor.fetchall() self.assertEqual(len(official_results), 3) unrated_search = deepcopy(self.default_track_query) unrated_search["unrated"] = True PlaylistTrackView.search(cursor, unrated_search) unrated_results = cursor.fetchall() self.assertEqual(len(unrated_results), 6) artist_search = deepcopy(self.default_track_query) artist_search["match"].append({"artist": "Built To Spill"}) PlaylistTrackView.search(cursor, artist_search) artist_results = cursor.fetchall() self.assertEqual(len(artist_results), 3) exclude_search = deepcopy(self.default_track_query) exclude_search["exclude"].append({"artist": "Built To Spill"}) PlaylistTrackView.search(cursor, exclude_search) exclude_results = cursor.fetchall() self.assertEqual(len(exclude_results), 6) cursor.close()
def test_002_update_podcast(self): cursor = self.conn.cursor() self.podcasts[0]["website"] = "https://www.lawfareblog.com/topic/lawfare-podcast" PodcastTable.update(cursor, self.podcasts[0]) rating = Rating("podcast", self.podcasts[1]["id"], 5) PodcastTable.set_rating(cursor, rating) PodcastTable.get_all(cursor) podcasts = [ row for row in cursor ] self.assertEqual(podcasts[0].website, "https://www.lawfareblog.com/topic/lawfare-podcast") self.assertEqual(podcasts[1].rating, 5) cursor.close()
def test_005_update_recording(self): cursor = self.conn.cursor() RecordingSummaryView.get_all(cursor) recording_id = cursor.fetchall()[0].id recording = LibrarySearchView.get_recording(cursor, recording_id) for track in recording.tracks: track.artist[0] = "Built To Spill" track.genre.append("Rock") LibrarySearchView.update_recording(cursor, recording.serialize()) album_rating = Rating("recording-rating", recording_id, 5) track_rating = Rating("track", recording.tracks[0].filename, 5) RecordingTable.set_rating(cursor, album_rating) TrackTable.set_rating(cursor, track_rating) updated = LibrarySearchView.get_recording(cursor, recording_id) self.assertEqual(updated.tracks[0].artist[0], "Built To Spill") self.assertEqual(updated.rating, 5) self.assertEqual(updated.tracks[0].rating, 5) cursor.close()
def test_002_update_station(self): cursor = self.conn.cursor() self.stations[0]["website"] = "https://weta.org/fm" StationTable.update(cursor, self.stations[0]) rating = Rating("station", self.stations[1]["id"], 5) StationTable.set_rating(cursor, rating) StationTable.get_all(cursor) stations = [row for row in cursor] self.assertEqual(stations[0].website, "https://weta.org/fm") self.assertEqual(stations[1].rating, 5) cursor.close()
def test_006_search_playlists(self): cursor = self.conn.cursor() playlist_id = PlaylistTable.create(cursor) name_search = deepcopy(self.default_playlist_query) name_search["match"].append({"name": "Untitled Playlist"}) PlaylistTable.search(cursor, name_search) name_result = cursor.fetchall() self.assertEqual(len(name_result), 1) self.assertEqual(name_result[0].name, "Untitled Playlist") rating = Rating("playlist", playlist_id, 5) PlaylistTable.set_rating(cursor, rating) rating_search = deepcopy(self.default_playlist_query) rating_search["match"].append({"rating": 5}) PlaylistTable.search(cursor, rating_search) rating_result = cursor.fetchall() self.assertEqual(len(rating_result), 2) cursor.close()