diff --git a/cozy/extensions/__init__.py b/cozy/extensions/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/cozy/extensions/is_same_book.py b/cozy/extensions/is_same_book.py deleted file mode 100644 index 80829da5..00000000 --- a/cozy/extensions/is_same_book.py +++ /dev/null @@ -1,2 +0,0 @@ -def is_same_book(book_a: str, book_b: str) -> bool: - return book_a.casefold() == book_b.casefold() diff --git a/cozy/extensions/set.py b/cozy/extensions/set.py deleted file mode 100644 index 23711c39..00000000 --- a/cozy/extensions/set.py +++ /dev/null @@ -1,5 +0,0 @@ -import re - - -def split_strings_to_set(set_to_split: set[str]) -> set[str]: - return {entry.strip() for item in set_to_split for entry in re.split(",|;|/|&", item)} diff --git a/cozy/media/player.py b/cozy/media/player.py index 0e26647b..8b13023d 100644 --- a/cozy/media/player.py +++ b/cozy/media/player.py @@ -479,6 +479,12 @@ def forward(self): if state == Gst.State.PLAYING: self._gst_player.play() + def volume_up(self): + self.volume = min(1.0, self.volume + 0.1) + + def volume_down(self): + self.volume = max(0, self.volume - 0.1) + def destroy(self): self._gst_player.stop() @@ -607,6 +613,30 @@ def _next_chapter(self): chapter.position = chapter.start_position self.play_pause_chapter(self._book, chapter) + def _previous_chapter(self): + if not self._book: + log.error("Cannot play previous chapter because no book reference is stored.") + reporter.error( + "player", "Cannot play previous chapter because no book reference is stored." + ) + return + + index_current_chapter = self._book.chapters.index(self._book.current_chapter) + self._book.current_chapter.position = self._book.current_chapter.start_position + + if index_current_chapter - 1 < 0: + log.info("Book reached start, cannot rewind further.") + chapter = self._book.chapters[0] + chapter.position = chapter.start_position + + self._load_chapter(chapter) + self.pause() + self._emit_tick() + else: + chapter = self._book.chapters[index_current_chapter - 1] + chapter.position = chapter.start_position + self.play_pause_chapter(self._book, chapter) + def _on_importer_event(self, event: str, message): if event == "scan" and message == ScanStatus.SUCCESS: log.info("Reloading current book") diff --git a/cozy/model/database_importer.py b/cozy/model/database_importer.py index fbc9ce77..f15bf403 100644 --- a/cozy/model/database_importer.py +++ b/cozy/model/database_importer.py @@ -7,13 +7,16 @@ from cozy.db.file import File from cozy.db.track import Track from cozy.db.track_to_file import TrackToFile -from cozy.extensions.is_same_book import is_same_book from cozy.media.media_file import MediaFile from cozy.model.book import Book, BookIsEmpty log = logging.getLogger("db_importer") +def is_same_book(book_a: str, book_b: str) -> bool: + return book_a.casefold() == book_b.casefold() + + class TrackInsertRequest: track_data: object file: File diff --git a/cozy/model/library.py b/cozy/model/library.py index 01815d12..0bd3afae 100644 --- a/cozy/model/library.py +++ b/cozy/model/library.py @@ -1,4 +1,5 @@ import logging +import re from typing import Optional import inject @@ -8,7 +9,6 @@ from cozy.architecture.profiler import timing from cozy.db.book import Book as BookModel from cozy.db.file import File -from cozy.extensions.set import split_strings_to_set from cozy.model.book import Book, BookIsEmpty from cozy.model.chapter import Chapter from cozy.model.settings import Settings @@ -16,6 +16,10 @@ log = logging.getLogger("ui") +def split_strings_to_set(set_to_split: set[str]) -> set[str]: + return {entry.strip() for item in set_to_split for entry in re.split(",|;|/|&", item)} + + class Library(EventSender): _db = cache = inject.attr(SqliteDatabase) _settings: Settings = inject.attr(Settings) diff --git a/cozy/ui/about_window.py b/cozy/ui/about_window.py index 09da27d9..bc6be071 100644 --- a/cozy/ui/about_window.py +++ b/cozy/ui/about_window.py @@ -22,6 +22,8 @@ def __init__(self, version: str) -> None: self.set_extra_credits() + self.connect = self._window.connect + def get_contributors(self) -> list[str]: authors_file = Gio.resources_lookup_data( "/com/github/geigi/cozy/appdata/authors.list", Gio.ResourceLookupFlags.NONE diff --git a/cozy/ui/file_not_found_dialog.py b/cozy/ui/file_not_found_dialog.py index bd746217..13539693 100644 --- a/cozy/ui/file_not_found_dialog.py +++ b/cozy/ui/file_not_found_dialog.py @@ -15,7 +15,7 @@ def __init__(self, chapter: Chapter): self.missing_chapter = chapter super().__init__( - heading=_("File Not Found"), + heading=_("File not Found"), body=_("This file could not be found. Do you want to locate it manually?"), default_response="locate", close_response="cancel", diff --git a/cozy/ui/main_view.py b/cozy/ui/main_view.py index 8a0b0811..d5ca71c4 100644 --- a/cozy/ui/main_view.py +++ b/cozy/ui/main_view.py @@ -20,6 +20,8 @@ from cozy.ui.library_view import LibraryView from cozy.ui.preferences_window import PreferencesWindow from cozy.ui.widgets.first_import_button import FirstImportButton +from cozy.view_model.playback_control_view_model import PlaybackControlViewModel +from cozy.view_model.playback_speed_view_model import PlaybackSpeedViewModel from cozy.view_model.storages_view_model import StoragesViewModel log = logging.getLogger("ui") @@ -36,6 +38,8 @@ class CozyUI(EventSender, metaclass=Singleton): _files: Files = inject.attr(Files) _player: Player = inject.attr(Player) _storages_view_model: StoragesViewModel = inject.attr(StoragesViewModel) + _playback_control_view_model: PlaybackControlViewModel = inject.attr(PlaybackControlViewModel) + _playback_speed_view_model: PlaybackSpeedViewModel = inject.attr(PlaybackSpeedViewModel) _library_view: LibraryView @@ -44,6 +48,8 @@ def __init__(self, app, version): self.app = app self.version = version + self._actions_to_disable = [] + def activate(self, library_view: LibraryView): self.__init_window() self.__init_actions() @@ -55,7 +61,9 @@ def activate(self, library_view: LibraryView): self.check_for_tracks() def startup(self): - self.window_builder = Gtk.Builder.new_from_resource("/com/github/geigi/cozy/ui/main_window.ui") + self.window_builder = Gtk.Builder.new_from_resource( + "/com/github/geigi/cozy/ui/main_window.ui" + ) self.window: Adw.ApplicationWindow = self.window_builder.get_object("app_window") def __init_window(self): @@ -90,15 +98,17 @@ def __init_actions(self): """ Init all app actions. """ - self.create_action("about", self.show_about_window, ["F1"]) + self.create_action("about", self.show_about_window, ["F1"], global_shorcut=True) self.create_action("reset_book", self.reset_book) self.create_action("remove_book", self.remove_book) + self.create_action("mark_book_as_read", self.mark_book_as_read) self.create_action("jump_to_book_folder", self.jump_to_book_folder) - self.create_action("prefs", self.show_preferences_window, ["comma"]) - self.create_action("quit", self.quit, ["q", "w"]) + + self.create_action("prefs", self.show_preferences_window, ["comma"], global_shorcut=True) + self.create_action("quit", self.quit, ["q", "w"], global_shorcut=True) + self.scan_action = self.create_action("scan", self.scan) - self.play_pause_action = self.create_action("play_pause", self.play_pause, ["space"]) self.hide_offline_action = Gio.SimpleAction.new_stateful( "hide_offline", None, GLib.Variant.new_boolean(self.application_settings.hide_offline) @@ -106,6 +116,10 @@ def __init_actions(self): self.hide_offline_action.connect("change-state", self.__on_hide_offline) self.app.add_action(self.hide_offline_action) + def set_hotkeys_enabled(self, enabled: bool) -> None: + for action in self._actions_to_disable: + action.set_enabled(enabled) + def __init_components(self): path = self._settings.default_location.path if self._settings.storage_locations else None self.import_button = FirstImportButton(self._set_audiobook_path, path) @@ -121,6 +135,8 @@ def create_action( name: str, callback: Callable[[Gio.SimpleAction, None], None], shortcuts: list[str] | None = None, + *, + global_shorcut: bool = False, ) -> Gio.SimpleAction: action = Gio.SimpleAction.new(name, None) action.connect("activate", callback) @@ -129,6 +145,9 @@ def create_action( if shortcuts: self.app.set_accels_for_action(f"app.{name}", shortcuts) + if not global_shorcut: + self._actions_to_disable.append(action) + return action def refresh_library_filters(self): @@ -161,14 +180,21 @@ def quit(self, action, parameter): self.on_close(None) self.app.quit() + def _dialog_close_callback(self, dialog): + dialog.disconnect_by_func(self._dialog_close_callback) + self.set_hotkeys_enabled(True) + def show_about_window(self, *_): - AboutWindow(self.version).present(self.window) + self.set_hotkeys_enabled(False) + about = AboutWindow(self.version) + about.connect("closed", self._dialog_close_callback) + about.present(self.window) def show_preferences_window(self, *_): - PreferencesWindow().present(self.window) - - def play_pause(self, *_): - self._player.play_pause() + self.set_hotkeys_enabled(False) + prefs = PreferencesWindow() + prefs.connect("closed", self._dialog_close_callback) + prefs.present(self.window) def block_ui_buttons(self, block, scan=False): """ @@ -177,7 +203,6 @@ def block_ui_buttons(self, block, scan=False): """ sensitive = not block try: - self.play_pause_action.set_enabled(sensitive) if scan: self.scan_action.set_enabled(sensitive) self.hide_offline_action.set_enabled(sensitive) @@ -189,7 +214,10 @@ def switch_to_playing(self): Switch the UI state back to playing. This enables all UI functionality for the user. """ - if self.navigation_view.props.visible_page != "book_overview" and self.main_stack.props.visible_child_name != "welcome": + if ( + self.navigation_view.props.visible_page != "book_overview" + and self.main_stack.props.visible_child_name != "welcome" + ): self.navigation_view.pop_to_tag("main") if self._player.loaded_book: @@ -289,4 +317,3 @@ def _save_window_size(self, *_): self.application_settings.window_width = width self.application_settings.window_height = height self.application_settings.window_maximize = self.window.is_maximized() - diff --git a/cozy/ui/media_controller.py b/cozy/ui/media_controller.py index b609d60d..c4b93170 100644 --- a/cozy/ui/media_controller.py +++ b/cozy/ui/media_controller.py @@ -9,6 +9,7 @@ from cozy.ui.widgets.seek_bar import SeekBar from cozy.ui.widgets.sleep_timer import SleepTimer from cozy.view_model.playback_control_view_model import PlaybackControlViewModel +from cozy.view_model.playback_speed_view_model import PlaybackSpeedViewModel log = logging.getLogger("MediaController") @@ -57,9 +58,8 @@ def __init__(self, main_window_builder: Gtk.Builder): ] ) - self._playback_control_view_model: PlaybackControlViewModel = inject.instance( - PlaybackControlViewModel - ) + self._playback_control_view_model = inject.instance(PlaybackControlViewModel) + self._playback_speed_view_model = inject.instance(PlaybackSpeedViewModel) self._artwork_cache: ArtworkCache = inject.instance(ArtworkCache) self._connect_view_model() self._connect_widgets() @@ -69,6 +69,7 @@ def __init__(self, main_window_builder: Gtk.Builder): self._on_length_changed() self._on_position_changed() self._on_volume_changed() + self._setup_shortcuts() def _connect_view_model(self): self._playback_control_view_model.bind_to("book", self._on_book_changed) @@ -103,6 +104,22 @@ def _set_cover_image(self, book: Book): self.cover_img.set_from_icon_name("book-open-variant-symbolic") self.cover_img.props.pixel_size = COVER_SIZE + @inject.param("main_window", "MainWindow") + def _setup_shortcuts(self, main_window): + main_window.create_action("play_pause", self._play_clicked, ["space"]) + main_window.create_action("seek_rewind", self._rewind_clicked, ["Left"]) + main_window.create_action("seek_forward", self._forward_clicked, ["Right"]) + + main_window.create_action("volume_up", self._volume_up, ["Up"]) + main_window.create_action("volume_down", self._volume_down, ["Down"]) + + main_window.create_action("speed_up", self._speed_up, ["plus", "KP_Add", "Up"]) + main_window.create_action("speed_down", self._speed_down, ["minus", "KP_Subtract", "Down"]) + main_window.create_action("speed_reset", self._speed_reset, ["equal"]) + + main_window.create_action("prev_chapter", self._prev_chapter, ["Page_Down", "Left"]) + main_window.create_action("next_chapter", self._next_chapter, ["Page_Up", "Right"]) + def _on_book_changed(self) -> None: book = self._playback_control_view_model.book self._set_book(book) @@ -145,6 +162,27 @@ def _on_lock_ui_changed(self): def _on_volume_changed(self): self.volume_button.set_value(self._playback_control_view_model.volume) + def _volume_up(self, *_): + self._playback_control_view_model.volume_up() + + def _volume_down(self, *_): + self._playback_control_view_model.volume_down() + + def _speed_up(self, *_): + self._playback_speed_view_model.speed_up() + + def _speed_down(self, *_): + self._playback_speed_view_model.speed_down() + + def _speed_reset(self, *_): + self._playback_speed_view_model.speed_reset() + + def _next_chapter(self, *_): + self._playback_control_view_model.next_chapter() + + def _prev_chapter(self, *_): + self._playback_control_view_model.previous_chapter() + def _play_clicked(self, *_): self._playback_control_view_model.play_pause() diff --git a/cozy/ui/search_view.py b/cozy/ui/search_view.py index eba2d72d..d47731b8 100644 --- a/cozy/ui/search_view.py +++ b/cozy/ui/search_view.py @@ -54,12 +54,12 @@ def __init__(self, main_window_builder: Gtk.Builder, headerbar: Headerbar) -> No def open(self, *_) -> None: self.library_stack.set_visible_child(self) self.search_bar.set_search_mode(True) - self.main_view.play_pause_action.set_enabled(False) + self.main_view.set_hotkeys_enabled(False) def close(self) -> None: self.library_stack.set_visible_child(self.split_view) self.search_bar.set_search_mode(False) - self.main_view.play_pause_action.set_enabled(True) + self.main_view.set_hotkeys_enabled(True) def on_state_changed(self, widget: Gtk.Widget, param) -> None: if widget.get_property(param.name): diff --git a/cozy/ui/widgets/book_card.py b/cozy/ui/widgets/book_card.py index cfcb75ca..92fc0438 100644 --- a/cozy/ui/widgets/book_card.py +++ b/cozy/ui/widgets/book_card.py @@ -105,12 +105,8 @@ def _install_event_controllers(self): long_press_gesture = Gtk.GestureLongPress() long_press_gesture.connect("pressed", self._on_long_tap) - key_event_controller = Gtk.EventControllerKey() - key_event_controller.connect("key-pressed", self._on_key_press_event) - self.add_controller(hover_controller) self.add_controller(long_press_gesture) - self.add_controller(key_event_controller) def set_playing(self, is_playing): self.play_button.set_playing(is_playing) @@ -160,7 +156,3 @@ def _on_long_tap(self, gesture: Gtk.Gesture, *_): device = gesture.get_device() if device and device.get_source() == Gdk.InputSource.TOUCHSCREEN: self.menu_button.emit("activate") - - def _on_key_press_event(self, controller, keyval, *_): - if keyval == Gdk.KEY_Return: - self.emit("open-book-overview", self.book) diff --git a/cozy/ui/widgets/seek_bar.py b/cozy/ui/widgets/seek_bar.py index 18303b68..78a48376 100644 --- a/cozy/ui/widgets/seek_bar.py +++ b/cozy/ui/widgets/seek_bar.py @@ -1,4 +1,4 @@ -from gi.repository import Gdk, GObject, Gtk +from gi.repository import GObject, Gtk from cozy.control.time_format import ns_to_time @@ -37,10 +37,6 @@ def __init__(self, **kwargs): click_gesture.connect("pressed", self._on_progress_scale_press) click_gesture.connect("released", self._on_progress_scale_release) - keyboard_controller = Gtk.EventControllerKey() - keyboard_controller.connect("key-pressed", self._on_progress_key_pressed) - self.progress_scale.add_controller(keyboard_controller) - @GObject.Signal(arg_types=(object,)) def position_changed(self, *_): ... @@ -90,11 +86,5 @@ def _on_progress_scale_release(self, *_): value = self.progress_scale.get_value() self.emit("position-changed", value) - def _on_progress_key_pressed(self, _, event, *__): - if event in {Gdk.KEY_Up, Gdk.KEY_Left}: - self.emit("rewind") - elif event in {Gdk.KEY_Down, Gdk.KEY_Right}: - self.emit("forward") - def _on_progress_scale_press(self, *_): self._progress_scale_pressed = True diff --git a/cozy/view_model/library_view_model.py b/cozy/view_model/library_view_model.py index 9ffc9a2d..4018af84 100644 --- a/cozy/view_model/library_view_model.py +++ b/cozy/view_model/library_view_model.py @@ -13,7 +13,8 @@ from cozy.media.importer import Importer, ScanStatus from cozy.media.player import Player from cozy.model.book import Book -from cozy.model.library import Library +from cozy.model.library import Library, split_strings_to_set +from cozy.open_view import OpenView from cozy.report import reporter from cozy.settings import ApplicationSettings from cozy.ui.import_failed_dialog import ImportFailedDialog diff --git a/cozy/view_model/playback_control_view_model.py b/cozy/view_model/playback_control_view_model.py index 857705ad..a46b5085 100644 --- a/cozy/view_model/playback_control_view_model.py +++ b/cozy/view_model/playback_control_view_model.py @@ -94,9 +94,25 @@ def play_pause(self): def rewind(self): self._player.rewind() + self._player._emit_tick() def forward(self): self._player.forward() + self._player._emit_tick() + + def next_chapter(self): + self._player._next_chapter() + + def previous_chapter(self): + self._player._previous_chapter() + + def volume_up(self): + self._player.volume_up() + self._notify("volume") + + def volume_down(self): + self._player.volume_down() + self._notify("volume") def open_book_detail(self): if self.book: diff --git a/cozy/view_model/playback_speed_view_model.py b/cozy/view_model/playback_speed_view_model.py index adf4b3dd..cc8d4484 100644 --- a/cozy/view_model/playback_speed_view_model.py +++ b/cozy/view_model/playback_speed_view_model.py @@ -34,3 +34,15 @@ def _on_player_event(self, event: str, message): if event == "chapter-changed" and message: self._book = message self._notify("playback_speed") + + def speed_up(self): + self.playback_speed = min(self.playback_speed + 0.1, 3.5) + self._notify("playback_speed") + + def speed_down(self): + self.playback_speed = max(self.playback_speed - 0.1, 0.5) + self._notify("playback_speed") + + def speed_reset(self): + self.playback_speed = 1.0 + self._notify("playback_speed") diff --git a/cozy/view_model/search_view_model.py b/cozy/view_model/search_view_model.py index 1c7b04f0..f99fb7f9 100644 --- a/cozy/view_model/search_view_model.py +++ b/cozy/view_model/search_view_model.py @@ -6,12 +6,21 @@ from cozy.architecture.event_sender import EventSender from cozy.architecture.observable import Observable from cozy.control.filesystem_monitor import FilesystemMonitor + +<<<<<<< HEAD from cozy.enums import OpenView from cozy.extensions.set import split_strings_to_set from cozy.model.book import Book from cozy.model.library import Library from cozy.settings import ApplicationSettings +======= +from cozy.model.book import Book +from cozy.model.library import Library, split_strings_to_set +from cozy.open_view import OpenView + +>>>>>>> master + class SearchViewModel(Observable, EventSender): _fs_monitor: FilesystemMonitor = inject.attr("FilesystemMonitor") diff --git a/data/ui/headerbar.blp b/data/ui/headerbar.blp index afc21dd5..ee9bb718 100644 --- a/data/ui/headerbar.blp +++ b/data/ui/headerbar.blp @@ -22,6 +22,7 @@ template $Headerbar: Box { tooltip-text: _("Options"); menu-model: primary_menu; icon-name: 'open-menu-symbolic'; + primary: true; accessibility { label: _("Open the options popover"); diff --git a/data/ui/main_window.blp b/data/ui/main_window.blp index 540a2a36..f4765d94 100644 --- a/data/ui/main_window.blp +++ b/data/ui/main_window.blp @@ -25,7 +25,7 @@ Adw.ApplicationWindow app_window { Adw.StatusPage { icon-name: 'library-symbolic'; - title: _("Drop Audio Books Here to Add Them to Your Library"); + title: _("Drop audiobooks here to add them to your library"); styles [ "drag-overlay-status-page", @@ -178,7 +178,7 @@ Adw.ApplicationWindow app_window { child: Adw.StatusPage { icon-name: 'library-symbolic'; - title: _("No Recent Books Yet"); + title: _("No Recent Books yet"); description: _("Explore your library by switching to the Author or Reader view"); }; } @@ -235,8 +235,8 @@ Adw.ApplicationWindow app_window { content: Adw.StatusPage welcome_status_page { icon-name: 'com.github.geigi.cozy'; - title: _("Let's get cozy"); - description: _("Select a Folder, or Drag Audiobooks Here to Add Them to Your Library"); + title: _("Let's Get Cozy"); + description: _("Select a folder, or drop audiobooks here to add them to your library"); }; }; } diff --git a/test/conftest.py b/test/conftest.py index 2aa48d09..0b4ef9ea 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,9 +1,8 @@ import json import os -import pytest - import gi +import pytest gi.require_version('Gtk', '4.0') gi.require_version('Gdk', '4.0') @@ -26,12 +25,12 @@ def chunks(lst, n): @pytest.fixture(scope="function") def peewee_database(): - from cozy.db.track import Track from cozy.db.book import Book + from cozy.db.file import File from cozy.db.settings import Settings - from cozy.db.storage_blacklist import StorageBlackList from cozy.db.storage import Storage - from cozy.db.file import File + from cozy.db.storage_blacklist import StorageBlackList + from cozy.db.track import Track from cozy.db.track_to_file import TrackToFile db_path, models, test_db = prepare_db() @@ -77,8 +76,8 @@ def peewee_database(): @pytest.fixture(scope="function") def peewee_database_storage(): - from cozy.db.storage import Storage from cozy.db.settings import Settings + from cozy.db.storage import Storage from cozy.db.storage_blacklist import StorageBlackList db_path, models, test_db = prepare_db() @@ -106,16 +105,17 @@ def teardown_db(db_path, models, test_db): def prepare_db(): from playhouse.pool import PooledSqliteDatabase + from cozy.db.artwork_cache import ArtworkCache from cozy.db.book import Book + from cozy.db.collation import collate_natural + from cozy.db.file import File from cozy.db.offline_cache import OfflineCache from cozy.db.settings import Settings from cozy.db.storage import Storage from cozy.db.storage_blacklist import StorageBlackList from cozy.db.track import Track - from cozy.db.file import File from cozy.db.track_to_file import TrackToFile - from cozy.db.collation import collate_natural models = [Track, Book, File, TrackToFile, Settings, ArtworkCache, Storage, StorageBlackList, OfflineCache] diff --git a/test/cozy/extensions/__init__.py b/test/cozy/extensions/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/cozy/extensions/test_is_same_book.py b/test/cozy/extensions/test_is_same_book.py deleted file mode 100644 index 3897df6c..00000000 --- a/test/cozy/extensions/test_is_same_book.py +++ /dev/null @@ -1,33 +0,0 @@ -from cozy.extensions.is_same_book import is_same_book - - -def test_books_with_identical_spelling_are_same(): - book_a = "Dummy Book Title" - book_b = "Dummy Book Title" - result = is_same_book(book_a, book_b) - - assert result is True - - -def test_books_with_inconsistent_spelling_are_same(): - book_a = "Dummy Book Title" - book_b = "Dummy book title" - result = is_same_book(book_a, book_b) - - assert result is True - - -def test_different_books_are_not_same(): - book_a = "First Dummy Book Title" - book_b = "Second Dummy Book Title" - result = is_same_book(book_a, book_b) - - assert result is False - - -def test_books_without_title_are_not_same(): - book_a = "First Dummy Book Title" - book_b = "" - result = is_same_book(book_a, book_b) - - assert result is False diff --git a/test/cozy/media/test_importer.py b/test/cozy/media/test_importer.py index 054cc583..692a568d 100644 --- a/test/cozy/media/test_importer.py +++ b/test/cozy/media/test_importer.py @@ -20,8 +20,8 @@ def setup_inject(peewee_database_storage): def test_external_paths_are_excluded_when_offline(mocker): - from cozy.media.importer import Importer from cozy.db.storage import Storage + from cozy.media.importer import Importer mocker.patch("os.path.exists", return_value=True) mocker.patch("cozy.control.filesystem_monitor.FilesystemMonitor.is_storage_online", autospec=True, @@ -48,8 +48,8 @@ def test_paths_not_existing_are_excluded(mocker): def test_all_existing_paths_are_included(mocker): - from cozy.media.importer import Importer from cozy.db.storage import Storage + from cozy.media.importer import Importer mocker.patch("os.path.exists", return_value=True) diff --git a/test/cozy/media/test_player.py b/test/cozy/media/test_player.py index f9d1c8d5..85b0acfa 100644 --- a/test/cozy/media/test_player.py +++ b/test/cozy/media/test_player.py @@ -4,10 +4,10 @@ import pytest from peewee import SqliteDatabase -from cozy.settings import ApplicationSettings from cozy.media.player import GstPlayer from cozy.model.library import Library from cozy.model.settings import Settings +from cozy.settings import ApplicationSettings @pytest.fixture(autouse=True) diff --git a/test/cozy/model/storage_block_list.py b/test/cozy/model/storage_block_list.py index 0ccf3f60..e4e3abdc 100644 --- a/test/cozy/model/storage_block_list.py +++ b/test/cozy/model/storage_block_list.py @@ -11,8 +11,8 @@ def setup_inject(peewee_database_storage): def test_rebase_path(): - from cozy.model.storage_block_list import StorageBlockList from cozy.db.storage_blacklist import StorageBlackList + from cozy.model.storage_block_list import StorageBlockList model = StorageBlockList() diff --git a/test/cozy/model/test_book.py b/test/cozy/model/test_book.py index 0958c785..b8b9bd27 100644 --- a/test/cozy/model/test_book.py +++ b/test/cozy/model/test_book.py @@ -23,8 +23,8 @@ def test_db_created(peewee_database): def test_name_returns_correct_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.name == "Test Book" @@ -41,8 +41,8 @@ def test_setting_name_updates_in_book_object_and_database(peewee_database): def test_author_returns_correct_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.author == "Test Author" @@ -59,8 +59,8 @@ def test_setting_author_updates_in_book_object_and_database(peewee_database): def test_reader_returns_correct_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.reader == "Test Reader" @@ -77,8 +77,8 @@ def test_setting_reader_updates_in_book_object_and_database(peewee_database): def test_position_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.position == 0 @@ -95,8 +95,8 @@ def test_setting_position_updates_in_book_object_and_database(peewee_database): def test_rating_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.rating == 0 @@ -113,8 +113,8 @@ def test_setting_rating_updates_in_book_object_and_database(peewee_database): def test_cover_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.cover is None @@ -131,8 +131,8 @@ def test_setting_cover_updates_in_book_object_and_database(peewee_database): def test_playback_speed_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.playback_speed == 1.0 @@ -149,8 +149,8 @@ def test_setting_playback_speed_updates_in_book_object_and_database(peewee_datab def test_last_played_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert book.last_played == 0 @@ -167,8 +167,8 @@ def test_setting_last_played_updates_in_book_object_and_database(peewee_database def test_offline_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert not book.offline @@ -185,8 +185,8 @@ def test_setting_offline_updates_in_book_object_and_database(peewee_database): def test_downloaded_returns_default_value(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert not book.downloaded @@ -203,16 +203,16 @@ def test_setting_downloaded_updates_in_book_object_and_database(peewee_database) def test_chapters_return_correct_count_of_chapters(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) assert len(book.chapters) == 1 def test_tracks_are_ordered_by_disk_number_name(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(9)) @@ -223,8 +223,8 @@ def test_tracks_are_ordered_by_disk_number_name(peewee_database): def test_current_track_is_actually_current_track(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(9)) @@ -232,26 +232,26 @@ def test_current_track_is_actually_current_track(peewee_database): def test_try_to_init_empty_book_should_throw_exception(peewee_database): - from cozy.model.book import Book - from cozy.model.book import BookIsEmpty from cozy.db.book import Book as BookDB + from cozy.model.book import Book, BookIsEmpty with pytest.raises(BookIsEmpty): Book(peewee_database, BookDB.get(10)) def test_try_to_init_non_existant_book_throws_exception(peewee_database): - from cozy.model.book import Book - from cozy.db.book import Book as BookDB from peewee import DoesNotExist + from cozy.db.book import Book as BookDB + from cozy.model.book import Book + with pytest.raises(DoesNotExist): Book(peewee_database, BookDB.get(-42)) def test_delete_deletes_book_from_db(peewee_database, mocker): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) spy = mocker.spy(book, "emit_event") @@ -263,9 +263,9 @@ def test_delete_deletes_book_from_db(peewee_database, mocker): def test_deleted_book_removed_from_last_played_book_if_necessary(peewee_database): + from cozy.db.book import Book as BookDB from cozy.model.book import Book from cozy.model.settings import Settings - from cozy.db.book import Book as BookDB settings = Settings() inject.clear_and_configure( @@ -279,16 +279,16 @@ def test_deleted_book_removed_from_last_played_book_if_necessary(peewee_database def test_skipping_removing_a_non_existing_chapter(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) book._on_chapter_event("chapter-deleted", None) def test_progress_return_progress_for_started_book(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) chapter = book.chapters[0] @@ -299,8 +299,8 @@ def test_progress_return_progress_for_started_book(peewee_database): def test_progress_should_be_zero_for_unstarted_book(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) book.position = 0 @@ -309,8 +309,8 @@ def test_progress_should_be_zero_for_unstarted_book(peewee_database): def test_progress_should_be_100_for_finished_book(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) book.position = -1 @@ -319,11 +319,11 @@ def test_progress_should_be_100_for_finished_book(peewee_database): def test_removing_book_removes_all_traces_in_db(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB - from cozy.db.track import Track from cozy.db.file import File + from cozy.db.track import Track from cozy.db.track_to_file import TrackToFile + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) track_ids = [chapter.id for chapter in book.chapters] @@ -345,11 +345,11 @@ def test_removing_book_removes_all_traces_in_db(peewee_database): def test_removing_book_with_missing_file_removes_all_traces_in_db(peewee_database): - from cozy.model.book import Book from cozy.db.book import Book as BookDB - from cozy.db.track import Track from cozy.db.file import File + from cozy.db.track import Track from cozy.db.track_to_file import TrackToFile + from cozy.model.book import Book book = Book(peewee_database, BookDB.get(1)) track_ids = [chapter.id for chapter in book.chapters] diff --git a/test/cozy/model/test_database_importer.py b/test/cozy/model/test_database_importer.py index 266e38fd..491aaaee 100644 --- a/test/cozy/model/test_database_importer.py +++ b/test/cozy/model/test_database_importer.py @@ -12,8 +12,8 @@ def setup_inject(peewee_database): def test_prepare_files_db_objects_skips_existing_files(): - from cozy.model.database_importer import DatabaseImporter from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter media_file = MediaFile(book_name="New Book Name", author="New Author", @@ -30,8 +30,8 @@ def test_prepare_files_db_objects_skips_existing_files(): def test_prepare_files_db_objects_skips_duplicate_file(): - from cozy.model.database_importer import DatabaseImporter from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter media_file = MediaFile(book_name="New Book Name", author="New Author", @@ -49,9 +49,9 @@ def test_prepare_files_db_objects_skips_duplicate_file(): def test_update_files_db_objects_updates_modified_field(): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile from cozy.db.file import File + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter media_file = MediaFile(book_name="New Book Name", author="New Author", @@ -70,8 +70,8 @@ def test_update_files_db_objects_updates_modified_field(): def test_prepare_files_db_objects_returns_object_for_new_file(): - from cozy.model.database_importer import DatabaseImporter from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter media_file = MediaFile(book_name="New Book Name", author="New Author", @@ -96,10 +96,10 @@ def test_prepare_db_objects_skips_none(): def test_create_track_db_object_creates_object(): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile from cozy.db.book import Book from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -126,10 +126,10 @@ def test_create_track_db_object_creates_object(): def test_update_book_db_object_updates_object(): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile from cozy.db.book import Book from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -154,10 +154,10 @@ def test_update_book_db_object_updates_object(): def test_update_book_db_object_updates_object_regardless_of_book_spelling(): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile from cozy.db.book import Book from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -182,10 +182,10 @@ def test_update_book_db_object_updates_object_regardless_of_book_spelling(): def test_create_book_db_object_creates_object(): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile from cozy.db.book import Book from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -212,11 +212,11 @@ def test_create_book_db_object_creates_object(): def test_prepare_db_objects_recreates_existing_track(mocker): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile - from cozy.media.chapter import Chapter - from cozy.db.track_to_file import TrackToFile from cozy.db.file import File + from cozy.db.track_to_file import TrackToFile + from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -248,9 +248,9 @@ def test_prepare_db_objects_recreates_existing_track(mocker): def test_prepare_db_objects_skips_if_file_object_not_present(mocker): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -270,10 +270,10 @@ def test_prepare_db_objects_skips_if_file_object_not_present(mocker): def test_prepare_db_objects_creates_new_track(mocker): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile - from cozy.media.chapter import Chapter from cozy.db.file import File + from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() spy = mocker.spy(database_importer, "_get_track_list_for_db") @@ -296,10 +296,10 @@ def test_prepare_db_objects_creates_new_track(mocker): def test_prepare_db_objects_updates_existing_book(mocker): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile - from cozy.media.chapter import Chapter from cozy.db.file import File + from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() spy = mocker.spy(database_importer, "_update_book_db_object") @@ -322,10 +322,10 @@ def test_prepare_db_objects_updates_existing_book(mocker): def test_prepare_db_objects_updates_existing_book_regardless_of_spelling(mocker): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile - from cozy.media.chapter import Chapter from cozy.db.file import File + from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() spy = mocker.spy(database_importer, "_update_book_db_object") @@ -358,10 +358,10 @@ def test_prepare_db_objects_updates_existing_book_regardless_of_spelling(mocker) def test_prepare_db_objects_creates_new_book(mocker): - from cozy.model.database_importer import DatabaseImporter - from cozy.media.media_file import MediaFile - from cozy.media.chapter import Chapter from cozy.db.file import File + from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() spy = mocker.spy(database_importer, "_create_book_db_object") @@ -384,11 +384,11 @@ def test_prepare_db_objects_creates_new_book(mocker): def test_delete_all_tracks_from_db_does_as_it_says(): - from cozy.media.media_file import MediaFile - from cozy.media.chapter import Chapter from cozy.db.file import File from cozy.db.track import Track from cozy.db.track_to_file import TrackToFile + from cozy.media.chapter import Chapter + from cozy.media.media_file import MediaFile from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -467,10 +467,10 @@ def test_is_chapter_count_in_db_different_returns_false_for_equal_chapter_count( def test_insert_track_inserts_all_rows_expected(): - from cozy.model.database_importer import DatabaseImporter, TrackInsertRequest from cozy.db.book import Book from cozy.db.file import File from cozy.db.track_to_file import TrackToFile + from cozy.model.database_importer import DatabaseImporter, TrackInsertRequest database_importer = DatabaseImporter() @@ -501,8 +501,8 @@ def test_insert_track_inserts_all_rows_expected(): def test_update_book_position_skips_empty_book(): - from cozy.model.database_importer import DatabaseImporter from cozy.db.book import Book + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -511,9 +511,9 @@ def test_update_book_position_skips_empty_book(): def test_update_book_position_sets_position_for_multi_chapter_file_correctly(): - from cozy.model.database_importer import DatabaseImporter from cozy.db.book import Book from cozy.db.track import Track + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -526,9 +526,9 @@ def test_update_book_position_sets_position_for_multi_chapter_file_correctly(): def test_update_book_position_sets_position_for_single_chapter_file_correctly(): - from cozy.model.database_importer import DatabaseImporter from cozy.db.book import Book from cozy.db.track import Track + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() @@ -542,8 +542,8 @@ def test_update_book_position_sets_position_for_single_chapter_file_correctly(): def test_update_book_position_resets_position_if_it_is_longer_than_the_duration(): - from cozy.model.database_importer import DatabaseImporter from cozy.db.book import Book + from cozy.model.database_importer import DatabaseImporter database_importer = DatabaseImporter() diff --git a/test/cozy/model/test_library.py b/test/cozy/model/test_library.py index 81a21f5b..42896ebe 100644 --- a/test/cozy/model/test_library.py +++ b/test/cozy/model/test_library.py @@ -4,9 +4,8 @@ import pytest from peewee import SqliteDatabase -from cozy.settings import ApplicationSettings -from cozy.extensions.set import split_strings_to_set from cozy.model.settings import Settings +from cozy.settings import ApplicationSettings @pytest.fixture(autouse=True) @@ -28,8 +27,8 @@ def test_library_contains_books(): def test_authors_contains_every_author_from_db(): - from cozy.model.library import Library from cozy.db.book import Book + from cozy.model.library import Library, split_strings_to_set library = Library() books = Book.select(Book.author).distinct().order_by(Book.author) @@ -42,8 +41,8 @@ def test_authors_contains_every_author_from_db(): def test_readers_contains_every_reader_from_db(): - from cozy.model.library import Library from cozy.db.book import Book + from cozy.model.library import Library, split_strings_to_set library = Library() books = Book.select(Book.reader).distinct().order_by(Book.reader) diff --git a/test/cozy/model/test_settings.py b/test/cozy/model/test_settings.py index 7f12f065..6d557076 100644 --- a/test/cozy/model/test_settings.py +++ b/test/cozy/model/test_settings.py @@ -11,8 +11,8 @@ def setup_inject(peewee_database): def test_storage_locations_contains_every_storage_location_from_db(peewee_database): - from cozy.model.settings import Settings from cozy.db.storage import Storage + from cozy.model.settings import Settings settings = Settings() storage_locations = Storage.select() @@ -28,8 +28,8 @@ def test_storage_locations_contains_every_storage_location_from_db(peewee_databa def test_external_storage_locations_contain_only_external_storages(peewee_database): - from cozy.model.settings import Settings from cozy.db.storage import Storage + from cozy.model.settings import Settings settings = Settings() storage_locations = Storage.select().where(Storage.external) @@ -39,8 +39,8 @@ def test_external_storage_locations_contain_only_external_storages(peewee_databa def test_last_played_book_returns_correct_value(peewee_database): - from cozy.model.settings import Settings from cozy.db.book import Book + from cozy.model.settings import Settings settings = Settings() @@ -48,8 +48,8 @@ def test_last_played_book_returns_correct_value(peewee_database): def test_setting_last_played_book_to_none_updates_in_settings_object_and_database(peewee_database): - from cozy.model.settings import Settings from cozy.db.settings import Settings as SettingsModel + from cozy.model.settings import Settings settings = Settings() settings.last_played_book = None @@ -59,8 +59,8 @@ def test_setting_last_played_book_to_none_updates_in_settings_object_and_databas def test_fetching_non_existent_last_played_book_returns_none(peewee_database): - from cozy.model.settings import Settings from cozy.db.settings import Settings as SettingsModel + from cozy.model.settings import Settings db_object = SettingsModel.get() db_object.last_played_book = 437878782 @@ -72,8 +72,8 @@ def test_fetching_non_existent_last_played_book_returns_none(peewee_database): def test_fetching_non_existent_last_played_book_sets_it_to_none(peewee_database): - from cozy.model.settings import Settings from cozy.db.settings import Settings as SettingsModel + from cozy.model.settings import Settings db_object = SettingsModel.get() db_object.last_played_book = 437878782 @@ -86,8 +86,8 @@ def test_fetching_non_existent_last_played_book_sets_it_to_none(peewee_database) def test_ensure_default_storage_is_present_adds_default_if_not_present(peewee_database): - from cozy.model.settings import Settings from cozy.db.storage import Storage + from cozy.model.settings import Settings Storage.update(default=False).where(Storage.id == 2).execute() @@ -99,8 +99,8 @@ def test_ensure_default_storage_is_present_adds_default_if_not_present(peewee_da def test_ensure_default_storage_is_present_does_nothing_if_default_is_present(peewee_database): - from cozy.model.settings import Settings from cozy.db.storage import Storage + from cozy.model.settings import Settings settings = Settings() settings._load_all_storage_locations() diff --git a/test/cozy/extensions/test_set.py b/test/cozy/model/test_split_strings_to_set.py similarity index 94% rename from test/cozy/extensions/test_set.py rename to test/cozy/model/test_split_strings_to_set.py index 3acd5e05..371afc59 100644 --- a/test/cozy/extensions/test_set.py +++ b/test/cozy/model/test_split_strings_to_set.py @@ -1,4 +1,4 @@ -from cozy.extensions.set import split_strings_to_set +from cozy.model.library import split_strings_to_set def test_split_strings_does_nothing_for_non_seperated_element(): diff --git a/test/cozy/model/test_storage.py b/test/cozy/model/test_storage.py index 46d0e87b..70a62cb4 100644 --- a/test/cozy/model/test_storage.py +++ b/test/cozy/model/test_storage.py @@ -21,7 +21,7 @@ def test_setting_path_updates_in_track_object_and_database(peewee_database_stora def test_setting_invalid_path_raises_exception(peewee_database_storage): - from cozy.model.storage import Storage, InvalidPath + from cozy.model.storage import InvalidPath, Storage invalid_path = "not an absolute path" storage = Storage(peewee_database_storage, 1) diff --git a/test/cozy/model/test_track.py b/test/cozy/model/test_track.py index fe9ac105..92e6ac4e 100644 --- a/test/cozy/model/test_track.py +++ b/test/cozy/model/test_track.py @@ -8,16 +8,16 @@ def test_db_created(peewee_database): def test_name_returns_correct_value(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) assert track.name == "Test Track" def test_name_returns_generated_name_when_no_name_is_present(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(234)) @@ -35,8 +35,8 @@ def test_setting_name_updates_in_track_object_and_database(peewee_database): def test_number_returns_correct_value(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) assert track.number == 1 @@ -53,8 +53,8 @@ def test_setting_number_updates_in_track_object_and_database(peewee_database): def test_disk_returns_correct_value(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) assert track.disk == 1 @@ -71,8 +71,8 @@ def test_setting_disk_updates_in_track_object_and_database(peewee_database): def test_position_returns_default_value(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) assert track.position == 0 @@ -89,17 +89,17 @@ def test_setting_position_updates_in_track_object_and_database(peewee_database): def test_file_returns_default_value(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) assert track.file == "test.mp3" def test_setting_file_updates_in_track_object_and_database(peewee_database): + from cozy.db.track import Track as TrackDB from cozy.db.track_to_file import TrackToFile from cozy.model.track import Track - from cozy.db.track import Track as TrackDB track = Track(peewee_database, TrackDB.get(1)) track.file = "altered.mp3" @@ -109,10 +109,10 @@ def test_setting_file_updates_in_track_object_and_database(peewee_database): def test_setting_file_gets_file_object_if_it_is_already_present_in_database(peewee_database): - from cozy.db.track_to_file import TrackToFile from cozy.db.file import File - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.db.track_to_file import TrackToFile + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) track.file = "file with multiple chapters.m4b" @@ -125,10 +125,10 @@ def test_setting_file_gets_file_object_if_it_is_already_present_in_database(peew def test_setting_file_gets_file_object_if_it_is_already_present_in_database_but_preserves_old_file_if_still_used( peewee_database): - from cozy.db.track_to_file import TrackToFile from cozy.db.file import File - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.db.track_to_file import TrackToFile + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(230)) track.file = "Changed path" @@ -140,8 +140,8 @@ def test_setting_file_gets_file_object_if_it_is_already_present_in_database_but_ def test_length_returns_default_value(peewee_database): - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) assert track.length == 42.1 * 1e9 @@ -158,9 +158,9 @@ def test_setting_length_updates_in_track_object_and_database(peewee_database): def test_setting_modified_updates_in_track_object_and_database(peewee_database): - from cozy.model.track import Track - from cozy.db.track_to_file import TrackToFile from cozy.db.track import Track as TrackDB + from cozy.db.track_to_file import TrackToFile + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) track.modified = 42 @@ -186,8 +186,8 @@ def test_delete_deletes_track_from_db(peewee_database, mocker): def test_delete_does_not_delete_book(peewee_database): - from cozy.db.track import Track as TrackDB from cozy.db.book import Book + from cozy.db.track import Track as TrackDB from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) @@ -198,8 +198,8 @@ def test_delete_does_not_delete_book(peewee_database): def test_track_to_file_not_present_throws_exception_and_deletes_track_instance(peewee_database): - from cozy.db.track_to_file import TrackToFile from cozy.db.track import Track as TrackDB + from cozy.db.track_to_file import TrackToFile from cozy.model.track import Track, TrackInconsistentData TrackToFile.select().join(TrackDB).where(TrackToFile.track.id == 1).get().delete_instance() @@ -211,8 +211,8 @@ def test_track_to_file_not_present_throws_exception_and_deletes_track_instance(p def test_delete_removes_file_object_if_not_used_elsewhere(peewee_database): from cozy.db.file import File - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(1)) file_id = track.file_id @@ -223,8 +223,8 @@ def test_delete_removes_file_object_if_not_used_elsewhere(peewee_database): def test_delete_keeps_file_object_if_used_elsewhere(peewee_database): from cozy.db.file import File - from cozy.model.track import Track from cozy.db.track import Track as TrackDB + from cozy.model.track import Track track = Track(peewee_database, TrackDB.get(230)) file_id = track.file_id