import os import pytest from bunker.bunker import Bunker from bunker.backends.kvs import KeyValueStore @pytest.fixture def bunker_and_password(tmpdir): path = os.path.join(str(tmpdir), "test.bunker") bunker = Bunker.open(path) return bunker, b"H6ihKLXV8HMQWbJs" def test_add_kvs(bunker_and_password): bunker, password = bunker_and_password kvs = bunker.add_component("kvs", "test.kvs", password) assert isinstance(kvs, KeyValueStore) @pytest.fixture def bunker_kvs_password_name(tmpdir): path = os.path.join(str(tmpdir), "test.bunker") password = b"H6ihKLXV8HMQWbJs" bunker = Bunker.open(path) kvs = bunker.add_component("kvs", "test.kvs", password) return bunker, kvs, password, "test.kvs" def test_kvs_additem_getitem(bunker_kvs_password_name): bunker, kvs, password, name = bunker_kvs_password_name kvs.additem("foo", "bar") assert kvs.getitem("foo") == "bar" def test_kvs_close_open(bunker_kvs_password_name): bunker, kvs, password, name = bunker_kvs_password_name kvs.additem("foo", "bar") kvs.close() kvs = bunker.get_component(name, password) assert kvs.getitem("foo") == "bar"