""" Articles: titles and summaries stored apart from the text (v2.16.0, ADR-076). Feeds give only articles a title and never repeat it in the content; the homepage and tag pages show an article as title, summary and "Read more" without its images; the admin editor has Title and Summary fields. """ import json import xml.etree.ElementTree as ET import mf2py from starpunk.auth import create_session from starpunk.notes import create_note, get_note from tests.test_micropub_v240 import SITE, app, client, h # noqa: F401 from tests.test_micropub_v265 import upload ATOM = {"a": "http://www.w3.org/2005/Atom"} def micropub(client, h, **props): response = client.post("/micropub", json={"type": ["h-entry"], "properties": props}, headers=h) assert response.status_code == 201, response.get_json() return response.headers["Location"] def make_both(app): with app.app_context(): article = create_note(content="The **body**.", title="An Article", summary="The gist.", published=True, tags=["essay"]) note = create_note(content="# Just a heading\n\nin a note", published=True, tags=["essay"]) return article, note class TestFeeds: def test_rss_title_only_for_articles(self, app, client): article, note = make_both(app) items = {i.find("link").text: i for i in ET.fromstring(client.get("/feed.rss").data).iter("item")} a, n = items[f"{SITE}/note/{article.slug}"], items[f"{SITE}/note/{note.slug}"] assert a.find("title").text == "An Article" assert "An Article" not in a.find("description").text # not repeated in the body assert n.find("title") is None assert n.find("description") is not None def test_atom_empty_title_and_summary(self, app, client): article, note = make_both(app) entries = {e.find("a:id", ATOM).text: e for e in ET.fromstring(client.get("/feed.atom").data).findall("a:entry", ATOM)} a, n = entries[f"{SITE}/note/{article.slug}"], entries[f"{SITE}/note/{note.slug}"] assert a.find("a:title", ATOM).text == "An Article" assert a.find("a:summary", ATOM).text == "The gist." assert "An Article" not in a.find("a:content", ATOM).text assert n.find("a:title", ATOM) is not None and not n.find("a:title", ATOM).text assert n.find("a:summary", ATOM) is None def test_json_feed(self, app, client): article, note = make_both(app) items = {i["url"]: i for i in json.loads(client.get("/feed.json").data)["items"]} a, n = items[f"{SITE}/note/{article.slug}"], items[f"{SITE}/note/{note.slug}"] assert (a["title"], a["summary"]) == ("An Article", "The gist.") assert "An Article" not in a["content_html"] assert "title" not in n and "summary" not in n assert "