test_file_importer tests pass
This commit is contained in:
parent
d596792375
commit
11400536b5
28
app/ds.py
28
app/ds.py
@ -459,16 +459,17 @@ def track_update(
|
||||
|
||||
with db.Session() as session:
|
||||
track = session.get(Tracks, track_id)
|
||||
|
||||
if not track:
|
||||
raise ApplicationError(f"Can't retrieve Track ({track_id=})")
|
||||
track.path = str(metadata["path"])
|
||||
track.title = str(metadata["title"]),
|
||||
track.artist = str(metadata["artist"]),
|
||||
track.duration = int(metadata["duration"]),
|
||||
track.start_gap = int(metadata["start_gap"]),
|
||||
track.fade_at = int(metadata["fade_at"]),
|
||||
track.silence_at = int(metadata["silence_at"]),
|
||||
track.bitrate = int(metadata["bitrate"]),
|
||||
track.title = str(metadata["title"])
|
||||
track.artist = str(metadata["artist"])
|
||||
track.duration = int(metadata["duration"])
|
||||
track.start_gap = int(metadata["start_gap"])
|
||||
track.fade_at = int(metadata["fade_at"])
|
||||
track.silence_at = int(metadata["silence_at"])
|
||||
track.bitrate = int(metadata["bitrate"])
|
||||
|
||||
session.commit()
|
||||
|
||||
@ -837,7 +838,7 @@ def playlist_save_as_template(playlist_id: int, template_name: str) -> None:
|
||||
|
||||
new_template = playlist_create(template_name, 0, as_template=True)
|
||||
|
||||
playlist_copy(playlist_id, new_template.id)
|
||||
playlist_copy(playlist_id, new_template.playlist_id)
|
||||
|
||||
|
||||
def playlists_templates_all() -> list[PlaylistDTO]:
|
||||
@ -853,14 +854,17 @@ def playlists_template_by_id(playlist_id: int) -> PlaylistDTO | None:
|
||||
Return a list of closed playlists
|
||||
"""
|
||||
|
||||
playlist_list = _playlists_where(
|
||||
Playlists.playlist_id == playlist_id, Playlists.is_template.is_(True)
|
||||
)
|
||||
playlist_list = _playlists_where(Playlists.playlist_id == playlist_id)
|
||||
|
||||
if not playlist_list:
|
||||
return None
|
||||
if len(playlist_list) > 1:
|
||||
raise ApplicationError(f"Duplicate {playlist_id=}")
|
||||
return playlist_list[0]
|
||||
template = playlist_list[0]
|
||||
if template.is_template is False:
|
||||
raise ApplicationError(f"Playlist {playlist_id=} is not a template")
|
||||
|
||||
return template
|
||||
|
||||
|
||||
# @log_call
|
||||
|
||||
@ -142,7 +142,7 @@ class FileImporter:
|
||||
|
||||
# Refresh list of existing tracks as they may have been updated
|
||||
# by previous imports
|
||||
self.existing_tracks = ds.get_all_tracks()
|
||||
self.existing_tracks = ds.tracks_all()
|
||||
|
||||
for infile in [
|
||||
os.path.join(Config.REPLACE_FILES_DEFAULT_SOURCE, f)
|
||||
@ -638,7 +638,7 @@ class DoTrackImport(QThread):
|
||||
# Update databse
|
||||
metadata = get_all_track_metadata(self.destination_track_path)
|
||||
if self.track_id == 0:
|
||||
track_dto = ds.create_track(self.destination_track_path, metadata)
|
||||
track_dto = ds.track_create(metadata)
|
||||
else:
|
||||
track_dto = ds.track_update(
|
||||
self.destination_track_path, self.track_id, metadata
|
||||
|
||||
@ -76,7 +76,6 @@ from dialogs import TrackInsertDialog
|
||||
from file_importer import FileImporter
|
||||
from helpers import ask_yes_no, file_is_unreadable, get_name
|
||||
from log import log, log_call
|
||||
from models import db, Playdates, PlaylistRows, Playlists, Queries, Settings, Tracks
|
||||
from playlistrow import PlaylistRow, TrackSequence
|
||||
from playlistmodel import PlaylistModel, PlaylistProxyModel
|
||||
from playlists import PlaylistTab
|
||||
@ -899,7 +898,7 @@ class QueryDialog(QDialog):
|
||||
querylist_y=self.y(),
|
||||
)
|
||||
for name, value in attributes_to_save.items():
|
||||
ds.set_setting(name, value)
|
||||
ds.setting_set(name, value)
|
||||
|
||||
header = self.table_view.horizontalHeader()
|
||||
if header is None:
|
||||
@ -909,7 +908,7 @@ class QueryDialog(QDialog):
|
||||
return
|
||||
for column_number in range(column_count - 1):
|
||||
attr_name = f"querylist_col_{column_number}_width"
|
||||
ds.set_setting(
|
||||
ds.setting_set(
|
||||
attr_name, self.table_view.columnWidth(column_number)
|
||||
)
|
||||
|
||||
@ -962,10 +961,10 @@ class QueryDialog(QDialog):
|
||||
def set_window_size(self) -> None:
|
||||
"""Set window sizes"""
|
||||
|
||||
x = ds.get_setting("querylist_x") or 100
|
||||
y = ds.get_setting("querylist_y") or 100
|
||||
width = ds.get_setting("querylist_width") or 100
|
||||
height = ds.get_setting("querylist_height") or 100
|
||||
x = ds.setting_get("querylist_x") or 100
|
||||
y = ds.setting_get("querylist_y") or 100
|
||||
width = ds.setting_get("querylist_width") or 100
|
||||
height = ds.setting_get("querylist_height") or 100
|
||||
self.setGeometry(x, y, width, height)
|
||||
|
||||
def set_column_sizes(self) -> None:
|
||||
@ -981,7 +980,7 @@ class QueryDialog(QDialog):
|
||||
# Last column is set to stretch so ignore it here
|
||||
for column_number in range(column_count - 1):
|
||||
attr_name = f"querylist_col_{column_number}_width"
|
||||
width = ds.get_setting(attr_name) or Config.DEFAULT_COLUMN_WIDTH
|
||||
width = ds.setting_get(attr_name) or Config.DEFAULT_COLUMN_WIDTH
|
||||
self.table_view.setColumnWidth(column_number, width)
|
||||
|
||||
|
||||
@ -998,8 +997,8 @@ class SelectPlaylistDialog(QDialog):
|
||||
self.ui.buttonBox.rejected.connect(self.close)
|
||||
self.playlist = None
|
||||
|
||||
width = ds.get_setting("select_playlist_dialog_width") or 800
|
||||
height = ds.get_setting("select_playlist_dialog_height") or 800
|
||||
width = ds.setting_get("select_playlist_dialog_width") or 800
|
||||
height = ds.setting_get("select_playlist_dialog_height") or 800
|
||||
self.resize(width, height)
|
||||
|
||||
for playlist in playlists:
|
||||
@ -1009,8 +1008,8 @@ class SelectPlaylistDialog(QDialog):
|
||||
self.ui.lstPlaylists.addItem(p)
|
||||
|
||||
def __del__(self): # review
|
||||
ds.set_setting("select_playlist_dialog_height", self.height())
|
||||
ds.set_setting("select_playlist_dialog_width", self.width())
|
||||
ds.setting_set("select_playlist_dialog_height", self.height())
|
||||
ds.setting_set("select_playlist_dialog_width", self.width())
|
||||
|
||||
def list_doubleclick(self, entry): # review
|
||||
self.playlist = entry.data(Qt.ItemDataRole.UserRole)
|
||||
@ -1207,7 +1206,7 @@ class Window(QMainWindow):
|
||||
active_tab=self.playlist_section.tabPlaylist.currentIndex(),
|
||||
)
|
||||
for name, value in attributes_to_save.items():
|
||||
ds.set_setting(name, value)
|
||||
ds.setting_set(name, value)
|
||||
|
||||
event.accept()
|
||||
|
||||
@ -1404,13 +1403,13 @@ class Window(QMainWindow):
|
||||
# # # # # # # # # # Playlist management functions # # # # # # # # # #
|
||||
|
||||
# @log_call
|
||||
def _create_playlist(self, name: str, template_id: int) -> Playlists:
|
||||
def _create_playlist(self, name: str, template_id: int) -> PlaylistDTO:
|
||||
"""
|
||||
Create a playlist in the database, populate it from the template
|
||||
if template_id > 0, and return the Playlists object.
|
||||
"""
|
||||
|
||||
return ds.create_playlist(name, template_id)
|
||||
return ds.playlist_create(name, template_id)
|
||||
|
||||
# @log_call
|
||||
def _open_playlist(self, playlist: PlaylistDTO, is_template: bool = False) -> int:
|
||||
@ -1916,7 +1915,7 @@ class Window(QMainWindow):
|
||||
playlist_ids.append(self._open_playlist(playlist))
|
||||
|
||||
# Set active tab
|
||||
value = ds.get_setting("active_tab")
|
||||
value = ds.setting_get("active_tab")
|
||||
if value is not None and value >= 0:
|
||||
self.playlist_section.tabPlaylist.setCurrentIndex(value)
|
||||
|
||||
@ -2416,10 +2415,10 @@ class Window(QMainWindow):
|
||||
def set_main_window_size(self) -> None:
|
||||
"""Set size of window from database"""
|
||||
|
||||
x = ds.get_setting("mainwindow_x") or 100
|
||||
y = ds.get_setting("mainwindow_y") or 100
|
||||
width = ds.get_setting("mainwindow_width") or 100
|
||||
height = ds.get_setting("mainwindow_height") or 100
|
||||
x = ds.setting_get("mainwindow_x") or 100
|
||||
y = ds.setting_get("mainwindow_y") or 100
|
||||
width = ds.setting_get("mainwindow_width") or 100
|
||||
height = ds.setting_get("mainwindow_height") or 100
|
||||
self.setGeometry(x, y, width, height)
|
||||
|
||||
# @log_call
|
||||
|
||||
@ -196,7 +196,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
if self.is_header_row(row):
|
||||
# Check for specific header colouring
|
||||
if plr.row_bg is None:
|
||||
plr.row_bg = ds.get_colour(plr.note)
|
||||
plr.row_bg = ds.notecolours_get_colour(plr.note)
|
||||
if plr.row_bg:
|
||||
return QBrush(QColor(plr.row_bg))
|
||||
else:
|
||||
@ -233,7 +233,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
if column == Col.NOTE.value:
|
||||
if plr.note:
|
||||
if plr.note_bg is None:
|
||||
plr.row_bg = ds.get_colour(plr.note)
|
||||
plr.row_bg = ds.notecolours_get_colour(plr.note)
|
||||
if plr.note_bg:
|
||||
return QBrush(QColor(plr.note_bg))
|
||||
|
||||
@ -395,7 +395,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# Signal that rows will be removed
|
||||
super().beginRemoveRows(QModelIndex(), min(row_group), max(row_group))
|
||||
# Remove rows from data store
|
||||
ds.remove_rows(self.playlist_id, row_group)
|
||||
ds.playlist_remove_rows(self.playlist_id, row_group)
|
||||
# Signal that data store has been updated
|
||||
super().endRemoveRows()
|
||||
|
||||
@ -500,7 +500,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
def _foreground_role(self, row: int, column: int, plr: PlaylistRow) -> QBrush:
|
||||
"""Return header foreground colour or QBrush() if none"""
|
||||
|
||||
plr.row_fg = ds.get_colour(plr.note, foreground=True)
|
||||
plr.row_fg = ds.notecolours_get_colour(plr.note, foreground=True)
|
||||
if plr.row_fg:
|
||||
return QBrush(QColor(plr.row_fg))
|
||||
return QBrush()
|
||||
@ -838,7 +838,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# Notify model going to change
|
||||
self.beginResetModel()
|
||||
# Update database
|
||||
ds.move_rows(from_rows, self.playlist_id, to_row_number)
|
||||
ds.playlist_move_rows(from_rows, self.playlist_id, to_row_number)
|
||||
# Notify model changed
|
||||
self.endResetModel()
|
||||
|
||||
@ -1063,7 +1063,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
track = self.playlist_rows[row_number]
|
||||
metadata = get_all_track_metadata(track.path)
|
||||
_ = ds.update_track(track.path, track.track_id, metadata)
|
||||
_ = ds.track_update(track.path, track.track_id, metadata)
|
||||
|
||||
roles = [
|
||||
Qt.ItemDataRole.BackgroundRole,
|
||||
@ -1103,7 +1103,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
):
|
||||
return
|
||||
|
||||
ds.remove_comments(self.playlist_id, row_numbers)
|
||||
ds.playlist_remove_comments(self.playlist_id, row_numbers)
|
||||
|
||||
# only invalidate required roles
|
||||
roles = [
|
||||
@ -1446,7 +1446,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
if not track_id:
|
||||
return ""
|
||||
|
||||
return ds.get_last_played_dates(track_id)
|
||||
return ds.playdates_get_last(track_id)
|
||||
|
||||
# @log_call
|
||||
def update_or_insert(self, track_id: int, row_number: int) -> None:
|
||||
|
||||
@ -1073,7 +1073,7 @@ class PlaylistTab(QTableView):
|
||||
# Last column is set to stretch so ignore it here
|
||||
for column_number in range(header.count() - 1):
|
||||
attr_name = f"playlist_col_{column_number}_width"
|
||||
value = ds.get_setting(attr_name)
|
||||
value = ds.setting_get(attr_name)
|
||||
if value is not None:
|
||||
self.setColumnWidth(column_number, value)
|
||||
else:
|
||||
|
||||
@ -79,7 +79,8 @@ class MyTestCase(unittest.TestCase):
|
||||
"""Runs after each test"""
|
||||
self.widget.close() # Close UI to prevent side effects
|
||||
|
||||
def wait_for_workers(self, timeout: int = 10000):
|
||||
# def wait_for_workers(self, timeout: int = 10000):
|
||||
def wait_for_workers(self, timeout: int = 1000000):
|
||||
"""
|
||||
Let import threads workers run to completion
|
||||
"""
|
||||
@ -171,7 +172,7 @@ class MyTestCase(unittest.TestCase):
|
||||
self.wait_for_workers()
|
||||
|
||||
# Check track was imported
|
||||
tracks = ds.get_all_tracks()
|
||||
tracks = ds.tracks_all()
|
||||
assert len(tracks) == 1
|
||||
track = tracks[0]
|
||||
assert track.title == "I'm So Afraid"
|
||||
@ -216,7 +217,7 @@ class MyTestCase(unittest.TestCase):
|
||||
self.wait_for_workers()
|
||||
|
||||
# Check track was imported
|
||||
tracks = ds.get_all_tracks()
|
||||
tracks = ds.tracks_all()
|
||||
assert len(tracks) == 2
|
||||
track = tracks[1]
|
||||
assert track.title == "The Lovecats"
|
||||
@ -268,7 +269,7 @@ class MyTestCase(unittest.TestCase):
|
||||
self.wait_for_workers()
|
||||
|
||||
# Check track was imported
|
||||
tracks = ds.get_all_tracks()
|
||||
tracks = ds.tracks_all()
|
||||
assert len(tracks) == 2
|
||||
track = tracks[1]
|
||||
assert track.title == "The Lovecats"
|
||||
@ -397,7 +398,7 @@ class MyTestCase(unittest.TestCase):
|
||||
assert result[0] == new_destination # Validate return value
|
||||
|
||||
# Check track was imported
|
||||
tracks = ds.get_all_tracks()
|
||||
tracks = ds.tracks_all()
|
||||
track = tracks[2]
|
||||
assert track.title == "The Lovecats"
|
||||
assert track.artist == "The Cure"
|
||||
@ -407,8 +408,8 @@ class MyTestCase(unittest.TestCase):
|
||||
assert os.listdir(self.import_source) == []
|
||||
|
||||
# Remove file so as not to interfere with later tests
|
||||
ds.delete(track)
|
||||
tracks = ds.get_all_tracks()
|
||||
ds.track_delete(track.track_id)
|
||||
tracks = ds.tracks_all()
|
||||
assert len(tracks) == 2
|
||||
|
||||
os.unlink(new_destination)
|
||||
@ -463,7 +464,7 @@ class MyTestCase(unittest.TestCase):
|
||||
self.wait_for_workers()
|
||||
|
||||
# Check track was imported
|
||||
tracks = ds.get_all_tracks()
|
||||
tracks = ds.tracks_all()
|
||||
assert len(tracks) == 2
|
||||
track = tracks[1]
|
||||
assert track.title == "The Lovecats xyz"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user