File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 33"""
44
55import unittest
6+ from io import BytesIO
67from unittest .mock import patch , Mock
78from lxml import etree
89
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' )
You can’t perform that action at this time.
0 commit comments