bunker/test/test_bunker_privates.py

49 lines
1.6 KiB
Python
Raw Normal View History

2019-03-13 13:02:48 +00:00
import os
import pytest
from bunker.bunker import Bunker
from bunker.files.bunkeredfile import BunkeredFile
@pytest.fixture
def bunker_with_test_file_empty(tmpdir):
path = os.path.join(str(tmpdir), "test.bunker")
bunker = Bunker.open(path)
bunker._add_component("test", b"H6ihKLXV8HMQWbJs", "kvs")
return bunker, "test", b"H6ihKLXV8HMQWbJs"
def test_add_component(tmpdir):
path = os.path.join(str(tmpdir), "test.bunker")
bunker = Bunker.open(path)
2019-03-20 09:00:35 +00:00
2019-03-13 13:02:48 +00:00
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
2019-03-20 09:00:35 +00:00
2019-03-13 13:02:48 +00:00
component, type_ = bunker._load_component(component_name, password)
assert isinstance(component, BunkeredFile)
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")
2019-03-20 09:00:35 +00:00
bunker._save_component(component_name, password, component)
2019-03-13 13:02:48 +00:00
component, type_ = bunker._load_component(component_name, password)
assert component.read() == b"this is a test text"
2019-03-20 09:00:35 +00:00
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