now with configuration
This commit is contained in:
parent
65b1520697
commit
34d26f7def
10 changed files with 497 additions and 83 deletions
131
tests/test_config.py
Normal file
131
tests/test_config.py
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
from pathlib import Path
|
||||
|
||||
from repub.config import (
|
||||
FeedConfig,
|
||||
RepublisherConfig,
|
||||
build_base_settings,
|
||||
build_feed_settings,
|
||||
load_config,
|
||||
)
|
||||
|
||||
|
||||
def test_load_config_resolves_relative_out_dir_against_config_path(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
config_path = tmp_path / "configs" / "repub.toml"
|
||||
config_path.parent.mkdir(parents=True)
|
||||
config_path.write_text(
|
||||
"""
|
||||
out_dir = "../mirror"
|
||||
|
||||
[[feeds]]
|
||||
name = "gp-pod"
|
||||
url = "https://guardianproject.info/podcast/podcast.xml"
|
||||
|
||||
[[feeds]]
|
||||
name = "nasa"
|
||||
url = "https://www.nasa.gov/rss/dyn/breaking_news.rss"
|
||||
""".strip()
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
config = load_config(config_path)
|
||||
|
||||
assert config.out_dir == (tmp_path / "mirror").resolve()
|
||||
assert config.feeds == (
|
||||
FeedConfig(
|
||||
name="gp-pod",
|
||||
url="https://guardianproject.info/podcast/podcast.xml",
|
||||
),
|
||||
FeedConfig(
|
||||
name="nasa",
|
||||
url="https://www.nasa.gov/rss/dyn/breaking_news.rss",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_load_config_preserves_absolute_out_dir(tmp_path: Path) -> None:
|
||||
absolute_out_dir = (tmp_path / "absolute-out").resolve()
|
||||
config_path = tmp_path / "repub.toml"
|
||||
config_path.write_text(
|
||||
f"""
|
||||
out_dir = "{absolute_out_dir}"
|
||||
|
||||
[[feeds]]
|
||||
name = "nasa"
|
||||
url = "https://www.nasa.gov/rss/dyn/breaking_news.rss"
|
||||
""".strip()
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
config = load_config(config_path)
|
||||
|
||||
assert config.out_dir == absolute_out_dir
|
||||
|
||||
|
||||
def test_build_feed_settings_derives_output_paths_from_out_dir(tmp_path: Path) -> None:
|
||||
out_dir = (tmp_path / "mirror").resolve()
|
||||
config = RepublisherConfig(
|
||||
config_path=tmp_path / "repub.toml",
|
||||
out_dir=out_dir,
|
||||
feeds=(
|
||||
FeedConfig(
|
||||
name="nasa",
|
||||
url="https://www.nasa.gov/rss/dyn/breaking_news.rss",
|
||||
),
|
||||
),
|
||||
scrapy_settings={"LOG_LEVEL": "DEBUG"},
|
||||
)
|
||||
|
||||
base_settings = build_base_settings(config)
|
||||
feed_settings = build_feed_settings(
|
||||
base_settings, out_dir=out_dir, feed_name="nasa"
|
||||
)
|
||||
|
||||
assert base_settings["LOG_LEVEL"] == "DEBUG"
|
||||
assert feed_settings["REPUBLISHER_OUT_DIR"] == str(out_dir)
|
||||
assert feed_settings["LOG_FILE"] == str(out_dir / "logs" / "nasa.log")
|
||||
assert feed_settings["HTTPCACHE_DIR"] == str(out_dir / "httpcache")
|
||||
assert feed_settings["IMAGES_STORE"] == str(out_dir / "nasa" / "images")
|
||||
assert feed_settings["AUDIO_STORE"] == str(out_dir / "nasa" / "audio")
|
||||
assert feed_settings["VIDEO_STORE"] == str(out_dir / "nasa" / "video")
|
||||
assert feed_settings["FILES_STORE"] == str(out_dir / "nasa" / "files")
|
||||
assert feed_settings["FEEDS"] == {
|
||||
str(out_dir / "nasa.rss"): {
|
||||
"format": "rss",
|
||||
"postprocessing": [],
|
||||
"feed_name": "nasa",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_build_feed_settings_uses_runtime_media_dir_overrides(tmp_path: Path) -> None:
|
||||
out_dir = (tmp_path / "mirror").resolve()
|
||||
config = RepublisherConfig(
|
||||
config_path=tmp_path / "repub.toml",
|
||||
out_dir=out_dir,
|
||||
feeds=(
|
||||
FeedConfig(
|
||||
name="gp-pod",
|
||||
url="https://guardianproject.info/podcast/podcast.xml",
|
||||
),
|
||||
),
|
||||
scrapy_settings={
|
||||
"REPUBLISHER_VIDEO_DIR": "videos-custom",
|
||||
"REPUBLISHER_AUDIO_DIR": "audio-custom",
|
||||
},
|
||||
)
|
||||
|
||||
base_settings = build_base_settings(config)
|
||||
feed_settings = build_feed_settings(
|
||||
base_settings,
|
||||
out_dir=out_dir,
|
||||
feed_name="gp-pod",
|
||||
)
|
||||
|
||||
assert feed_settings["REPUBLISHER_VIDEO_DIR"] == "videos-custom"
|
||||
assert feed_settings["REPUBLISHER_AUDIO_DIR"] == "audio-custom"
|
||||
assert feed_settings["VIDEO_STORE"] == str(out_dir / "gp-pod" / "videos-custom")
|
||||
assert feed_settings["AUDIO_STORE"] == str(out_dir / "gp-pod" / "audio-custom")
|
||||
Loading…
Add table
Add a link
Reference in a new issue