def test_store_and_retrieve_simple_config(): adapter = SQLiteAdapter(MEMORY_DBNAME) store_val = {"val1": True, "val2": None, "val3": 1.4} adapter.store_config("myconf", store_val) read_val = adapter.read_config("myconf") assert read_val == store_val assert read_val is not store_val
def test_sqlite_reading_bad_config(): adapter = SQLiteAdapter(":memory:") # inject bad data (array, needs to be dict) # store_config does not check the input type, just uses json.dumps() adapter.store_config("foo_conf", []) with pytest.raises(ValueError, match="reading config data and got non-dict result"): adapter.read_config("foo_conf")
def test_remove_config(): adapter = SQLiteAdapter(MEMORY_DBNAME) store_val = {"val1": True, "val2": None, "val3": 1.4} adapter.store_config("myconf", store_val) adapter.store_config("myconf2", store_val) removed = adapter.remove_config("myconf") assert removed read_val = adapter.read_config("myconf") assert read_val is None read_val = adapter.read_config("myconf2") assert read_val == store_val removed = adapter.remove_config("myconf") assert not removed
def test_iter_namespaces(mock_response, db_filename): foo_adapter = SQLiteAdapter(db_filename, namespace="foo") bar_adapter = SQLiteAdapter(db_filename, namespace="bar") baz_adapter = SQLiteAdapter(db_filename, namespace="baz") for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert list(adapter.iter_namespaces()) == [] assert list( adapter.iter_namespaces(include_config_namespaces=True)) == [] foo_adapter.store(mock_response) for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert list(adapter.iter_namespaces()) == ["foo"] assert list(adapter.iter_namespaces( include_config_namespaces=True)) == ["foo"] bar_adapter.store(mock_response) for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert set(adapter.iter_namespaces()) == {"foo", "bar"} assert set( adapter.iter_namespaces(include_config_namespaces=True)) == { "foo", "bar", } baz_adapter.store_config("some_conf", {}) for adapter in [foo_adapter, bar_adapter, baz_adapter]: assert set(adapter.iter_namespaces()) == {"foo", "bar"} assert set( adapter.iter_namespaces(include_config_namespaces=True)) == { "foo", "bar", "baz", }