Example #1
0
    def test_add_remove(self):
        node1 = MagicMock(Node)
        node2 = MagicMock(Node)
        graph = MagicMock(Graph)
        node1.graph = graph
        node2.graph = graph
        branch = Branch(node1, node2, "1234")
        graph.add_branch.assert_called_once_with(branch)
        node1.add_outgoing_branch.assert_called_once_with(branch)
        node2.add_ingoing_branch.assert_called_once_with(branch)
        self.assertEqual(graph, branch.graph)

        branch.remove()
        self.assertIsNone(branch.graph)
        node1.remove_outgoing_branch.assert_called_once_with(branch)
        node2.remove_ingoing_branch.assert_called_once_with(branch)
Example #2
0
    def test_connect(self):
        node1 = MagicMock(Node)
        node2 = MagicMock(Node)
        graph = MagicMock(Graph)
        node1.graph = graph
        node2.graph = graph
        branch = Branch(node1, node2, "1234")
        branch.remove()

        node3 = MagicMock(Node)
        node4 = MagicMock(Node)
        node3.graph = graph
        node4.graph = graph

        branch.reconnect(node3, node4)
        self.assertEqual(graph, branch.graph)
        node3.add_outgoing_branch.assert_called_once_with(branch)
        node4.add_ingoing_branch.assert_called_once_with(branch)