feat: Mastodon Post Composition and Publishing
This commit is contained in:
@@ -8,9 +8,22 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from datetime import date
|
||||
|
||||
from tenbackward import main as main_module
|
||||
from tenbackward.logging_setup import JsonFormatter
|
||||
from tenbackward.main import main
|
||||
from tenbackward.matching import MatchedPost
|
||||
from tenbackward.publishing import PublishError
|
||||
|
||||
|
||||
def _match(path: str) -> MatchedPost:
|
||||
return MatchedPost(
|
||||
path=path,
|
||||
title=path,
|
||||
date=date(2016, 8, 4),
|
||||
url=f"https://blog.example.com/2016/08/04/{path.split('-', 3)[-1].removesuffix('.md')}/",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@@ -38,7 +51,11 @@ def _seed_state(data_dir: Path, ids: list[str]) -> None:
|
||||
def test_run_emits_one_info_summary_on_success(env_setup, data_dir, capture_logger, monkeypatch) -> None:
|
||||
monkeypatch.setenv("DATA_DIR", str(data_dir))
|
||||
|
||||
monkeypatch.setattr(main_module, "_iter_candidates", lambda config: ["new-1", "already-1"])
|
||||
def _stub_publish(config, posts, **_kwargs):
|
||||
return "stubbed"
|
||||
|
||||
monkeypatch.setattr(main_module, "_iter_candidates", lambda config: [_match("new-1"), _match("already-1")])
|
||||
monkeypatch.setattr(main_module, "publish_mastodon", _stub_publish)
|
||||
|
||||
_seed_state(data_dir, ["already-1"])
|
||||
|
||||
@@ -100,7 +117,12 @@ def test_run_distinguishes_posted_from_skipped_via_ids(env_setup, data_dir, capt
|
||||
monkeypatch.setattr(
|
||||
main_module,
|
||||
"_iter_candidates",
|
||||
lambda config: ["alpha", "beta", "gamma"],
|
||||
lambda config: [_match("alpha"), _match("beta"), _match("gamma")],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
main_module,
|
||||
"publish_mastodon",
|
||||
lambda config, posts, **_kwargs: "stubbed",
|
||||
)
|
||||
_seed_state(data_dir, ["beta"])
|
||||
|
||||
@@ -114,3 +136,28 @@ def test_run_distinguishes_posted_from_skipped_via_ids(env_setup, data_dir, capt
|
||||
assert "beta" not in payload["posted_ids"]
|
||||
assert payload["skipped"] == 1
|
||||
assert payload["posted"] == 2
|
||||
|
||||
|
||||
def test_run_publish_failure_leaves_state_untouched(
|
||||
env_setup, data_dir, capture_logger, monkeypatch
|
||||
) -> None:
|
||||
monkeypatch.setenv("DATA_DIR", str(data_dir))
|
||||
|
||||
def _boom(config, posts, **_kwargs):
|
||||
raise PublishError("publish_failed: stub")
|
||||
|
||||
monkeypatch.setattr(main_module, "_iter_candidates", lambda config: [_match("alpha")])
|
||||
monkeypatch.setattr(main_module, "publish_mastodon", _boom)
|
||||
|
||||
rc = main()
|
||||
assert rc != 0
|
||||
|
||||
from tenbackward.state import load_posted
|
||||
|
||||
assert load_posted(data_dir) == []
|
||||
error_lines = [
|
||||
line
|
||||
for line in _run_lines(capture_logger)
|
||||
if line.get("level") == "ERROR"
|
||||
]
|
||||
assert any(line.get("event") == "pipeline_error" for line in error_lines)
|
||||
|
||||
Reference in New Issue
Block a user