From da66f2ddc6a389bd4bf9c16b0375df9c4d616173 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Fri, 24 Oct 2025 17:20:46 +0000 Subject: [PATCH] Add comprehensive unit tests for rendering functions - Test text rendering with markdown - Test unordered and ordered lists - Test table rendering - Test diagram rendering (success and error cases) - Test diagram with custom options - Test code blocks - Test edge cases (empty content, no type) - Test multiple sections - Test md_table_to_html function - Integration tests for mixed content --- abschnitte/tests.py | 378 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 376 insertions(+), 2 deletions(-) diff --git a/abschnitte/tests.py b/abschnitte/tests.py index 7ce503c..93a0813 100644 --- a/abschnitte/tests.py +++ b/abschnitte/tests.py @@ -1,3 +1,377 @@ -from django.test import TestCase +from unittest.mock import Mock, patch, MagicMock +from django.test import TestCase, override_settings +from abschnitte.models import AbschnittTyp, Textabschnitt +from abschnitte.utils import render_textabschnitte, md_table_to_html -# Create your tests here. + +class MockTextabschnitt: + """Mock object for Textabschnitt (since it's abstract).""" + def __init__(self, abschnitttyp, inhalt): + self.abschnitttyp = abschnitttyp + self.inhalt = inhalt + + +class RenderTextabschnitteTestCase(TestCase): + """Test cases for render_textabschnitte function.""" + + def setUp(self): + """Set up test fixtures.""" + # Create mock AbschnittTyp objects + self.typ_text = Mock() + self.typ_text.abschnitttyp = "text" + + self.typ_liste_ungeordnet = Mock() + self.typ_liste_ungeordnet.abschnitttyp = "liste ungeordnet" + + self.typ_liste_geordnet = Mock() + self.typ_liste_geordnet.abschnitttyp = "liste geordnet" + + self.typ_tabelle = Mock() + self.typ_tabelle.abschnitttyp = "tabelle" + + self.typ_diagramm = Mock() + self.typ_diagramm.abschnitttyp = "diagramm" + + self.typ_code = Mock() + self.typ_code.abschnitttyp = "code" + + def test_render_basic_text(self): + """Test rendering basic text content.""" + abschnitt = MockTextabschnitt( + abschnitttyp=self.typ_text, + inhalt="This is **bold** text with *italic*." + ) + + result = render_textabschnitte([abschnitt]) + + self.assertEqual(len(result), 1) + typ, html = result[0] + self.assertEqual(typ, "text") + self.assertIn("bold", html) + self.assertIn("italic", html) + + def test_render_unordered_list(self): + """Test rendering unordered list.""" + abschnitt = MockTextabschnitt( + abschnitttyp=self.typ_liste_ungeordnet, + inhalt="Item 1\nItem 2\nItem 3" + ) + + result = render_textabschnitte([abschnitt]) + + self.assertEqual(len(result), 1) + typ, html = result[0] + self.assertEqual(typ, "liste ungeordnet") + self.assertIn("