import unittest from django.template import Context from ..processors import render_universal_segment, render_template class TestProcessors(unittest.TestCase): def setUp(self): self.context_data = { "document": { "organization": {"name": "Example Corp"}, "created_at": "2025-04-08", "third_party_vendor_access": 50 } } self.template_segments = [ { "segment_type": "example_segment", "content": [ { "title": "Main Title", "subtitle": "Subtitle 1", "description": "This is the first description.\n- Bullet 1\n- Bullet 2" }, { "subtitle": "Subtitle 2", "description": "This is the second description.\nAnother paragraph here." } ], "html": "

Custom HTML content with {{ document.organization.name }}

" } ] def test_render_universal_segment(self): segment = self.template_segments[0] result = render_universal_segment(segment, self.context_data) self.assertIn("

Custom HTML content with Example Corp

", result) def test_render_template(self): result = render_template(self.template_segments, self.context_data) self.assertIn('
', result) self.assertIn("Main Title", result) self.assertIn("Subtitle 1", result) self.assertIn("Custom HTML content with Example Corp", result) def test_empty_segment(self): segment = {"segment_type": "empty_segment", "content": []} result = render_universal_segment(segment, self.context_data) self.assertEqual(result, "") def test_missing_html(self): segment = { "segment_type": "no_html_segment", "content": [{"title": "Title Only"}] } result = render_universal_segment(segment, self.context_data) self.assertIn("Title Only", result) self.assertNotIn("
", result) def test_missing_content(self): segment = {"segment_type": "html_only", "html": "

Only HTML

"} result = render_universal_segment(segment, self.context_data) self.assertIn("

Only HTML

", result)