refactor: use MakoService.render_template to remove deprecation warnings

from test code.
This commit is contained in:
Jillian Vogel
2021-10-05 14:51:45 +10:30
parent 8d62d337f5
commit 26b43465a4
3 changed files with 28 additions and 22 deletions

View File

@@ -169,6 +169,7 @@ class GetPreviewHtmlTestCase(ModuleStoreTestCase):
@XBlock.needs("field-data")
@XBlock.needs("i18n")
@XBlock.needs("mako")
@XBlock.needs("user")
@XBlock.needs("teams_configuration")
class PureXBlock(XBlock):
@@ -180,7 +181,7 @@ class PureXBlock(XBlock):
Renders the output that a student will see.
"""
fragment = Fragment()
fragment.add_content(self.runtime.render_template('edxmako.html', context))
fragment.add_content(self.runtime.service(self, 'mako').render_template('edxmako.html', context))
return fragment

View File

@@ -166,7 +166,8 @@ class ConditionalBlockBasicTest(unittest.TestCase):
# because get_test_system returns the repr of the context dict passed to render_template,
# we reverse it here
html = modules['cond_module'].render(STUDENT_VIEW).content
expected = modules['cond_module'].xmodule_runtime.render_template('conditional_ajax.html', {
mako_service = modules['cond_module'].xmodule_runtime.service(modules['cond_module'], 'mako')
expected = mako_service.render_template('conditional_ajax.html', {
'ajax_url': modules['cond_module'].ajax_url,
'element_id': 'i4x-edX-conditional_test-conditional-SampleConditional',
'depends': 'i4x-edX-conditional_test-problem-SampleProblem',
@@ -241,7 +242,8 @@ class ConditionalBlockXmlTest(unittest.TestCase):
module = self.get_module_for_location(location)
html = module.render(STUDENT_VIEW).content
html_expect = module.xmodule_runtime.render_template(
mako_service = module.xmodule_runtime.service(module, 'mako')
html_expect = mako_service.render_template(
'conditional_ajax.html',
{
# Test ajax url is just usage-id / handler_name

View File

@@ -130,9 +130,9 @@ class TestVideoYouTube(TestVideo): # lint-amnesty, pylint: disable=missing-clas
'poster': 'null',
}
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
class TestVideoNonYouTube(TestVideo): # pylint: disable=test-inherits-tests
@@ -211,8 +211,9 @@ class TestVideoNonYouTube(TestVideo): # pylint: disable=test-inherits-tests
'poster': 'null',
}
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
expected_result = get_context_dict_from_string(
self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context)
mako_service.render_template('video.html', expected_context)
)
assert get_context_dict_from_string(context) == expected_result
assert expected_result['download_video_link'] == 'example.mp4'
@@ -383,9 +384,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
'metadata': json.dumps(metadata)
})
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
def test_get_html_source(self):
# lint-amnesty, pylint: disable=invalid-name, redefined-outer-name
@@ -491,9 +492,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
'metadata': json.dumps(expected_context['metadata'])
})
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
def test_get_html_with_non_existent_edx_video_id(self):
"""
@@ -631,9 +632,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
'metadata': json.dumps(expected_context['metadata'])
})
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
def test_get_html_with_existing_edx_video_id(self):
"""
@@ -659,9 +660,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
# context returned by get_html when provided with above data
# expected_context, a dict to assert with context
context, expected_context = self.helper_get_html_with_edx_video_id(data)
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
def test_get_html_with_existing_unstripped_edx_video_id(self):
"""
@@ -690,9 +691,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
# expected_context, a dict to assert with context
context, expected_context = self.helper_get_html_with_edx_video_id(data)
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
def encode_and_create_video(self, edx_video_id):
"""
@@ -899,9 +900,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
'metadata': json.dumps(expected_context['metadata'])
})
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
# pylint: disable=invalid-name
def test_get_html_cdn_source_external_video(self):
@@ -1001,9 +1002,9 @@ class TestGetHtmlMethod(BaseTestVideoXBlock):
'metadata': json.dumps(expected_context['metadata'])
})
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
assert get_context_dict_from_string(context) ==\
get_context_dict_from_string(self.item_descriptor.xmodule_runtime.render_template('video.html',
expected_context))
get_context_dict_from_string(mako_service.render_template('video.html', expected_context))
@ddt.data(
(True, ['youtube', 'desktop_webm', 'desktop_mp4', 'hls']),
@@ -2234,7 +2235,8 @@ class TestVideoWithBumper(TestVideo): # pylint: disable=test-inherits-tests
}))
}
expected_content = self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context)
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
expected_content = mako_service.render_template('video.html', expected_context)
assert get_context_dict_from_string(content) == get_context_dict_from_string(expected_content)
@@ -2325,8 +2327,9 @@ class TestAutoAdvanceVideo(TestVideo): # lint-amnesty, pylint: disable=test-inh
autoadvance_flag=autoadvance_must_be,
)
mako_service = self.item_descriptor.xmodule_runtime.service(self.item_descriptor, 'mako')
with override_settings(FEATURES=self.FEATURES):
expected_content = self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context)
expected_content = mako_service.render_template('video.html', expected_context)
assert get_context_dict_from_string(content) == get_context_dict_from_string(expected_content)