|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import unittest |
6 | | -from io import BytesIO |
7 | | -from unittest.mock import patch, Mock |
8 | | -from lxml import etree |
9 | 6 |
|
10 | 7 | from xblock.core import XBlock |
11 | 8 | from xblock.test.toy_runtime import ToyRuntime |
12 | | -from xblock.utils.helpers import ( |
13 | | - child_isinstance, |
14 | | - name_to_pathname, |
15 | | - is_pointer_tag, |
16 | | - load_definition_xml, |
17 | | - format_filepath, |
18 | | - file_to_xml, |
19 | | -) |
| 9 | +from xblock.utils.helpers import child_isinstance |
20 | 10 |
|
21 | 11 |
|
22 | 12 | # pylint: disable=unnecessary-pass |
@@ -88,64 +78,3 @@ def test_child_isinstance_descendants(self): |
88 | 78 | self.assertTrue(child_isinstance(root, block.children[1], DogXBlock)) |
89 | 79 | self.assertTrue(child_isinstance(root, block.children[1], GoldenRetrieverXBlock)) |
90 | 80 | self.assertFalse(child_isinstance(root, block.children[1], CatXBlock)) |
91 | | - |
92 | | - |
93 | | -class TestPointerTagParsing(unittest.TestCase): |
94 | | - """ |
95 | | - Tests for core functions in XBlock. |
96 | | - """ |
97 | | - def test_name_to_pathname(self): |
98 | | - self.assertEqual(name_to_pathname("course:subcourse"), "course/subcourse") |
99 | | - self.assertEqual(name_to_pathname("module:lesson:part"), "module/lesson/part") |
100 | | - self.assertEqual(name_to_pathname("no_colon"), "no_colon") |
101 | | - |
102 | | - def test_is_pointer_tag(self): |
103 | | - # Case 1: Valid pointer tag |
104 | | - xml_obj = etree.Element("some_tag", url_name="test_url") |
105 | | - self.assertTrue(is_pointer_tag(xml_obj)) |
106 | | - |
107 | | - # Case 2: Valid course pointer tag |
108 | | - xml_obj = etree.Element("course", url_name="test_url", course="test_course", org="test_org") |
109 | | - self.assertTrue(is_pointer_tag(xml_obj)) |
110 | | - |
111 | | - # Case 3: Invalid case - extra attribute |
112 | | - xml_obj = etree.Element("some_tag", url_name="test_url", extra_attr="invalid") |
113 | | - self.assertFalse(is_pointer_tag(xml_obj)) |
114 | | - |
115 | | - # Case 4: Invalid case - has text |
116 | | - xml_obj = etree.Element("some_tag", url_name="test_url") |
117 | | - xml_obj.text = "invalid_text" |
118 | | - self.assertFalse(is_pointer_tag(xml_obj)) |
119 | | - |
120 | | - # Case 5: Invalid case - has children |
121 | | - xml_obj = etree.Element("some_tag", url_name="test_url") |
122 | | - _ = etree.SubElement(xml_obj, "child") |
123 | | - self.assertFalse(is_pointer_tag(xml_obj)) |
124 | | - |
125 | | - @patch("xblock.utils.helpers.load_file") |
126 | | - def test_load_definition_xml(self, mock_load_file): |
127 | | - mock_load_file.return_value = "<mock_xml />" |
128 | | - node = etree.Element("course", url_name="test_url") |
129 | | - runtime = Mock() |
130 | | - def_id = "mock_id" |
131 | | - |
132 | | - definition_xml, filepath = load_definition_xml(node, runtime, def_id) |
133 | | - self.assertEqual(filepath, "course/test_url.xml") |
134 | | - self.assertEqual(definition_xml, "<mock_xml />") |
135 | | - mock_load_file.assert_called_once() |
136 | | - |
137 | | - def test_format_filepath(self): |
138 | | - self.assertEqual(format_filepath("course", "test_url"), "course/test_url.xml") |
139 | | - |
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