Migrate remaining Component() callers to Element; delete the shim
The legacy back-compat ``Component(tag_name=...)`` function (a thin
string-returning wrapper over ``Element``) was the last piece of the
pre-node-tree API. Migrate its ~18 call sites across the views to the node
builders and remove it:
- stats_content.py: the table helpers now use the whitelisted ``Td`` / ``Th``
/ ``Tr`` builders and ``Element`` for table/tbody/thead/h1; helper return
types are ``Node``.
- auth.py / statuschange.py / game.py / purchase.py: the hand-built
``<form>`` / ``<button>`` / ``<h1>`` / ``<h2>`` / ``<table>`` markup now uses
``Element("tag", ...)``.
- core.py: drop the ``Component()`` function and its back-compat note;
``common/components/__init__`` no longer exports it.
- Tests that exercised the shim now target ``Element`` directly
(test_components cache/escaping/edge-case classes; test_node_tree drops the
legacy-parity and legacy-bridge cases, which ``Element`` coverage subsumes).
- CLAUDE.md: drop the "legacy Component retained for back-compat" notes.
Full suite green (443; one obsolete legacy-bridge test removed).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+3
-18
@@ -1,17 +1,14 @@
|
||||
"""Phase 1: the lazy node layer (Node/Element/Safe/Fragment/BaseComponent/Media).
|
||||
|
||||
These cover the new machinery directly and assert byte-for-byte parity between
|
||||
``Element`` and the legacy ``Component()`` shim, so the migration of call sites
|
||||
in later phases can rely on identical output.
|
||||
These cover the new machinery directly: rendering, escaping, media bubbling.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from django.utils.safestring import SafeText, mark_safe
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from common.components import (
|
||||
BaseComponent,
|
||||
Component,
|
||||
Element,
|
||||
Fragment,
|
||||
Media,
|
||||
@@ -23,12 +20,8 @@ from common.components import (
|
||||
|
||||
|
||||
class ElementRenderTest(unittest.TestCase):
|
||||
def test_matches_legacy_component(self):
|
||||
def test_renders_tag_attrs_children(self):
|
||||
element = Element("div", [("class", "test")], "hello")
|
||||
legacy = Component(
|
||||
tag_name="div", attributes=[("class", "test")], children="hello"
|
||||
)
|
||||
self.assertEqual(render(element), legacy)
|
||||
self.assertEqual(render(element), '<div class="test">hello</div>')
|
||||
|
||||
def test_plain_string_children_escaped(self):
|
||||
@@ -48,14 +41,6 @@ class ElementRenderTest(unittest.TestCase):
|
||||
render(Element("span", children=[inner])), "<span><b>x</b></span>"
|
||||
)
|
||||
|
||||
def test_legacy_component_renders_node_children(self):
|
||||
# The compatibility bridge: a string-returning legacy Component must
|
||||
# render nested Node children as HTML, not escape them.
|
||||
inner = Element("b", children=["x"])
|
||||
result = Component(tag_name="span", children=[inner])
|
||||
self.assertEqual(result, "<span><b>x</b></span>")
|
||||
self.assertIsInstance(result, SafeText)
|
||||
|
||||
|
||||
class SafeAndFragmentTest(unittest.TestCase):
|
||||
def test_safe_passes_html_through(self):
|
||||
|
||||
Reference in New Issue
Block a user