Update tests to check old signature of Block.get_template

pull/10948/head
Matt Westcott 2023-10-16 20:50:25 +01:00
rodzic 247fc467eb
commit 8af4774ff0
1 zmienionych plików z 18 dodań i 23 usunięć

Wyświetl plik

@ -28,6 +28,7 @@ from wagtail.test.testapp.blocks import LinkBlock as CustomLinkBlock
from wagtail.test.testapp.blocks import SectionBlock from wagtail.test.testapp.blocks import SectionBlock
from wagtail.test.testapp.models import EventPage, SimplePage from wagtail.test.testapp.models import EventPage, SimplePage
from wagtail.test.utils import WagtailTestUtils from wagtail.test.utils import WagtailTestUtils
from wagtail.utils.deprecation import RemovedInWagtail60Warning
class FooStreamBlock(blocks.StreamBlock): class FooStreamBlock(blocks.StreamBlock):
@ -5184,37 +5185,31 @@ class TestIncludeBlockTag(TestCase):
self.assertIn("<body>some <em>evil</em> HTML</body>", result) self.assertIn("<body>some <em>evil</em> HTML</body>", result)
class BlockUsingGetTemplateMethod(blocks.Block):
my_new_template = "my_super_awesome_dynamic_template.html"
def get_template(self, value=None, context=None):
return self.my_new_template
class BlockChoosingTemplateBasedOnValue(blocks.Block):
last_value = None
def get_template(self, value=None, context=None):
self.last_value = value
if value == "HEADING":
return "tests/blocks/heading_block.html"
return None # using render_basic
class TestOverriddenGetTemplateBlockTag(TestCase): class TestOverriddenGetTemplateBlockTag(TestCase):
def test_template_is_overridden_by_get_template(self): def test_get_template_old_signature(self):
class BlockUsingGetTemplateMethod(blocks.Block):
my_new_template = "tests/blocks/heading_block.html"
def get_template(self, context=None):
return self.my_new_template
block = BlockUsingGetTemplateMethod( block = BlockUsingGetTemplateMethod(
template="tests/blocks/this_shouldnt_be_used.html" template="tests/blocks/this_shouldnt_be_used.html"
) )
template = block.get_template() with self.assertWarns(RemovedInWagtail60Warning):
self.assertEqual(template, block.my_new_template) html = block.render("Hello World")
self.assertEqual(html, "<h1>Hello World</h1>")
def test_block_render_passes_the_value_argument_to_get_template(self): def test_block_render_passes_the_value_argument_to_get_template(self):
"""verifies Block.render() passes the value to get_template""" """verifies Block.render() passes the value to get_template"""
class BlockChoosingTemplateBasedOnValue(blocks.Block):
def get_template(self, value=None, context=None):
if value == "HEADING":
return "tests/blocks/heading_block.html"
return None # using render_basic
block = BlockChoosingTemplateBasedOnValue() block = BlockChoosingTemplateBasedOnValue()
html = block.render("Hello World") html = block.render("Hello World")