jack/tests/test_models.py

72 lines
1.4 KiB
Python

"""Tests associated to the models"""
from jack.models import Article, Section, Site
content = """---
title: This is a test article
description: Some fancy description
tags:
- python
- dev
- code
---
This is the content
```python
def this_is_a_python_function():
...
```
"""
def test_article_metadata():
article = Article(content, None, None)
assert article.title == "This is a test article"
assert article.description == "Some fancy description"
assert article.tags == ["python", "dev", "code"]
def test_article_content():
article = Article(content, None, None)
assert "title" not in article.content
def test_article_published_date():
article = Article(content, None, None)
assert article.published_date is None
def test_article_fenced_code():
article = Article(content, None, None)
assert """<pre><code class="language-python">""" in article.to_prose()
def test_section_add():
parent = Section("dev")
child = Section("code")
parent.add(child)
assert child.parent == parent
assert child in parent.sections.values()
assert child == parent.sections.get("code")
def test_add_existing_section():
parent = Section("dev")
child = Section("code")
parent.add(child)
other_child = Section("code")
parent.add(other_child)
assert len(parent.sections) == 1
def test_site_append_article():
site = Site(".")
article = site.add(content)
assert article in site.articles
assert "python" in site.tags
assert article in site.tags.get("python")