Skip to content

Commit fe49706

Browse files
committed
test: update test_file_to_xml
1 parent 573d7f1 commit fe49706

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

xblock/test/utils/test_helpers.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import unittest
6+
from io import BytesIO
67
from unittest.mock import patch, Mock
78
from lxml import etree
89

@@ -15,7 +16,6 @@
1516
load_definition_xml,
1617
format_filepath,
1718
file_to_xml,
18-
XML_PARSER,
1919
)
2020

2121

@@ -137,10 +137,15 @@ def test_load_definition_xml(self, mock_load_file):
137137
def test_format_filepath(self):
138138
self.assertEqual(format_filepath("course", "test_url"), "course/test_url.xml")
139139

140-
@patch("xblock.utils.helpers.etree.parse")
141-
def test_file_to_xml(self, mock_etree_parse):
142-
mock_etree_parse.return_value.getroot.return_value = "mock_xml_root"
143-
file_object = Mock()
144-
result = file_to_xml(file_object)
145-
self.assertEqual(result, "mock_xml_root")
146-
mock_etree_parse.assert_called_once_with(file_object, parser=XML_PARSER)
140+
def test_file_to_xml(self):
141+
"""Test that `file_to_xml` correctly parses XML from a file object."""
142+
# Create a BytesIO object
143+
file_obj = BytesIO(b"<root><child>Value</child></root>")
144+
145+
# Parse the XML
146+
result = file_to_xml(file_obj)
147+
148+
# Verify the result
149+
self.assertEqual(result.tag, 'root')
150+
self.assertEqual(result[0].tag, 'child')
151+
self.assertEqual(result[0].text, 'Value')

0 commit comments

Comments
 (0)