Skip to content

Commit

Permalink
Merge pull request #111 from eduNEXT/and/fix_invalid_markdown
Browse files Browse the repository at this point in the history
fix: validate markdown type
  • Loading branch information
andrey-canon authored Nov 27, 2023
2 parents 7912e54 + 1bd5577 commit d620155
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions eox_nelp/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_course_id_found(self, course_overviews_mock):
course_overviews_mock.assert_called_once_with([CourseKey.from_string(course_id)])


@ddt
class GetItemLabelTestCase(TestCase):
"""Test class for the get_item_lable method."""

Expand All @@ -116,6 +117,20 @@ def test_item_does_not_have_markdown(self):

self.assertEqual("", label)

@data(None, 14, object)
def test_invalid_markdown_type(self, markdown):
""" Test when the markdown attribute is different from a string type.
Expected behavior:
- Returns an empty string
"""
fake_item = Mock()
fake_item.markdown = markdown

label = get_item_label(fake_item)

self.assertEqual("", label)

def test_returns_label(self):
""" Test that the method finds and returns the label for the given item.
Expand Down
2 changes: 1 addition & 1 deletion eox_nelp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_item_label(item):
Returns:
label <string>: Label data if it's found otherwise empty string.
"""
if not hasattr(item, "markdown"):
if not (hasattr(item, "markdown") and isinstance(item.markdown, str)):
return ""

regex = re.compile(r'>>\s*(.*?)\s*<<')
Expand Down

0 comments on commit d620155

Please sign in to comment.