84 lines
2 KiB
Python
84 lines
2 KiB
Python
import tomllib
|
|
from pathlib import Path
|
|
|
|
from pygea import main as main_module
|
|
|
|
|
|
class StubPangeaFeed:
|
|
def __init__(self, config, feeds):
|
|
self.config = config
|
|
self.feed = feeds[0]
|
|
|
|
def acquire_content(self) -> None:
|
|
return None
|
|
|
|
def generate_feed(self) -> None:
|
|
return None
|
|
|
|
def disgorge(self, slug: str):
|
|
output_path = self.config.results.output_directory / slug / "rss.xml"
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
output_path.write_text("<rss />\n", encoding="utf-8")
|
|
return output_path
|
|
|
|
|
|
def test_main_writes_manifest_toml_with_absolute_file_urls(
|
|
tmp_path: Path, monkeypatch
|
|
) -> None:
|
|
config_path = tmp_path / "pygea.toml"
|
|
config_path.write_text(
|
|
"""
|
|
domain = "www.martinoticias.com"
|
|
|
|
[[feeds]]
|
|
name = "Info Martí "
|
|
slug = "info-marti"
|
|
only_newest = false
|
|
|
|
[[feeds]]
|
|
name = "Titulares"
|
|
slug = "titulares"
|
|
only_newest = true
|
|
content_type = "articles"
|
|
|
|
[runtime]
|
|
api_key = "demo-key"
|
|
verbose_p = false
|
|
|
|
[results]
|
|
output_directory = "feed"
|
|
output_file_name = "rss.xml"
|
|
|
|
[logging]
|
|
log_file = "logs/pygea.log"
|
|
default_log_level = "INFO"
|
|
""".strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
monkeypatch.setattr(main_module, "feed_class", lambda: StubPangeaFeed)
|
|
|
|
exit_code = main_module.main(["--config", str(config_path)])
|
|
|
|
manifest_path = tmp_path / "feed" / "manifest.toml"
|
|
assert exit_code == 0
|
|
assert manifest_path.exists()
|
|
|
|
manifest = tomllib.loads(manifest_path.read_text(encoding="utf-8"))
|
|
assert manifest == {
|
|
"feeds": [
|
|
{
|
|
"name": "Info Martí ",
|
|
"slug": "info-marti",
|
|
"url": (tmp_path / "feed" / "info-marti" / "rss.xml")
|
|
.resolve()
|
|
.as_uri(),
|
|
},
|
|
{
|
|
"name": "Titulares",
|
|
"slug": "titulares",
|
|
"url": (tmp_path / "feed" / "titulares" / "rss.xml").resolve().as_uri(),
|
|
},
|
|
]
|
|
}
|