def test_setTextContent_no_childNodes(self): """Tests setTextContent when it has childNodes""" _node = MagicMock(childNodes=[]) _childNodes = PropertyMock(return_value=iter([])) type(_node).childNodes = _childNodes _text_object = MagicMock() _dom_text = self._init_patch_with_name( '_dom_text', 'xmind.core.DOM.Text', return_value=_text_object, autospec=True) _element = Element(_node) _element.setTextContent('data2') _node.appendChild.assert_called_once_with(_text_object) _dom_text.assert_called_once() _node.removeChild.assert_not_called() _text_object.data = 'data2' _childNodes.assert_called_once()
def test_setTextContent_has_childNodes(self): """Tests setTextContent when it has childNodes""" _childNodesValues = [ InnerNode(0, '0'), InnerNode(3, '3'), InnerNode(3, '16'), InnerNode(1, '1') ] _node = MagicMock() _childNodes = PropertyMock(return_value=iter(_childNodesValues)) type(_node).childNodes = _childNodes _text_object = MagicMock() _dom_text = self._init_patch_with_name( '_dom_text', 'xmind.core.DOM.Text', return_value=_text_object, autospec=True) _element = Element(_node) _element.setTextContent('data2') _node.appendChild.assert_called_once_with(_text_object) self.assertEqual(_node.removeChild.call_count, 2) self.assertListEqual(_node.removeChild.call_args_list, [ call(_childNodesValues[1]), call(_childNodesValues[2])]) _dom_text.assert_called_once() _text_object.data = 'data2' _childNodes.assert_called_once()