Пример #1
0
def test_add_subscription(sqlite_backend: SQLiteBackend):
    sqlite_backend.add_subscription(
        Subscription(name="233", updating=False, episode=10))
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        sub = conn.execute(
            "select name, episode, updating from subscription where name='233'"
        ).fetchone()
        assert sub == ("233", 10, False), "subscription in db diff from args"
Пример #2
0
def test_remove_subscription(sqlite_backend: SQLiteBackend):
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        conn.execute(
            "insert into subscription(name, episode) values ('233', 2)")

    sqlite_backend.remove_subscription(Subscription(name="233"))

    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        sub = conn.execute(
            "select * from subscription where name='233'").fetchone()
        assert sub is None, "subscription should be deleted"
Пример #3
0
def test_add_subscription_exists(sqlite_backend: SQLiteBackend):
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        conn.execute(
            "insert into subscription(name, episode) values ('233', 2)")

    sqlite_backend.add_subscription(
        Subscription(name="233", updating=False, episode=10))

    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        sub = conn.execute(
            "select episode from subscription where name='233'").fetchone()
        assert sub[0] == 10, "existed subscription should be replaced by args"
Пример #4
0
def test_get_series(sqlite_backend: SQLiteBackend):
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        conn.execute(
            "insert into series(id, name, source, sub_name)"
            " values ('id1','n', 'src', '233'), ('id2', 'm','c','234')")
    s = sqlite_backend.get_series("src", "n")
    assert s.id == "id1", "sqlite_backend.get_series get wrong series"
Пример #5
0
def test_get_all_subscription(sqlite_backend: SQLiteBackend):
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        conn.execute(
            "insert into subscription(name, episode, updating) values ('233', 2, 1), "
            "('234',3,0)")
    s = sqlite_backend.get_all_subscription()
    assert len(s) == 2
Пример #6
0
def test_get_subscription_with_series(sqlite_backend: SQLiteBackend):
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        conn.execute("insert into subscription(name, episode, updating) "
                     "values ('233', 2, 1), ('234', 3, 0)")
        conn.execute(
            "insert into series(id, name, source, sub_name)"
            " values ('id1','n', 'src', '233'), ('id2', 'm','c','234')")

    s = sqlite_backend.get_subscription("233")
    assert len(s.series) == 1, "subscription get extra series"
    assert s.series[0].id == "id1", "subscription get wrong series"
Пример #7
0
def test_get_subscription(sqlite_backend: SQLiteBackend):
    with sqlite3.connect(sqlite_backend.cfg.db_path) as conn:
        conn.execute(
            "insert into subscription(name, episode, updating) values ('233', 2, 1)"
        )

    sub = sqlite_backend.get_subscription("233")
    assert (sub.name, sub.episode, sub.updating) == (
        "233",
        2,
        True,
    ), "subscription not same with db record"
Пример #8
0
def test_save_subscription(mocker: MockFixture, sqlite_db_config):
    m: MagicMock = mocker.patch(
        "bgmi3.backend.sqlite.SQLiteBackend.add_subscription")
    sub = Subscription(name="233")
    SQLiteBackend(sqlite_db_config).save_subscription(sub)
    m.assert_called_once_with(sub)
Пример #9
0
def test_install(sqlite_db_config: SqliteConfig):
    SQLiteBackend.install(sqlite_db_config.dict())
    conn = sqlite3.connect(sqlite_db_config.db_path)
    tables = conn.execute(
        "SELECT Name FROM sqlite_master WHERE type='table'").fetchall()
    assert tables
Пример #10
0
def sqlite_backend(sqlite_db_config):
    SQLiteBackend.install(sqlite_db_config.dict())
    return SQLiteBackend(sqlite_db_config.dict())
Пример #11
0
def test_impl_all_abstract_method():
    SQLiteBackend({})
Пример #12
0
def test_wrong_config():
    with pytest.raises(ConfigNotValid):
        SQLiteBackend({"a": "b"})
Пример #13
0
def test_get_series_raise(sqlite_backend: SQLiteBackend):
    with pytest.raises(SeriesNotFollowed):
        sqlite_backend.get_series("1", "2")