feat(export): add csv/json article export with date relevance scoring

This commit is contained in:
Oliver 2026-02-18 10:04:38 +01:00
parent 5159a6e3b4
commit 6691db8051
7 changed files with 224 additions and 0 deletions

View file

@ -72,6 +72,73 @@ class TestApiAuth(unittest.TestCase):
self.assertFalse(body["allowed"])
self.assertGreaterEqual(len(body["issues"]), 1)
def test_articles_export_json_and_csv_contains_relevance(self) -> None:
login = self.client.post("/auth/login", json={"username": "admin", "password": "secret"})
self.assertEqual(login.status_code, 200)
source = self.client.post(
"/api/sources",
json={
"name": "Export Source",
"base_url": "https://example.org",
"terms_url": "https://example.org/terms",
"license_name": "cc-by",
"risk_level": "green",
"is_enabled": True,
"last_reviewed_at": "2026-02-18T00:00:00Z",
},
)
self.assertEqual(source.status_code, 200)
source_id = source.json()["id"]
feed = self.client.post(
"/api/feeds",
json={"name": "Export Feed", "url": "https://example.org/feed.xml", "source_id": source_id, "is_enabled": True},
)
self.assertEqual(feed.status_code, 200)
feed_id = feed.json()["id"]
article = self.client.post(
"/api/articles/upsert",
json={
"feed_id": feed_id,
"source_article_id": "exp-1",
"source_hash": "exp-hash-1",
"title": "Export Artikel",
"source_url": "https://example.org/article/1",
"canonical_url": "https://example.org/article/1",
"published_at": "2026-02-18T00:00:00Z",
"author": "Autor",
"summary": "Kurz",
"content_raw": "Langtext",
"image_urls_json": "[\"https://example.org/img.jpg\"]",
"press_contact": "Kontakt",
"source_name_snapshot": "Export Source",
"source_terms_url_snapshot": "https://example.org/terms",
"source_license_name_snapshot": "cc-by",
"status": "review",
},
)
self.assertEqual(article.status_code, 200)
export_json = self.client.get("/api/articles/export?format=json")
self.assertEqual(export_json.status_code, 200)
body = export_json.json()
self.assertTrue(body.get("ok"))
self.assertGreaterEqual(body.get("count", 0), 1)
first = body["items"][0]
self.assertIn("published_at", first)
self.assertIn("days_old", first)
self.assertIn("relevance", first)
export_csv = self.client.get("/api/articles/export?format=csv")
self.assertEqual(export_csv.status_code, 200)
self.assertIn("text/csv", export_csv.headers.get("content-type", ""))
csv_text = export_csv.text
self.assertIn("published_at", csv_text)
self.assertIn("days_old", csv_text)
self.assertIn("relevance", csv_text)
if __name__ == "__main__":
unittest.main()