]> danix's work - publisher.git/commitdiff
feat: Article dataclass and ARTICLE_TYPES
authorDanilo M. <redacted>
Fri, 1 May 2026 10:47:22 +0000 (12:47 +0200)
committerDanilo M. <redacted>
Fri, 1 May 2026 10:47:22 +0000 (12:47 +0200)
core/models.py [new file with mode: 0644]
tests/test_models.py [new file with mode: 0644]

diff --git a/core/models.py b/core/models.py
new file mode 100644 (file)
index 0000000..3df2088
--- /dev/null
@@ -0,0 +1,15 @@
+from __future__ import annotations
+from dataclasses import dataclass
+from pathlib import Path
+
+ARTICLE_TYPES = ["Life", "Photo", "Link", "Quote", "Tech"]
+
+
+@dataclass
+class Article:
+    slug: str
+    lang: str          # "it" | "en"
+    path: Path
+    frontmatter: dict
+    has_translation: bool
+    translation_path: Path | None
diff --git a/tests/test_models.py b/tests/test_models.py
new file mode 100644 (file)
index 0000000..858ce21
--- /dev/null
@@ -0,0 +1,36 @@
+from pathlib import Path
+from core.models import Article, ARTICLE_TYPES
+
+
+def test_article_types_contains_five():
+    assert len(ARTICLE_TYPES) == 5
+    assert "Tech" in ARTICLE_TYPES
+    assert "Life" in ARTICLE_TYPES
+
+
+def test_article_fields():
+    a = Article(
+        slug="test-post",
+        lang="it",
+        path=Path("/blog/content/it/articles/test-post/index.md"),
+        frontmatter={"title": "Test", "type": "Tech"},
+        has_translation=False,
+        translation_path=None,
+    )
+    assert a.slug == "test-post"
+    assert a.lang == "it"
+    assert a.has_translation is False
+    assert a.translation_path is None
+
+
+def test_article_with_translation():
+    a = Article(
+        slug="test-post",
+        lang="it",
+        path=Path("/blog/content/it/articles/test-post/index.md"),
+        frontmatter={},
+        has_translation=True,
+        translation_path=Path("/blog/content/en/articles/test-post/index.md"),
+    )
+    assert a.has_translation is True
+    assert a.translation_path is not None