Skip to content

Commit c27f1d3

Browse files
committed
test: improve coverage
1 parent 46d4567 commit c27f1d3

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

lti_consumer/tests/unit/test_lti_xblock.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,18 +1989,59 @@ def runtime_service_side_effect(_block, service_name):
19891989
return mock_i18n_service
19901990
if service_name == 'configuration':
19911991
return mock_config_service
1992-
return None
1992+
return None # pragma: nocover
19931993

19941994
self.xblock.runtime.service.side_effect = runtime_service_side_effect
19951995

19961996
mock_course = Mock()
19971997
mock_course.display_name_with_default = "DemoX"
19981998
mock_course.display_org_with_default = "edX"
1999-
mock_course.lti_passports = ["lti_passport:key:secret"]
1999+
mock_course.lti_passports = ["lti_passport_name:key:secret"]
20002000
mock_get_course_by_id.return_value = mock_course
20012001

2002-
response = self.xblock.studio_view({})
2003-
self.assertEqual(response.js_init_fn, 'LtiConsumerXBlockInitStudio')
2002+
fragment = self.xblock.studio_view({})
2003+
self.assertEqual(fragment.js_init_fn, 'LtiConsumerXBlockInitStudio')
2004+
2005+
normalized_content = " ".join(fragment.content.split())
2006+
2007+
# Assert that the LTI passports are rendered in the fragment.
2008+
self.assertIn(
2009+
'<option value="lti_passport_name" > lti_passport_name </option>',
2010+
normalized_content,
2011+
)
2012+
2013+
@patch('lti_consumer.plugin.compat.get_course_by_id')
2014+
def test_studio_view_without_course(self, mock_get_course_by_id):
2015+
"""
2016+
Test that the studio view is reder correctly when there is no course (e.g. in a library).
2017+
"""
2018+
# Mock runtime services used by studio view
2019+
mock_i18n_service = gettext.NullTranslations()
2020+
mock_i18n_service.ugettext = mock_i18n_service.gettext
2021+
2022+
mock_config_service = Mock()
2023+
mock_config_service.configuration.lti_access_to_learners_editable.return_value = False
2024+
2025+
mock_get_course_by_id.return_value = None
2026+
2027+
def runtime_service_side_effect(_block, service_name):
2028+
if service_name == 'i18n':
2029+
return mock_i18n_service
2030+
if service_name == 'configuration':
2031+
return mock_config_service
2032+
return None # pragma: no cover
2033+
2034+
self.xblock.runtime.service.side_effect = runtime_service_side_effect
2035+
2036+
fragment = self.xblock.studio_view({})
2037+
2038+
normalized_content = " ".join(fragment.content.split())
2039+
2040+
# Assert that the lti_id field is disabled if the LTI passports is empty because we don't have a course.
2041+
self.assertIn(
2042+
'<select class="field-data-control" id="xb-field-edit-lti_id" name="lti_id" disabled >',
2043+
normalized_content,
2044+
)
20042045

20052046
@patch('lti_consumer.lti_xblock.LtiConsumerXBlock.get_lti_1p3_launch_data')
20062047
@patch('lti_consumer.api.get_lti_1p3_launch_info')

0 commit comments

Comments
 (0)