33from django .template import Context
44from django .test import RequestFactory , TestCase , modify_settings , override_settings
55
6- from render_block import BlockNotFound , UnsupportedEngine , render_block_to_string
6+ from render_block import (
7+ BlockNotFound ,
8+ UnsupportedEngine ,
9+ render_block ,
10+ render_block_to_string ,
11+ )
712
813
914class TestDjango (TestCase ):
@@ -174,6 +179,20 @@ def test_request_context(self) -> None:
174179
175180 self .assertEqual (result , "/dummy-url" )
176181
182+ @modify_settings (
183+ INSTALLED_APPS = {
184+ "prepend" : [
185+ "django.contrib.auth" ,
186+ "django.contrib.contenttypes" ,
187+ ],
188+ },
189+ )
190+ def test_render_block (self ) -> None :
191+ """Test rendering an individual block to a response."""
192+ request = RequestFactory ().get ("dummy-url" )
193+ response = render_block (request , "test1.html" , "block1" )
194+ self .assertEqual (response .content , b"block1 from test1" )
195+
177196
178197@override_settings (
179198 TEMPLATES = [
@@ -185,7 +204,7 @@ def test_request_context(self) -> None:
185204 ]
186205)
187206class TestJinja2 (TestCase ):
188- """Test the Django templating engine."""
207+ """Test the Jinja2 templating engine."""
189208
190209 def assertExceptionMessageEquals (self , exception : Exception , expected : str ) -> None :
191210 self .assertEqual (expected , exception .args [0 ])
@@ -271,3 +290,17 @@ def test_context(self) -> None:
271290 data = "block2 from test5"
272291 result = render_block_to_string ("test5.html" , "block2" , {"foo" : data })
273292 self .assertEqual (result , data )
293+
294+ @modify_settings (
295+ INSTALLED_APPS = {
296+ "prepend" : [
297+ "django.contrib.auth" ,
298+ "django.contrib.contenttypes" ,
299+ ],
300+ },
301+ )
302+ def test_render_block (self ) -> None :
303+ """Test rendering an individual block to a response."""
304+ request = RequestFactory ().get ("dummy-url" )
305+ response = render_block (request , "test1.html" , "block1" )
306+ self .assertEqual (response .content , b"block1 from test1" )
0 commit comments