tests: remove pyfakefs due to issues with pathlib and sqlite in favor of a simple tempfolder where to store test files
This commit is contained in:
parent
4fb1fff521
commit
c6d361f649
6 changed files with 45 additions and 29 deletions
|
|
@ -41,11 +41,26 @@ def ssh_recipient(halig_ssh_public_key: str) -> Recipient:
|
|||
return Recipient.from_str(halig_ssh_public_key)
|
||||
|
||||
|
||||
# @pytest.fixture()
|
||||
# def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
||||
# fs.add_real_paths(["/etc/localtime"])
|
||||
# ssh_path = Path("~/.ssh").expanduser()
|
||||
# ssh_path.mkdir(parents=True)
|
||||
#
|
||||
# with (ssh_path / "id_ed25519").open("w") as f:
|
||||
# f.write(halig_ssh_private_key)
|
||||
#
|
||||
# with (ssh_path / "id_ed25519.pub").open("w") as f:
|
||||
# f.write(halig_ssh_public_key)
|
||||
#
|
||||
# halig_path = Path("~/.config/halig").expanduser()
|
||||
# halig_path.mkdir(parents=True)
|
||||
# return halig_path
|
||||
|
||||
@pytest.fixture()
|
||||
def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
||||
fs.add_real_paths(["/etc/localtime"])
|
||||
ssh_path = Path("~/.ssh").expanduser()
|
||||
ssh_path.mkdir(parents=True)
|
||||
def halig_ssh_path(tmp_path: Path, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
||||
ssh_path = tmp_path / ".ssh"
|
||||
ssh_path.mkdir()
|
||||
|
||||
with (ssh_path / "id_ed25519").open("w") as f:
|
||||
f.write(halig_ssh_private_key)
|
||||
|
|
@ -53,26 +68,35 @@ def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
|
|||
with (ssh_path / "id_ed25519.pub").open("w") as f:
|
||||
f.write(halig_ssh_public_key)
|
||||
|
||||
halig_path = Path("~/.config/halig").expanduser()
|
||||
return ssh_path
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def halig_config_path(tmp_path: Path):
|
||||
halig_path = tmp_path / ".config/halig"
|
||||
halig_path.mkdir(parents=True)
|
||||
return halig_path
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def notebooks_path(halig_path) -> Path:
|
||||
notebooks_path = Path("~/Notebooks").expanduser()
|
||||
notebooks_path.mkdir(parents=True)
|
||||
def notebooks_path(tmp_path) -> Path:
|
||||
notebooks_path = tmp_path / "Notebooks"
|
||||
notebooks_path.mkdir()
|
||||
return notebooks_path
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def settings(notebooks_path: Path) -> Settings:
|
||||
return Settings(notebooks_root_path=notebooks_path)
|
||||
def settings(notebooks_path: Path, halig_ssh_path) -> Settings:
|
||||
return Settings(
|
||||
notebooks_root_path=notebooks_path,
|
||||
identity_paths=[halig_ssh_path / "id_ed25519"],
|
||||
recipient_paths=[halig_ssh_path / "id_ed25519.pub"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def settings_file_path(halig_path: Path, notebooks_path: Path) -> Path:
|
||||
yaml_file = halig_path / "halig.yml"
|
||||
def settings_file_path(halig_config_path: Path, notebooks_path: Path) -> Path:
|
||||
yaml_file = halig_config_path / "halig.yml"
|
||||
yaml_file.touch()
|
||||
s = Settings(notebooks_root_path=notebooks_path)
|
||||
# `.dict()` doesn't serialize some fields that yaml doesn't understand
|
||||
|
|
@ -83,8 +107,8 @@ def settings_file_path(halig_path: Path, notebooks_path: Path) -> Path:
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def empty_file_path(halig_path: Path) -> Path:
|
||||
empty_path = halig_path / "empty"
|
||||
def empty_file_path(halig_config_path: Path) -> Path:
|
||||
empty_path = halig_config_path / "empty"
|
||||
empty_path.touch()
|
||||
return empty_path
|
||||
|
||||
|
|
|
|||
|
|
@ -4,27 +4,26 @@ from halig.encryption import Encryptor
|
|||
from halig.settings import Settings
|
||||
|
||||
|
||||
def test_instance_encryptor_from_age_keys(halig_path, notebooks_path):
|
||||
def test_instance_encryptor_from_age_keys(notebooks_path, halig_config_path):
|
||||
identity_paths = []
|
||||
recipient_paths = []
|
||||
identities = []
|
||||
for i in range(5):
|
||||
identity = x25519.Identity.generate()
|
||||
identities.append(identity)
|
||||
identity_path = halig_path / f"identity_{i}.key"
|
||||
identity_path = halig_config_path / f"identity_{i}.key"
|
||||
identity_path.touch()
|
||||
with identity_path.open("w") as f:
|
||||
f.write(str(identity))
|
||||
identity_paths.append(identity_path)
|
||||
|
||||
recipient_path = halig_path / f"recipient_{i}.key"
|
||||
recipient_path = halig_config_path / f"recipient_{i}.key"
|
||||
recipient_path.touch()
|
||||
|
||||
with recipient_path.open("w") as f:
|
||||
f.write(str(identity.to_public()))
|
||||
|
||||
recipient_paths.append(recipient_path)
|
||||
# cache_path = platformdirs.user_cache_path("halig", ensure_exists=True)
|
||||
settings = Settings(
|
||||
notebooks_root_path=notebooks_path,
|
||||
identity_paths=identity_paths,
|
||||
|
|
|
|||
|
|
@ -20,17 +20,12 @@ def test_load_from_file(notebooks_path: Path, settings_file_path: Path):
|
|||
assert settings.notebooks_root_path == notebooks_path
|
||||
|
||||
|
||||
def test_load_from_existing_standard_file(settings_file_path: Path, settings: Settings):
|
||||
standard_settings = load_from_file()
|
||||
assert standard_settings.notebooks_root_path == settings.notebooks_root_path
|
||||
|
||||
|
||||
def test_load_from_empty_file_raises_value_error(empty_file_path: Path):
|
||||
with pytest.raises(ValueError, match=f"File {empty_file_path} is empty"):
|
||||
load_from_file(empty_file_path)
|
||||
|
||||
|
||||
def test_load_from_non_existing_file_path_raises_file_not_found_error(halig_path: Path):
|
||||
file = halig_path / "some_invalid_file.yml"
|
||||
def test_load_from_non_existing_file_path_raises_file_not_found_error(halig_config_path: Path):
|
||||
file = halig_config_path / "some_invalid_file.yml"
|
||||
with pytest.raises(FileNotFoundError, match=f"File {file} does not exist"):
|
||||
load_from_file(file)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue