Beispiel #1
0
def test_last_played_book_returns_correct_value(peewee_database):
    from cozy.model.settings import Settings
    from cozy.db.book import Book

    settings = Settings()

    assert settings.last_played_book == Book.get()
Beispiel #2
0
 def configure_inject(self, binder):
     binder.bind_to_provider(SqliteDatabase, get_db)
     binder.bind("MainWindow", self.main_window)
     binder.bind_to_constructor(
         Gio.Settings, lambda: Gio.Settings("com.github.geigi.cozy"))
     binder.bind_to_constructor(ApplicationSettings,
                                lambda: ApplicationSettings())
     binder.bind_to_constructor(Settings, lambda: Settings())
     binder.bind_to_constructor("FilesystemMonitor",
                                lambda: FilesystemMonitor())
     binder.bind_to_constructor(OfflineCache, lambda: OfflineCache())
     binder.bind_to_constructor(Player, lambda: Player())
     binder.bind_to_constructor(Library, lambda: Library())
     binder.bind_to_constructor(LibraryViewModel,
                                lambda: LibraryViewModel())
     binder.bind_to_constructor(SearchViewModel, lambda: SearchViewModel())
     binder.bind_to_constructor(UISettings, lambda: UISettings())
     binder.bind_to_constructor(StorageBlockList,
                                lambda: StorageBlockList())
     binder.bind_to_constructor(Files, lambda: Files())
     binder.bind_to_constructor(BookDetailViewModel,
                                lambda: BookDetailViewModel())
     binder.bind_to_constructor(PlaybackControlViewModel,
                                lambda: PlaybackControlViewModel())
     binder.bind_to_constructor(HeaderbarViewModel,
                                lambda: HeaderbarViewModel())
     binder.bind_to_constructor(PlaybackSpeedViewModel,
                                lambda: PlaybackSpeedViewModel())
     binder.bind_to_constructor(SleepTimerViewModel,
                                lambda: SleepTimerViewModel())
Beispiel #3
0
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

    settings = Settings()
    settings.last_played_book = None

    assert settings.last_played_book == None
    assert SettingsModel.get().last_played_book == None
Beispiel #4
0
def test_external_storage_locations_contain_only_external_storages(peewee_database):
    from cozy.model.settings import Settings
    from cozy.db.storage import Storage

    settings = Settings()
    storage_locations = Storage.select().where(Storage.external == True)

    assert len(settings.external_storage_locations) == len(storage_locations)
    assert all([storage.external for storage in settings.external_storage_locations])
Beispiel #5
0
def test_ensure_default_storage_present_does_nothing_if_default_is_present(peewee_database):
    from cozy.model.settings import Settings
    from cozy.db.storage import Storage

    settings = Settings()
    settings._load_all_storage_locations()
    settings._ensure_default_storage_present()
    assert not Storage.get(1).default
    assert Storage.get(2).default
Beispiel #6
0
def setup_inject(peewee_database):
    inject.clear()
    inject.configure(lambda binder:
                     (binder.bind(SqliteDatabase, peewee_database),
                      binder.bind_to_constructor(Settings, lambda: Settings()).
                      bind_to_constructor(ApplicationSettings, lambda:
                                          ApplicationSettingsMock())))
    yield
    inject.clear()
Beispiel #7
0
def setup_inject(peewee_database):
    inject.clear_and_configure(
        lambda binder: binder.bind(SqliteDatabase, peewee_database).
        bind_to_constructor("FilesystemMonitor", MagicMock(
        )).bind_to_constructor(GstPlayer, MagicMock()).bind_to_constructor(
            ApplicationSettings, MagicMock()).bind_to_constructor(
                Library, lambda: Library()).bind_to_constructor(
                    Settings, lambda: Settings()))

    yield
    inject.clear()
Beispiel #8
0
def test_ensure_default_storage_present_adds_default_if_not_present(peewee_database):
    from cozy.model.settings import Settings
    from cozy.db.storage import Storage

    Storage.update(default=False).where(Storage.id == 2).execute()

    settings = Settings()
    settings._load_all_storage_locations()
    settings._ensure_default_storage_present()
    assert Storage.get(1).default
    assert not Storage.get(2).default
Beispiel #9
0
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

    db_object = SettingsModel.get()
    db_object.last_played_book = 437878782
    db_object.save(only=db_object.dirty_fields)

    settings = Settings()

    assert settings.last_played_book is None
Beispiel #10
0
def test_deleted_book_removed_from_last_played_book_if_necessary(
        peewee_database):
    from cozy.model.book import Book
    from cozy.model.settings import Settings

    settings = Settings()
    inject.clear_and_configure(lambda binder: binder.bind(
        SqliteDatabase, peewee_database) and binder.bind(Settings, settings))
    book = Book(peewee_database, 1)

    settings.last_played_book = book.db_object
    book._on_chapter_event("chapter-deleted", book.chapters[0])

    assert settings.last_played_book == None
Beispiel #11
0
def test_storage_locations_contains_every_storage_location_from_db(peewee_database):
    from cozy.model.settings import Settings
    from cozy.db.storage import Storage

    settings = Settings()
    storage_locations = Storage.select()

    assert len(settings.storage_locations) == len(storage_locations)
    assert [storage.path for storage in settings.storage_locations] == [storage.path for storage in storage_locations]
    assert [storage.location_type for storage in settings.storage_locations] == [storage.location_type for storage in
                                                                                 storage_locations]
    assert [storage.default for storage in settings.storage_locations] == [storage.default for storage in
                                                                           storage_locations]
    assert [storage.external for storage in settings.storage_locations] == [storage.external for storage in
                                                                            storage_locations]
Beispiel #12
0
 def configure_inject(binder):
     binder.bind_to_provider(SqliteDatabase, get_db)
     binder.bind_to_constructor(
         Gio.Settings, lambda: Gio.Settings("com.github.geigi.cozy"))
     binder.bind_to_constructor(ApplicationSettings,
                                lambda: ApplicationSettings())
     binder.bind_to_constructor(Settings, lambda: Settings())
     binder.bind_to_constructor("FilesystemMonitor",
                                lambda: FilesystemMonitor())
     binder.bind_to_constructor(Library, lambda: Library())
     binder.bind_to_constructor(LibraryViewModel,
                                lambda: LibraryViewModel())
     binder.bind_to_constructor(SearchViewModel, lambda: SearchViewModel())
     binder.bind_to_constructor(UISettings, lambda: UISettings())
     binder.bind_to_constructor(StorageBlockList,
                                lambda: StorageBlockList())
     binder.bind_to_constructor(Files, lambda: Files())