This commit is contained in:
parent
3d053d532a
commit
d9eb99b72e
9 changed files with 71 additions and 28 deletions
|
|
@ -3,6 +3,7 @@ from tempfile import NamedTemporaryFile
|
|||
|
||||
import pytest
|
||||
import yaml
|
||||
from pydantic import ValidationError
|
||||
|
||||
from halig.config import get_config, Config, EncryptionKeysConfig
|
||||
from halig.exceptions import ConfigFileDoesNotExist, ConfigFileIsInvalid
|
||||
|
|
@ -26,9 +27,9 @@ def test_get_config_raises_invalid_config_file_00(tmpfile): # noqa: F811
|
|||
get_config(Path(tmpfile.name))
|
||||
|
||||
|
||||
def test_get_config_raises_invalid_config_file_01(tmpfile): # noqa: F811
|
||||
def test_get_config_raises_validation_error(tmpfile): # noqa: F811
|
||||
yaml.dump({"foo": "bar"}, tmpfile, Dumper=yaml.SafeDumper)
|
||||
with pytest.raises(ConfigFileIsInvalid):
|
||||
with pytest.raises(ValidationError):
|
||||
get_config(Path(tmpfile.name))
|
||||
|
||||
|
||||
|
|
@ -50,7 +51,20 @@ def test_get_config(tmpdir): # noqa: F811
|
|||
public_key_path=public_key_path, private_key_path=private_key_path
|
||||
),
|
||||
)
|
||||
assert config.notes_root_path == notes_root_path
|
||||
assert config.age_binary_path == age_binary_path
|
||||
assert config.encryption_keys.public_key_path == public_key_path
|
||||
assert config.encryption_keys.private_key_path == private_key_path
|
||||
raw_config = config.dict()
|
||||
assert (
|
||||
config.notes_root_path == notes_root_path == Path(raw_config["notes_root_path"])
|
||||
)
|
||||
assert (
|
||||
config.age_binary_path == age_binary_path == Path(raw_config["age_binary_path"])
|
||||
)
|
||||
assert (
|
||||
config.encryption_keys.public_key_path
|
||||
== public_key_path
|
||||
== Path(raw_config["encryption_keys"]["public_key_path"])
|
||||
)
|
||||
assert (
|
||||
config.encryption_keys.private_key_path
|
||||
== private_key_path
|
||||
== Path(raw_config["encryption_keys"]["private_key_path"])
|
||||
)
|
||||
|
|
|
|||
33
tests/test_utils.py
Normal file
33
tests/test_utils.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from halig.utils import resolve_path
|
||||
|
||||
|
||||
def test_resolve_absolute_path():
|
||||
path = Path("/foo/bar/baz")
|
||||
assert resolve_path(path) == path
|
||||
|
||||
|
||||
def test_resolve_user_path():
|
||||
path = Path("~/foo/bar/baz")
|
||||
assert resolve_path(path) == path.expanduser()
|
||||
|
||||
|
||||
def test_resolve_path_with_envvars():
|
||||
os.environ["FOO"] = "foo"
|
||||
os.environ["BAR"] = "bar"
|
||||
path = Path("/${FOO}/${BAR}")
|
||||
assert resolve_path(path) == Path("/foo/bar")
|
||||
|
||||
|
||||
def test_resolve_relative_path():
|
||||
path = Path("foo/bar/baz")
|
||||
assert resolve_path(path) == path.resolve()
|
||||
|
||||
|
||||
def test_resolve_path_all():
|
||||
os.environ["FOO"] = "foo"
|
||||
os.environ["BAR"] = "bar"
|
||||
path = Path("foo/bar/$FOO/../$BAR")
|
||||
assert resolve_path(path) == Path(os.path.expandvars(path)).resolve().expanduser()
|
||||
Loading…
Add table
Add a link
Reference in a new issue