53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from repub.config import feed_output_path, staged_feed_output_path
|
||
|
|
from repub.postprocessing import publish_staged_feed
|
||
|
|
|
||
|
|
VALID_FEED = '<rss version="2.0"><channel><title>new</title></channel></rss>\n'
|
||
|
|
|
||
|
|
|
||
|
|
def test_publish_staged_feed_replaces_public_feed(tmp_path: Path) -> None:
|
||
|
|
out_dir = tmp_path / "out"
|
||
|
|
public_path = feed_output_path(out_dir=out_dir, feed_slug="demo")
|
||
|
|
staged_path = staged_feed_output_path(out_dir=out_dir, feed_slug="demo")
|
||
|
|
public_path.parent.mkdir(parents=True)
|
||
|
|
public_path.write_text("<rss>old</rss>\n", encoding="utf-8")
|
||
|
|
staged_path.write_text(VALID_FEED, encoding="utf-8")
|
||
|
|
|
||
|
|
published_path = publish_staged_feed(out_dir=out_dir, feed_slug="demo")
|
||
|
|
|
||
|
|
assert published_path == public_path
|
||
|
|
assert public_path.read_text(encoding="utf-8") == VALID_FEED
|
||
|
|
assert not staged_path.exists()
|
||
|
|
|
||
|
|
|
||
|
|
def test_publish_staged_feed_requires_staged_file(tmp_path: Path) -> None:
|
||
|
|
with pytest.raises(FileNotFoundError):
|
||
|
|
publish_staged_feed(out_dir=tmp_path / "out", feed_slug="missing")
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(
|
||
|
|
"staged_feed",
|
||
|
|
[
|
||
|
|
'<rss version="2.0"/>\n',
|
||
|
|
'<rss version="2.0"><channel></rss>\n',
|
||
|
|
],
|
||
|
|
)
|
||
|
|
def test_publish_staged_feed_rejects_unusable_feed(
|
||
|
|
tmp_path: Path, staged_feed: str
|
||
|
|
) -> None:
|
||
|
|
out_dir = tmp_path / "out"
|
||
|
|
public_path = feed_output_path(out_dir=out_dir, feed_slug="demo")
|
||
|
|
staged_path = staged_feed_output_path(out_dir=out_dir, feed_slug="demo")
|
||
|
|
public_path.parent.mkdir(parents=True)
|
||
|
|
public_path.write_text("<rss>old</rss>\n", encoding="utf-8")
|
||
|
|
staged_path.write_text(staged_feed, encoding="utf-8")
|
||
|
|
|
||
|
|
with pytest.raises(ValueError):
|
||
|
|
publish_staged_feed(out_dir=out_dir, feed_slug="demo")
|
||
|
|
|
||
|
|
assert public_path.read_text(encoding="utf-8") == "<rss>old</rss>\n"
|
||
|
|
assert staged_path.read_text(encoding="utf-8") == staged_feed
|