Skip to content

Commit

Permalink
fix: Improve lti_xblock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuipumu committed Jul 16, 2023
1 parent 28281d4 commit b8b3728
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lti_consumer/tests/unit/test_lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,11 @@ def setUp(self):

@patch.object(LtiConsumerXBlock, 'get_parameter_processors')
@patch('lti_consumer.lti_xblock.resolve_custom_parameter_template')
def test_get_lti_1p3_custom_parameters(self, mock_resolve_custom_parameter_template, get_parameter_processors_mock):
def test_get_lti_1p3_custom_parameters(
self,
mock_resolve_custom_parameter_template,
get_parameter_processors_mock,
):
"""
Test that get_lti_1p3_custom_parameters returns an dictionary of custom parameters
"""
Expand All @@ -1699,6 +1703,33 @@ def test_get_lti_1p3_custom_parameters(self, mock_resolve_custom_parameter_templ
processor_mock.assert_called_once_with(self.xblock)
mock_resolve_custom_parameter_template.assert_called_once_with(self.xblock, '${test}')

@patch.object(LtiConsumerXBlock, 'get_parameter_processors')
@patch('lti_consumer.lti_xblock.resolve_custom_parameter_template')
@patch('lti_consumer.lti_xblock.log.exception')
def test_get_lti_1p3_custom_parameters_with_invalid_processor(
self,
log_exception_mock,
mock_resolve_custom_parameter_template,
get_parameter_processors_mock,
):
"""
Test that get_lti_1p3_custom_parameters logs error when a paramater processor fails.
"""
processor_mock = Mock(side_effect=Exception())
get_parameter_processors_mock.return_value = [processor_mock]
mock_resolve_custom_parameter_template.return_value = ''
self.xblock.custom_parameters = ['test1=test', 'test2=${test}']

self.assertDictEqual(
self.xblock.get_lti_1p3_custom_parameters(),
{'test1': 'test', 'test2': ''},
)
get_parameter_processors_mock.assert_called_once_with()
log_exception_mock.assert_called_once_with(
'Error in XBlock LTI parameter processor "%s"', processor_mock,
)
mock_resolve_custom_parameter_template.assert_called_once_with(self.xblock, '${test}')

@ddt.idata(product([True, False], [True, False], [True, False], [True, False]))
@ddt.unpack
def test_get_lti_1p3_launch_data(
Expand Down

0 comments on commit b8b3728

Please sign in to comment.