64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
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": "<div><p>Custom HTML content with {{ document.organization.name }}</p></div>"
|
|
}
|
|
]
|
|
|
|
def test_render_universal_segment(self):
|
|
segment = self.template_segments[0]
|
|
result = render_universal_segment(segment, self.context_data)
|
|
self.assertIn("<h2>", result)
|
|
self.assertIn("<h3>", result)
|
|
self.assertIn("<ul style=", result)
|
|
self.assertIn("<div><p>Custom HTML content with Example Corp</p></div>", result)
|
|
|
|
def test_render_template(self):
|
|
result = render_template(self.template_segments, self.context_data)
|
|
self.assertIn('<div class="section">', 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, '<div class="section">\n</div>')
|
|
|
|
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("<div>", result)
|
|
|
|
def test_missing_content(self):
|
|
segment = {"segment_type": "html_only", "html": "<p>Only HTML</p>"}
|
|
result = render_universal_segment(segment, self.context_data)
|
|
self.assertIn("<p>Only HTML</p>", result) |