56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
import os
|
|
import pytest
|
|
|
|
from bunker.bunker import Bunker
|
|
from bunker.backends.directory_store import DirectoryStore
|
|
|
|
@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_directory_store(bunker_and_password):
|
|
bunker, password = bunker_and_password
|
|
|
|
ds = bunker.add_component("ds", "test.ds", password)
|
|
|
|
assert isinstance(ds, DirectoryStore)
|
|
|
|
@pytest.fixture
|
|
def bunker_ds_password_name(tmpdir):
|
|
path = os.path.join(str(tmpdir), "test.bunker")
|
|
password = b"H6ihKLXV8HMQWbJs"
|
|
bunker = Bunker.open(path)
|
|
|
|
ds = bunker.add_component("ds", "test.ds", password)
|
|
|
|
return bunker, ds, password, "test.ds"
|
|
|
|
@pytest.fixture
|
|
def file_contents():
|
|
return {
|
|
"foo.tx": "test 123"
|
|
, "bar.tx": "foobar"
|
|
}
|
|
|
|
def test_directory_store_add_get_files(bunker_ds_password_name, file_contents):
|
|
bunker, ds, password, name = bunker_ds_password_name
|
|
directory = ds.get_directory()
|
|
for fname, content in file_contents.items():
|
|
with open(os.path.join(directory, fname), "w") as fout:
|
|
fout.write(content)
|
|
ds.close()
|
|
ds = bunker.get_component(name, password)
|
|
directory = ds.get_directory()
|
|
|
|
for fname, content in file_contents.items():
|
|
with open(os.path.join(directory, fname), "r") as fin:
|
|
assert fin.read() == content
|
|
|
|
|
|
|
|
|
|
|