updated tests to changes
This commit is contained in:
parent
b0e68ae5a1
commit
e7716a52e4
46
test/test_backends_kvs.py
Normal file
46
test/test_backends_kvs.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
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"
|
||||
|
|
@ -15,12 +15,14 @@ def bunker_with_test_file_empty(tmpdir):
|
|||
def test_add_component(tmpdir):
|
||||
path = os.path.join(str(tmpdir), "test.bunker")
|
||||
bunker = Bunker.open(path)
|
||||
|
||||
bunker._add_component("test", b"H6ihKLXV8HMQWbJs", "kvs")
|
||||
|
||||
assert {"component": "test"} in bunker._components
|
||||
|
||||
def test_load_component1(bunker_with_test_file_empty):
|
||||
bunker, component_name, password = bunker_with_test_file_empty
|
||||
|
||||
component, type_ = bunker._load_component(component_name, password)
|
||||
|
||||
assert isinstance(component, BunkeredFile)
|
||||
|
@ -29,7 +31,18 @@ def test_save_and_load(bunker_with_test_file_empty):
|
|||
bunker, component_name, password = bunker_with_test_file_empty
|
||||
component, type_ = bunker._load_component(component_name, password)
|
||||
component.write(b"this is a test text")
|
||||
bunker._save_compontent(component_name, password, component)
|
||||
bunker._save_component(component_name, password, component)
|
||||
|
||||
component, type_ = bunker._load_component(component_name, password)
|
||||
|
||||
assert component.read() == b"this is a test text"
|
||||
|
||||
def test_save_and_load_long(bunker_with_test_file_empty):
|
||||
bunker, component_name, password = bunker_with_test_file_empty
|
||||
component, type_ = bunker._load_component(component_name, password)
|
||||
component.write(b"this is a test text" * 50)
|
||||
bunker._save_component(component_name, password, component)
|
||||
|
||||
component, type_ = bunker._load_component(component_name, password)
|
||||
|
||||
assert component.read() == b"this is a test text" * 50
|
||||
|
|
Loading…
Reference in New Issue
Block a user