Add to_dict and to_file API to SiteConfig
This commit is contained in:
1 parent
b97487eb4b
commit
278d3e937e
2 files changed
+70
No files matched your search
@@ -58,6 +58,48 @@ def test_from_dict_full():
|
||||
assert config.base_dir == Path("/blog")
|
||||
|
||||
|
||||
def test_to_dict():
|
||||
config = SiteConfig(
|
||||
name="My Site",
|
||||
origin="http://example.com",
|
||||
base_dir=Path("/blog"),
|
||||
items_per_page=42,
|
||||
template="plain",
|
||||
)
|
||||
|
||||
assert config.to_dict() == {
|
||||
"name": "My Site",
|
||||
"template": "plain",
|
||||
"items_per_page": 42,
|
||||
"base_url": "http://example.com/blog",
|
||||
}
|
||||
|
||||
|
||||
def test_to_dict_default_base_url():
|
||||
config = SiteConfig(
|
||||
name="My Site",
|
||||
origin="",
|
||||
base_dir=Path("/"),
|
||||
items_per_page=DEFAULT_ITEMS_PER_PAGE,
|
||||
template="plain",
|
||||
)
|
||||
|
||||
assert config.to_dict()["base_url"] == "/"
|
||||
|
||||
|
||||
def test_to_dict_round_trip():
|
||||
original = SiteConfig.from_dict(
|
||||
{
|
||||
"name": "My Site",
|
||||
"template": "plain",
|
||||
"base_url": "http://example.com/blog",
|
||||
"items_per_page": 42,
|
||||
}
|
||||
)
|
||||
|
||||
assert SiteConfig.from_dict(original.to_dict()) == original
|
||||
|
||||
|
||||
MISSING = object()
|
||||
|
||||
|
||||
@@ -128,6 +170,21 @@ def test_from_file_full(tmp_path):
|
||||
assert config.base_dir == Path("/blog")
|
||||
|
||||
|
||||
def test_to_file(tmp_path):
|
||||
path = tmp_path / "config.yml"
|
||||
config = SiteConfig(
|
||||
name="My Site",
|
||||
origin="http://example.com",
|
||||
base_dir=Path("/blog"),
|
||||
items_per_page=42,
|
||||
template="plain",
|
||||
)
|
||||
|
||||
config.to_file(path)
|
||||
|
||||
assert SiteConfig.from_file(path) == config
|
||||
|
||||
|
||||
def test_from_file_missing(tmp_path):
|
||||
path = tmp_path / "config.yml"
|
||||
|
||||
|
||||
Reference in new issue
Block a user