def test_remove_lists_from_xml_dict_sub_elements_only_list_is_removed( self): # Arrange xml_dict = { "root": { "list": [{ "value": 1 }, { "value": 2 }], "int": 3, "str": "test", "dict": { "value": "test" }, } } # Act remove_lists_from_xml_dict(xml_dict) # Assert self.assertTrue( xml_dict == {"root": { "int": 3, "str": "test", "dict": { "value": "test" } }})
def test_remove_lists_from_xml_dict_empty_dict_does_nothing(self): # Arrange xml_dict = {} # Act remove_lists_from_xml_dict(xml_dict) # Assert self.assertTrue(xml_dict == {})
def test_remove_lists_from_xml_dict_sub_element_list_is_removed(self): # Arrange xml_dict = {"root": {"list": [{"value": 1}, {"value": 2}]}} # Act remove_lists_from_xml_dict(xml_dict) # Assert self.assertTrue(xml_dict == {"root": {}})
def test_remove_lists_from_xml_dict_sub_elements_only_list_is_removed( self): # Arrange xml_dict = { 'root': { 'list': [{ 'value': 1 }, { 'value': 2 }], 'int': 3, 'str': 'test', 'dict': { 'value': 'test' } } } # Act remove_lists_from_xml_dict(xml_dict) # Assert self.assertTrue( xml_dict == {'root': { 'int': 3, 'str': 'test', 'dict': { 'value': 'test' } }})
def test_remove_lists_from_xml_dict_sub_element_list_is_removed(self): # Arrange xml_dict = {'root': {'list': [{'value': 1}, {'value': 2}]}} # Act remove_lists_from_xml_dict(xml_dict) # Assert self.assertTrue(xml_dict == {'root': {}})
def test_remove_lists_from_xml_dict_root_list_is_not_removed_if_smaller_than_max_size( self, ): # Arrange xml_dict = {"list": [{"value": 1}, {"value": 2}]} # Act remove_lists_from_xml_dict(xml_dict, 3) # Assert self.assertTrue(xml_dict == {"list": [{"value": 1}, {"value": 2}]})
def test_remove_lists_from_xml_dict_root_list_is_not_removed_if_smaller_than_max_size( self): # Arrange xml_dict = {'list': [{'value': 1}, {'value': 2}]} # Act remove_lists_from_xml_dict(xml_dict, 3) # Assert self.assertTrue(xml_dict == {'list': [{'value': 1}, {'value': 2}]})
def convert_to_dict(self): """ Convert the xml contained in xml_content into a dictionary. Returns: """ # transform xml content into a dictionary dict_content = xml_utils.raw_xml_to_dict(self.xml_content, xml_utils.post_processor) # if limit on element occurrences is set if SEARCHABLE_DATA_OCCURRENCES_LIMIT is not None: # Remove lists which size exceed the limit size xml_utils.remove_lists_from_xml_dict(dict_content, SEARCHABLE_DATA_OCCURRENCES_LIMIT) # store dictionary self.dict_content = dict_content