mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 06:18:17 +00:00
refactor: Use top-level exports as public API (#562)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
d819f3ff49
commit
e771a0aaaf
30 changed files with 615 additions and 598 deletions
|
@ -9,7 +9,7 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.http import HttpResponse
|
||||
from django.template import Context, Template, TemplateSyntaxError
|
||||
|
||||
from django_components import component, types
|
||||
from django_components import Component, registry, types
|
||||
from django_components.slots import SlotRef
|
||||
|
||||
from .django_test_setup import setup_test_config
|
||||
|
@ -19,7 +19,7 @@ setup_test_config({"autodiscover": False})
|
|||
|
||||
|
||||
class ComponentTest(BaseTestCase):
|
||||
class ParentComponent(component.Component):
|
||||
class ParentComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
<div>
|
||||
|
@ -39,7 +39,7 @@ class ComponentTest(BaseTestCase):
|
|||
def get_context_data(self):
|
||||
return {"shadowing_variable": "NOT SHADOWED"}
|
||||
|
||||
class VariableDisplay(component.Component):
|
||||
class VariableDisplay(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
<h1>Shadowing variable = {{ shadowing_variable }}</h1>
|
||||
|
@ -56,12 +56,12 @@ class ComponentTest(BaseTestCase):
|
|||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
component.registry.register(name="parent_component", component=self.ParentComponent)
|
||||
component.registry.register(name="variable_display", component=self.VariableDisplay)
|
||||
registry.register(name="parent_component", component=self.ParentComponent)
|
||||
registry.register(name="variable_display", component=self.VariableDisplay)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_empty_component(self):
|
||||
class EmptyComponent(component.Component):
|
||||
class EmptyComponent(Component):
|
||||
pass
|
||||
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
|
@ -69,7 +69,7 @@ class ComponentTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_template_string_static_inlined(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
Variable: <strong>{{ variable }}</strong>
|
||||
"""
|
||||
|
@ -93,7 +93,7 @@ class ComponentTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_template_string_dynamic(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
def get_template_string(self, context):
|
||||
content: types.django_html = """
|
||||
Variable: <strong>{{ variable }}</strong>
|
||||
|
@ -119,7 +119,7 @@ class ComponentTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_template_name_static(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template_name = "simple_template.html"
|
||||
|
||||
def get_context_data(self, variable=None):
|
||||
|
@ -141,7 +141,7 @@ class ComponentTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_template_name_dynamic(self):
|
||||
class SvgComponent(component.Component):
|
||||
class SvgComponent(Component):
|
||||
def get_context_data(self, name, css_class="", title="", **attrs):
|
||||
return {
|
||||
"name": name,
|
||||
|
@ -168,7 +168,7 @@ class ComponentTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_allows_to_override_get_template(self):
|
||||
class TestComponent(component.Component):
|
||||
class TestComponent(Component):
|
||||
def get_context_data(self, variable, **attrs):
|
||||
return {
|
||||
"variable": variable,
|
||||
|
@ -190,7 +190,7 @@ class ComponentTest(BaseTestCase):
|
|||
class ComponentRenderTest(BaseTestCase):
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_minimal(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
the_arg2: {{ the_arg2 }}
|
||||
|
@ -230,7 +230,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_full(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
the_arg: {{ the_arg }}
|
||||
|
@ -283,7 +283,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_to_response_full(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
the_arg: {{ the_arg }}
|
||||
|
@ -342,7 +342,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
def __init__(self, content: str) -> None:
|
||||
self.content = bytes(content, "utf-8")
|
||||
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
response_class = MyResponse
|
||||
template: types.django_html = "HELLO"
|
||||
|
||||
|
@ -358,7 +358,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
def test_render_slot_as_func(self, context_behavior_data):
|
||||
is_isolated = context_behavior_data
|
||||
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% slot "first" required data1="abc" data2:hello="world" data2:one=123 %}
|
||||
|
@ -414,7 +414,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_raises_on_missing_slot(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% slot "first" required %}
|
||||
|
@ -430,7 +430,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_with_include(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% include 'slotted_template.html' %}
|
||||
|
@ -450,7 +450,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_with_extends(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
{% extends 'block.html' %}
|
||||
{% block body %}
|
||||
|
@ -478,7 +478,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_can_access_instance(self):
|
||||
class TestComponent(component.Component):
|
||||
class TestComponent(Component):
|
||||
template = "Variable: <strong>{{ id }}</strong>"
|
||||
|
||||
def get_context_data(self, **attrs):
|
||||
|
@ -494,7 +494,7 @@ class ComponentRenderTest(BaseTestCase):
|
|||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_render_to_response_can_access_instance(self):
|
||||
class TestComponent(component.Component):
|
||||
class TestComponent(Component):
|
||||
template = "Variable: <strong>{{ id }}</strong>"
|
||||
|
||||
def get_context_data(self, **attrs):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue