def test_deletion_event_on_new_node_should_remote_it(self): tree = FakeIndexTree() builder = HintBuilder() builder.apply_modified_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C", "NEW STATE", FakeNode) builder.apply_deleted_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C") assert tree.get_node_by_path("A/B/C") is None
def test_deletion_on_missing_node(self): """Deletion should do nothing if the file don't exists.""" tree = FakeIndexTree() builder = HintBuilder() builder.apply_deleted_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C") assert tree.get_node_by_path("A/B/C") is None
def test_deletion_event_on_empty_node(self): """Should add the DeletedHint.""" builder = HintBuilder() node = FakeNode("C") tree = FakeIndexTree({"A/B/C": node}) builder.apply_deleted_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C") assert isinstance(node.remote_hint, DeletedHint) assert node.local_hint is None
def test_deletion_event_on_modified_node(self): """It should delete the node anyway.""" builder = HintBuilder() node = FakeNode("C") tree = FakeIndexTree({"A/B/C": node}) builder.apply_modified_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C", "STATE", FakeNode) builder.apply_deleted_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C") assert isinstance(node.local_hint, DeletedHint)
def test_modification_event_on_deleted_node(self): """Should replace the deleted event.""" builder = HintBuilder() node = FakeNode("C") tree = FakeIndexTree({"A/B/C": node}) builder.apply_deleted_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C") builder.apply_modified_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C", "STATE", FakeNode) assert isinstance(node.local_hint, ModifiedHint) assert node.local_hint.new_data == "STATE"
def test_move_event_to_existing_deleted_node(self): """It should replace the destination node.""" builder = HintBuilder() src_node = FakeNode("A") dest_node = FakeNode("B") tree = FakeIndexTree({"A": src_node, "B": dest_node}) builder.apply_deleted_event(tree, HintBuilder.SCOPE_LOCAL, "B") builder.apply_move_event(tree, HintBuilder.SCOPE_LOCAL, "A", "B", FakeNode) assert isinstance(src_node.local_hint, SourceMoveHint) assert isinstance(dest_node.local_hint, DestMoveHint) assert dest_node.local_hint.source_node is src_node assert src_node.local_hint.dest_node is dest_node
def test_deletion_event_on_moved_src_node(self): """It should do nothing. The target has moved: it's already gone, there is nothing to delete. """ builder = HintBuilder() source_node = FakeNode("C") tree = FakeIndexTree({"A/B/C": source_node}) builder.apply_move_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C", "D/E/F", FakeNode) builder.apply_deleted_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C") assert isinstance(source_node.remote_hint, SourceMoveHint) dest_node = tree.get_node_by_path("D/E/F") assert isinstance(dest_node.remote_hint, DestMoveHint)
def test_deletion_event_on_moved_dest_node(self): """Should mark both node as deleted. After the move, the source node don't point to something anymore. After the delete, the destination node is also gone: both node should have a "deleted" hint. If the destination didn't exist before the move, the node should be removed. """ builder = HintBuilder() source_node = FakeNode("C") tree = FakeIndexTree({"A/B/C": source_node}) builder.apply_move_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C", "D/E/F", FakeNode) builder.apply_deleted_event(tree, HintBuilder.SCOPE_REMOTE, "D/E/F") assert isinstance(source_node.remote_hint, DeletedHint) assert tree.get_node_by_path("D/E/F") is None
def test_move_event_from_deleted_node(self): """It should set a "Modified" hint for destination node. This is a unusual case: the source can't be moved if it's been deleted before. As we can't know what happened, the destination node's hint will be "Modified", without state. The source node's hint is "Deleted" anyway. """ builder = HintBuilder() src_node = FakeNode("C", remote_state="STATE?") tree = FakeIndexTree({"A/B/C": src_node}) builder.apply_deleted_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C") builder.apply_move_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C", "D/E/F", FakeNode) assert isinstance(src_node.remote_hint, DeletedHint) dest_node = tree.get_node_by_path("D/E/F") assert isinstance(dest_node.remote_hint, ModifiedHint) assert dest_node.remote_hint.new_data is None