grimboite/tests/test_models.py

45 lines
1.4 KiB
Python

"""Checks structure associated with articles."""
from datetime import date
from grnx.models import get_date_from_article_filename
from grnx.models import Article
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
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