예제 #1
0
    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
예제 #2
0
    def test_modification_event_on_empty_node(self):
        """Should add the ModifiedHint."""
        builder = HintBuilder()
        node = FakeNode("C")
        tree = FakeIndexTree({"A/B/C": node})

        builder.apply_modified_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C", "NEW STATE", FakeNode)
        assert isinstance(node.local_hint, ModifiedHint)
        assert node.local_hint.new_data == "NEW STATE"
        assert node.remote_hint is None
예제 #3
0
    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)
예제 #4
0
    def test_modification_event_on_missing_node(self):
        """Should create a new node."""
        tree = FakeIndexTree()
        builder = HintBuilder()

        builder.apply_modified_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C", "NEW STATE", FakeNode)

        node = tree.get_node_by_path("A/B/C")
        assert isinstance(node.local_hint, ModifiedHint)
        assert node.local_hint.new_data == "NEW STATE"
        assert node.remote_hint is None
예제 #5
0
    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"
예제 #6
0
    def test_modification_event_on_modified_node(self):
        """Should Replace the first modification."""
        builder = HintBuilder()
        node = FakeNode("C")
        tree = FakeIndexTree({"A/B/C": node})

        builder.apply_modified_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C", "STATE 1", FakeNode)
        builder.apply_modified_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C", "STATE 2", FakeNode)

        assert isinstance(node.remote_hint, ModifiedHint)
        assert node.remote_hint.new_data == "STATE 2"
        assert node.local_hint is None
예제 #7
0
    def test_move_event_to_existing_modified_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_modified_event(tree, HintBuilder.SCOPE_LOCAL, "B", "state", FakeNode)
        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
예제 #8
0
    def test_modification_event_on_moved_dst_node(self):
        """Should rewrite both move hints.

        The destination node's hint is replaced by the new one. The source
        node has moved, which is equivalent to a deletion.
        """
        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_modified_event(tree, HintBuilder.SCOPE_REMOTE, "D/E/F", "STATE", FakeNode)

        assert isinstance(source_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 == "STATE"
예제 #9
0
    def test_move_event_from_modified_node(self):
        """It should do the move with "Deleted" and "Modified" hints.

        The source node should be "Deleted". The destination node should be
        "Modified", and should keep the data the source node had before the
        move.
        """
        builder = HintBuilder()
        src_node = FakeNode("C")
        tree = FakeIndexTree({"A/B/C": src_node})

        builder.apply_modified_event(tree, HintBuilder.SCOPE_REMOTE, "A/B/C", "NEW STATE", FakeNode)
        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 == "NEW STATE"
예제 #10
0
    def test_modification_event_on_moved_src_node(self):
        """Should rewrite both move hints.

        The source hint should be replaced by the new ModifiedHint. The
        destination node's hint should be converted in a ModifiedHint.
        There is too much changes to use the "move" information, as we don't
        have the source.
        """
        builder = HintBuilder()
        node = FakeNode("C", local_state="INITIAL STATE")
        tree = FakeIndexTree({"A/B/C": node})

        builder.apply_move_event(tree, HintBuilder.SCOPE_LOCAL, "A/B/C", "D/E/F", FakeNode)
        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"
        dest_node = tree.get_node_by_path("D/E/F")
        assert isinstance(dest_node.local_hint, ModifiedHint)
        assert dest_node.local_hint.new_data == "INITIAL STATE"