def test_fd_manager_fd_list(db_controller):
    assert (
        "__seeded_test_db__" in FdMultiController.fd_list()
    ), "failed to register test db"
    # remove file and try to open
    os.remove(FdMultiController._path_generator("registered_pickle"))
    assert FdMultiController.fd_list() == [], "failed to remove db registry"
def db_controller():
    """ return db controller for use with testing
    """
    helpers.clear_DBs()
    FdMultiController.fd_create("__seeded_test_db__")
    FdMultiController.fd_create("__empty_test_db__")
    # this is a bit scetch but preferable to having a seeding script lying about
    # add some data independant of read and write modules

    conn1 = sqlite3.connect(
        FdMultiController._path_generator("__seeded_test_db__"))
    conn2 = sqlite3.connect(
        FdMultiController._path_generator("__empty_test_db__"))
    conn1.cursor().executescript(SEED)
    conn1.commit()
    conn2.commit()
    conn1.close()
    conn2.close()

    yield {
        "seeded": FdMultiController.fd_connect("__seeded_test_db__", "rwd"),
        "empty": FdMultiController.fd_connect("__empty_test_db__", "rwd"),
    }
    helpers.clear_DBs()
def test_fd_manager_fd_register(db_controller):
    # test faliure, file not there
    path = FdMultiController._path_generator("RaNdOmGibBeRiSh")
    with pytest.raises(Exception) as e:
        FdMultiController.fd_register("RaNdOmGibBeRiSh")
    expWarn = "No file found at: " + path
    assert expWarn in str(e.value)
    # test sucess
    # Warning: If schema checks implemented as per TODO, rewrite this
    conn = sqlite3.connect(path)
    # reregister existing db and check no duplicate added
    FdMultiController.fd_register("RaNdOmGibBeRiSh")
    FdMultiController.fd_register("RaNdOmGibBeRiSh")

    assert FdMultiController.fd_list().count("RaNdOmGibBeRiSh") == 1

    FdMultiController.fd_remove("RaNdOmGibBeRiSh")
    assert "RaNdOmGibBeRiSh" not in FdMultiController.fd_list()