File tree 1 file changed +13
-8
lines changed
1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 3
3
"""
4
4
5
5
import unittest
6
+ from io import BytesIO
6
7
from unittest .mock import patch , Mock
7
8
from lxml import etree
8
9
15
16
load_definition_xml ,
16
17
format_filepath ,
17
18
file_to_xml ,
18
- XML_PARSER ,
19
19
)
20
20
21
21
@@ -137,10 +137,15 @@ def test_load_definition_xml(self, mock_load_file):
137
137
def test_format_filepath (self ):
138
138
self .assertEqual (format_filepath ("course" , "test_url" ), "course/test_url.xml" )
139
139
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' )
You can’t perform that action at this time.
0 commit comments