Ejemplo n.º 1
0
def test_load_graph(relationship_nodes):
    # Arrange
    expected = Graph([
        Node("TypeA", given_id="1"),
        Node("TypeB", given_id="2")
    ], [Relationship(relationship_nodes["1"], "Rel", relationship_nodes["2"])])
    # Act
    result = import_graph_json({
        "nodes": [{
            "node_type": "TypeA",
            "properties": {
                "node_id": "1"
            }
        }, {
            "node_type": "TypeB",
            "properties": {
                "node_id": "2"
            }
        }],
        "relationships": [{
            "node_a": "1",
            "relationship_type": "Rel",
            "node_b": "2"
        }]
    })
    # Assert
    assert result == expected
Ejemplo n.º 2
0
def import_node_json(node_raw: Dict) -> Node:
    """
    Loads a node from raw json
    :param node_raw: the json to load from
    :return: the node object
    """
    return Node(node_raw["node_types"], node_raw["properties"])
Ejemplo n.º 3
0
def test_multi_label_node():
    # Arrange
    expected = "(n:TestTypeA:TestTypeB {prop1: 'value1', node_id: '1'})"
    test_node = Node(["TestTypeA", "TestTypeB"], {"prop1": "value1"}, "1")
    # Act
    result = node_query(test_node)
    # Assert
    assert result == expected
Ejemplo n.º 4
0
def test_node_query_sanity():
    # Arrange
    expected = "(n:TestType {prop1: 'value1', node_id: '1'})"
    test_node = Node("TestType", {"prop1": "value1"}, "1")
    # Act
    result = node_query(test_node)
    # Assert
    assert result == expected
Ejemplo n.º 5
0
def import_node_neo4j(result: neo4j.Record) -> Node:
    """
    Takes a neo4j result and converts it to a use able node object
    :param result: the neo4j result
    :return: the node created from the result
    """
    return Node(list(result[0].labels),
                {key: value
                 for key, value in result[0].items()})
Ejemplo n.º 6
0
def test_load_node():
    # Arrange
    expected = Node("TestType", given_id="1")
    # Act
    result = import_node_json({
        "node_type": "TestType",
        "properties": {
            "node_id": "1"
        }
    })
    # Assert
    assert result == expected
Ejemplo n.º 7
0
def create_graph_map(names: List[AnyStr], connection_chance: int) -> Database:
    """
    Creates a randomly generated graph in neo4j and saves it to a json representation for use in testing the differ
    loads names for generating from a file.
    :param connection_chance: the chance for a node to connect to another higher is a bigger change
    :param names: the path to save the graph to.
    """
    names = names
    relationships = []
    names_nodes = [
        Node(GlobalSettings.TEST_GRAPH_TYPE, properties={"name": name})
        for name in names
    ]
    for current_node in names_nodes:
        for i in range(random.randint(0, connection_chance)):
            selected_node = random.choice(names_nodes)
            if selected_node is not current_node:
                new_relationship = Relationship(
                    current_node, GlobalSettings.TEST_GRAPH_RELATIONSHIP,
                    selected_node)
                relationships.append(new_relationship)
    return Database(Graph(names_nodes, relationships), "TestDatabase")
Ejemplo n.º 8
0
def test_node() -> Node:
    return Node("TestType", {"prop1": "value1"}, "1")
Ejemplo n.º 9
0
def test_relationship() -> Relationship:
    return Relationship(Node("TestTypeA", {"prop1": "value1"}, "1"),
                        "Knows",
                        Node("TestTypeB", {"prop2": "value2"}, "2"), {"rel_prop": "value1"})
Ejemplo n.º 10
0
def relationship_nodes():
    return {"1": Node("TypeA", given_id="1"), "2": Node("TypeB", given_id="2")}
Ejemplo n.º 11
0
def test_node() -> Node:
    return Node("TestType", given_id="1")
Ejemplo n.º 12
0
def test_relationship() -> Relationship:
    return Relationship(Node("TypeA", given_id="1"), "Rel", Node("TypeB", given_id="2"))