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) 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) 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_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