From e7716a52e48e6a1e6ffdc882d014059bf04ab1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 20 Mar 2019 10:00:35 +0100 Subject: [PATCH] updated tests to changes --- test/test_backends_kvs.py | 46 ++++++++++++++++++++++++++++++++++++ test/test_bunker_privates.py | 15 +++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/test_backends_kvs.py diff --git a/test/test_backends_kvs.py b/test/test_backends_kvs.py new file mode 100644 index 0000000..49cbbfb --- /dev/null +++ b/test/test_backends_kvs.py @@ -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" + diff --git a/test/test_bunker_privates.py b/test/test_bunker_privates.py index b4424c7..3f83384 100644 --- a/test/test_bunker_privates.py +++ b/test/test_bunker_privates.py @@ -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