From c9d1c7d3c34e53462e4564939490cec2e5c83a5b Mon Sep 17 00:00:00 2001 From: Stuart Maxwell Date: Thu, 30 May 2024 09:14:12 +1200 Subject: [PATCH] Add render_markdown tests --- tests/test_utils.py | 80 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index f37fcb3..a8f96bd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,9 @@ import pytest -from djpress.utils import get_author_display_name +from djpress.utils import get_author_display_name, render_markdown from django.contrib.auth.models import User +from djpress.conf import settings + # create a parameterized fixture for a test user with first name, last name, and username @pytest.fixture( @@ -44,3 +46,79 @@ def test_get_author_display_name(test_user): if not first_name and not last_name: assert display_name == user_name + + +def test_render_markdown_basic(): + markdown_text = "# Heading\n\nThis is some **bold** text. And this is *italic*.\n\nAnd a paragraph." + html = render_markdown(markdown_text) + + assert "

Heading

" in html + assert "bold" in html + assert "italic" in html + assert "

And a paragraph.

" in html + + +def test_render_markdown_link(): + markdown_text = "[DJ Press](https://github.com/stuartmaxwell/djpress/)" + html = render_markdown(markdown_text) + + assert 'DJ Press' in html + + +def test_render_markdown_link_with_title(): + markdown_text = ( + '[DJ Press](https://github.com/stuartmaxwell/djpress/ "DJ Press GitHub")' + ) + html = render_markdown(markdown_text) + + assert ( + 'DJ Press' + in html + ) + + +def test_render_markdown_image(): + markdown_text = ( + "![DJ Press Logo](https://github.com/stuartmaxwell/djpress/logo.png)" + ) + html = render_markdown(markdown_text) + + assert ( + 'DJ Press Logo' + in html + ) + + +def test_render_markdown_image_with_title(): + markdown_text = '![DJ Press Logo](https://github.com/stuartmaxwell/djpress/logo.png "DJ Press Logo")' + html = render_markdown(markdown_text) + + assert ( + 'DJ Press Logo' + in html + ) + + +def test_render_markdown_python_codehilite(): + markdown_text = """ +```python +print("Hello, DJ Press!") +```""" + html = render_markdown(markdown_text) + + output = ( + '
' + "
"
+        ""
+        ""
+        'print'
+        '('
+        '"Hello, DJ Press!"'
+        ')'
+        "\n"
+        ""
+        "
" + "
" + ) + + assert output in html