summaryrefslogtreecommitdiffstats
path: root/tests/test_models.py
blob: 3d83653b55cee184fb1c637702bf39d7d1cca025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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


def test_article_draft_property():
    fm = {"draft": True, "type": "Tech", "tags": ["linux"], "categories": ["DIY"], "date": "2024-01-15T10:00:00+00:00"}
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
    assert a.draft is True


def test_article_meta_type():
    fm = {"type": "Tech"}
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
    assert a.meta_type == "Tech"


def test_article_meta_type_missing():
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter={}, has_translation=False, translation_path=None)
    assert a.meta_type == ""


def test_article_meta_tags():
    fm = {"tags": ["linux", "python"]}
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
    assert a.meta_tags == "linux, python"


def test_article_meta_tags_empty():
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter={}, has_translation=False, translation_path=None)
    assert a.meta_tags == ""


def test_article_meta_categories():
    fm = {"categories": ["DIY", "Tech"]}
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
    assert a.meta_categories == "DIY, Tech"


def test_article_meta_date():
    fm = {"date": "2024-01-15T10:00:00+00:00"}
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
    assert a.meta_date == "2024-01-15"


def test_article_meta_date_missing():
    a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter={}, has_translation=False, translation_path=None)
    assert a.meta_date == ""