Exemplo n.º 1
0
class UniversityGraph(Graph):
    __graph__ = 'university_graph'

    graph_connections = [
        # Using general Relation class for relationship
        GraphConnection(Student, Relation("studies"), Subject),
        GraphConnection(Teacher, Relation("teaches"), Subject),
        GraphConnection(Teacher, Relation("teacher"), Student),

        # Using specific classes for vertex and edges
        GraphConnection(Teacher, SpecializesIn, Subject),
        GraphConnection([Teacher, Student], Relation("resides_in"), Area)
    ]
Exemplo n.º 2
0
    def test_12_update_graph_update_connection(self):

        UniversityGraph.graph_connections[-1] = GraphConnection(
            [DummyFromCol1, DummyFromCol2],
            DummyRelation,
            [DummyToCol1, DummyToCol2],
        )

        assert 5 == len(UniversityGraph.graph_connections)
        db, graph = self._get_graph()
        db.update_graph(graph)

        # Test if we have the new collections and graph relation
        col_names = [c["name"] for c in db.collections()]

        assert DummyFromCol1.__collection__ in col_names
        assert DummyFromCol2.__collection__ in col_names
        assert DummyToCol1.__collection__ in col_names
        assert DummyToCol2.__collection__ in col_names
        assert DummyRelation.__collection__ in col_names

        gi = db.graphs()[0]
        assert DummyRelation.__collection__ in [
            e["edge_collection"] for e in gi["edge_definitions"]
        ]
Exemplo n.º 3
0
    def test_11_update_graph_add_connection(self):

        UniversityGraph.graph_connections.append(
            GraphConnection(DummyFromCol1, DummyRelation, DummyToCol1))

        assert 5 == len(UniversityGraph.graph_connections)

        db, graph = self._get_graph()
        db.update_graph(graph)

        # Test if we have the new collections and graph relation
        col_names = [c["name"] for c in db.collections()]

        assert DummyFromCol1.__collection__ in col_names
        assert DummyToCol1.__collection__ in col_names
        assert DummyRelation.__collection__ in col_names

        assert DummyFromCol2.__collection__ not in col_names
        assert DummyToCol2.__collection__ not in col_names

        gi = db.graphs()[0]
        log.debug(gi)

        assert DummyRelation.__collection__ in [
            e["edge_collection"] for e in gi["edge_definitions"]
        ]
Exemplo n.º 4
0
    def test_15_drop_graph_with_collections(self):
        # making sure we remove the dummy collections too
        UniversityGraph.graph_connections.append(
            GraphConnection([DummyFromCol1, DummyFromCol2], DummyRelation,
                            [DummyToCol1, DummyToCol2]))
        db, graph = self._get_graph()
        db.create_graph(graph)
        db.drop_graph(graph, drop_collections=True)

        # verify that the collections are not deleted
        assert 'teaches' not in [c['name'] for c in db.collections()]

        # Remove the dummy relation connection
        UniversityGraph.graph_connections.pop()