73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from pygea.config import load_config
|
|
|
|
|
|
def test_load_config_resolves_relative_paths_and_preserves_feed_fields(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
config_path = tmp_path / "configs" / "pygea.toml"
|
|
config_path.parent.mkdir(parents=True)
|
|
config_path.write_text(
|
|
"""
|
|
domain = "www.martinoticias.com"
|
|
default_content_type = "articles"
|
|
|
|
[[feeds]]
|
|
name = "Info Martí "
|
|
slug = "info-marti"
|
|
only_newest = false
|
|
content_type = "articles"
|
|
|
|
[runtime]
|
|
api_key = "demo-key"
|
|
max_articles = 25
|
|
oldest_article = 7
|
|
verbose_p = false
|
|
|
|
[results]
|
|
output_directory = "../feed-out"
|
|
output_file_name = "rss.xml"
|
|
|
|
[logging]
|
|
log_file = "../logs/pygea.log"
|
|
default_log_level = "INFO"
|
|
""".strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
config = load_config(config_path)
|
|
|
|
assert config.domain == "www.martinoticias.com"
|
|
assert config.default_content_type == "articles"
|
|
assert config.results.output_directory == (tmp_path / "feed-out").resolve()
|
|
assert config.logging.log_file == (tmp_path / "logs" / "pygea.log").resolve()
|
|
assert config.feeds == (
|
|
{
|
|
"name": "Info Martí ",
|
|
"slug": "info-marti",
|
|
"only_newest": False,
|
|
"content_type": "articles",
|
|
},
|
|
)
|
|
|
|
|
|
def test_load_config_rejects_invalid_slug(tmp_path: Path) -> None:
|
|
config_path = tmp_path / "pygea.toml"
|
|
config_path.write_text(
|
|
"""
|
|
domain = "www.martinoticias.com"
|
|
|
|
[[feeds]]
|
|
name = "Titulares"
|
|
slug = "bad slug"
|
|
""".strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="Feed slug"):
|
|
load_config(config_path)
|