grnx/tests/test_models.py

63 lines
2.1 KiB
Python

"""Checks structure associated with articles."""
from datetime import date
from grnx.models import get_date_from_article_filename, split
from grnx.models import Article
def test_split_path():
assert split('articles/sys/2018-01-01 Scaleway Review.md') == ['articles', 'sys', '2018-01-01 Scaleway Review.md']
def test_filename():
article = Article("2019-01-01-blabla.md", "")
assert "2019-01-01-blabla" == article.filename_without_extension
assert "2019-01-01-blabla.md" == article.filename
def test_article_match_date():
"""Checks that a date can be extracted from a filename."""
assert get_date_from_article_filename('2018-09-01-test.md') == date(2018, 9, 1)
assert get_date_from_article_filename('2017-02-30-divinity-origin-sin.md') == None
assert get_date_from_article_filename('lynis.md') == None
assert get_date_from_article_filename('2018-01-01 scaleway-review.md') == date(2018, 1, 1)
def test_article_slug():
"""Check the article slug is well built."""
assert "scaleway-review" == Article('articles/sys/2018-01-01 Scaleway Review.md', '').slug
def test_article_category():
"""Asserts that the category of an article is found, based on the filepath."""
assert "home" == Article('articles/home/2019-01-01-blabla.md', "").category
assert "dev" == Article('articles/dev/python/django/2019-01-01-blabla.md', "").category
assert '' == Article('articles', "").category
def test_article_keywords():
"""Asserts that the keywords of an article are found, based on the filepath."""
article = Article('articles/dev/python/django/2019-01-01-blabla.md', "")
assert "python" in article.keywords
assert "django" in article.keywords
assert "dev" not in article.keywords
article = Article('articles/dev/2019-01-01-blabla.md', "")
assert len(article.keywords) == 0
def test_article_properties():
article = Article('articles/dev/python/django/2019-01-01-blabla.md', "")
assert article.filename == '2019-01-01-blabla.md'
assert article.filename_without_extension == '2019-01-01-blabla'
assert article.slug == 'blabla'
assert article.publication_date == date(2019, 1, 1)