def test_update_edge(self):
        # prepare
        edge_repository_mock = EdgeRepositoryMock()
        edge_business_service = EdgeBusinessService(edge_repository_mock)
        edge_model = EdgeModel()

        updated_edge_name = 'UpdatedEdgeName'
        updated_edge_cost = 31
        updated_start_node_id = 9

        edge_model.edge_name = updated_edge_name
        edge_model.edge_cost = updated_edge_cost
        edge_model.start_node_id = updated_start_node_id
        edge_model.edge_id = edge_repository_mock.first_edge_id
        edge_model.end_node_id = edge_repository_mock.first_end_node_id
        edge_model.graph_id = edge_repository_mock.graph_id

        # act
        resulted_edge_model = edge_business_service.update_edge(edge_model)

        # assert returned type is GraphModel
        self.assertEqual(type(resulted_edge_model), EdgeModel)

        # assert same instance of node_model is returned
        self.assertEqual(resulted_edge_model, edge_model)

        # assert updated properties did not change
        self.assertEqual(resulted_edge_model.edge_name, updated_edge_name)
        self.assertEqual(resulted_edge_model.edge_cost, updated_edge_cost)
        self.assertEqual(resulted_edge_model.start_node_id, updated_start_node_id)
Beispiel #2
0
 def db_entity_to_edge_model(db_entity: tuple) -> EdgeModel:
     edge_model = EdgeModel()
     edge_model.edge_id = db_entity[0]
     edge_model.edge_name = db_entity[1]
     edge_model.edge_cost = db_entity[2]
     edge_model.start_node_id = db_entity[3]
     edge_model.end_node_id = db_entity[4]
     edge_model.graph_id = db_entity[5]
     return edge_model
    def test_insert_edge(self):
        # prepare
        edge_repository_mock = EdgeRepositoryMock()
        edge_business_service = EdgeBusinessService(edge_repository_mock)
        edge_model = EdgeModel()

        edge_name = 'TestEdgeName0'
        edge_cost = 13
        start_node_id = 3
        end_node_id = 5
        graph_id = 1

        edge_model.edge_name = edge_name
        edge_model.edge_cost = edge_cost
        edge_model.start_node_id = start_node_id
        edge_model.end_node_id = end_node_id
        edge_model.graph_id = graph_id

        # act
        result_edge_model = edge_business_service.insert_edge(edge_model)

        # assert edge_model is returned
        self.assertEqual(type(result_edge_model), EdgeModel)

        # assert id is the same
        self.assertEqual(result_edge_model.edge_id, edge_repository_mock.first_edge_id)
Beispiel #4
0
    def test_save_graph_model(self):

        # prepare
        graph_business_service_mock = GraphBusinessServiceMock()
        node_business_service_mock = NodeBusinessServiceMock()
        edge_business_service_mock = EdgeBusinessServiceMock()

        graph_model = GraphModel()
        graph_application_service = GraphApplicationService(
            graph_business_service_mock, node_business_service_mock,
            edge_business_service_mock)

        # act

        # insert graph_model

        graph_application_service.save_graph_model(graph_model)

        # add nodes to graph.list_of_nodes
        node1 = NodeModel()
        node1.node_id = -1
        node2 = NodeModel()
        node2.node_id = -2
        graph_model.list_of_nodes.append(node1)
        graph_model.list_of_nodes.append(node2)

        # add edges
        edge1 = EdgeModel()
        edge1.start_node_id = node1.node_id
        edge1.end_node_id = node2.node_id

        node1.start_edges.append(edge1)
        node2.end_edges.append(edge1)

        # insert node_models
        graph_application_service.save_graph_model(graph_model)

        # assert
        self.assertEqual(graph_model.graph_id,
                         graph_business_service_mock.graph_model_id)
        self.assertEqual(graph_model.list_of_nodes[0].node_id,
                         node_business_service_mock.node_id)
        self.assertEqual(graph_model.list_of_nodes[0].start_edges[0].edge_id,
                         edge_business_service_mock.edge_id)
    def set_edge_model(self, start_node: NodeModel,
                       end_node: NodeModel) -> EdgeModel:
        edge_model = EdgeModel(edge_name='EdgeName')
        self.set_id(edge_model)

        edge_model.start_node_id = start_node.node_id
        edge_model.start_node = start_node
        start_node.start_edges.append(edge_model)

        edge_model.end_node_id = end_node.node_id
        edge_model.end_node = end_node
        end_node.end_edges.append(edge_model)
        return edge_model
 def insert_edge(self, edge_model: EdgeModel) -> EdgeModel:
     edge_model.edge_id = self.edge_id
     return edge_model
 def get_edge_models_of_node(self, node_id: int) -> list:
     edge_model = EdgeModel()
     edge_model.edge_id = self.edge_id
     edge_model.start_node_id = node_id
     return [edge_model]
 def get_edge_model(self, edge_id: int) -> EdgeModel:
     edge_model = EdgeModel()
     edge_model.edge_id = edge_id
     return edge_model
 def insert_edge(self, edge_model: EdgeModel) -> EdgeModel:
     edge_id = self.edge_repository.insert_edge(edge_model.edge_name, edge_model.edge_cost, edge_model.start_node_id,
                                                edge_model.end_node_id, edge_model.graph_id)
     edge_model.edge_id = edge_id
     return edge_model