mirror of
https://github.com/django-components/django-components.git
synced 2025-12-03 20:00:02 +00:00
tests: Split test files and run template tests under both context behavior modes (#509)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
8bbe81d717
commit
95f6554f4c
13 changed files with 3392 additions and 3339 deletions
|
|
@ -8,7 +8,7 @@ from django.urls import path
|
|||
|
||||
# isort: off
|
||||
from .django_test_setup import * # noqa
|
||||
from .testutils import BaseTestCase
|
||||
from .testutils import BaseTestCase, parametrize_context_behavior
|
||||
|
||||
# isort: on
|
||||
|
||||
|
|
@ -113,6 +113,7 @@ class TestComponentAsView(BaseTestCase):
|
|||
response.content,
|
||||
)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_replace_slot_in_view(self):
|
||||
class MockComponentSlot(component.Component):
|
||||
template = """
|
||||
|
|
@ -141,6 +142,7 @@ class TestComponentAsView(BaseTestCase):
|
|||
response.content,
|
||||
)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_replace_slot_in_view_with_insecure_content(self):
|
||||
class MockInsecureComponentSlot(component.Component):
|
||||
template = """
|
||||
|
|
@ -162,6 +164,28 @@ class TestComponentAsView(BaseTestCase):
|
|||
response.content,
|
||||
)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_replace_context_in_view(self):
|
||||
class TestComponent(component.Component):
|
||||
template = """
|
||||
{% load component_tags %}
|
||||
<div>
|
||||
Hey, I'm {{ name }}
|
||||
</div>
|
||||
"""
|
||||
|
||||
def get(self, request, *args, **kwargs) -> HttpResponse:
|
||||
return self.render_to_response({"name": "Bob"})
|
||||
|
||||
client = CustomClient(urlpatterns=[path("test_context_django/", TestComponent.as_view())])
|
||||
response = client.get("/test_context_django/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn(
|
||||
b"Hey, I'm Bob",
|
||||
response.content,
|
||||
)
|
||||
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_replace_context_in_view_with_insecure_content(self):
|
||||
class MockInsecureComponentContext(component.Component):
|
||||
template = """
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue