Exemplo n.º 1
0
 def test_add_and_remove_edge_definition(self):
     # Create the edge and vertex collections
     vertex_col_name = get_next_col_name(self.db)
     self.db.add_collection(vertex_col_name)
     edge_col_name = get_next_col_name(self.db)
     self.db.add_collection(edge_col_name, is_edge=True)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.add_graph(graph_name)
     # Add the edge definition to the graph
     edge_definition = {
         "collection": edge_col_name,
         "from": [vertex_col_name],
         "to": [vertex_col_name]
     }
     graph.add_edge_definition(
         edge_col_name,
         [vertex_col_name],
         [vertex_col_name]
     )
     self.assertEqual(
         graph.edge_definitions,
         [edge_definition]
     )
     graph.remove_edge_definition(
         edge_col_name,
         drop_collection=True
     )
     self.assertEqual(graph.edge_definitions, [])
     self.assertNotIn(edge_col_name, self.db.collections["all"])
Exemplo n.º 2
0
 def setUp(self):
     self.arango = Arango()
     self.db_name = get_next_db_name(self.arango)
     self.db = self.arango.create_database(self.db_name)
     self.col_name = get_next_col_name(self.db)
     self.col = self.db.create_collection(self.col_name)
     # Create the vertex collection
     self.vertex_col_name = get_next_col_name(self.db)
     self.vertex_col = self.db.create_collection(self.vertex_col_name)
     # Create the edge collection
     self.edge_col_name = get_next_col_name(self.db)
     self.edge_col = self.db.create_collection(
         self.edge_col_name, is_edge=True
     )
     # Create the graph
     self.graph_name = get_next_graph_name(self.db)
     self.graph = self.db.create_graph(
         name=self.graph_name,
         edge_definitions=[{
             "collection": self.edge_col_name,
             "from": [self.vertex_col_name],
             "to": [self.vertex_col_name]
         }],
     )
     # Test database cleaup
     self.addCleanup(self.arango.delete_database,
                     name=self.db_name, safe_delete=True)
Exemplo n.º 3
0
 def test_remove_graph(self):
     # Add a new collection
     graph_name = get_next_graph_name(self.db)
     self.db.add_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
     # Remove the collection and ensure that it's gone
     self.db.remove_graph(graph_name)
     self.assertNotIn(graph_name, self.db.graphs)
Exemplo n.º 4
0
 def test_delete_graph(self):
     # Create a new collection
     graph_name = get_next_graph_name(self.db)
     self.db.create_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
     # Delete the collection and ensure that it's gone
     self.db.delete_graph(graph_name)
     self.assertNotIn(graph_name, self.db.graphs)
Exemplo n.º 5
0
 def test_delete_graph(self):
     # Create a new collection
     graph_name = get_next_graph_name(self.db)
     self.db.create_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
     # Delete the collection and ensure that it's gone
     self.db.delete_graph(graph_name)
     self.assertNotIn(graph_name, self.db.graphs)
Exemplo n.º 6
0
 def test_add_graph_with_defined_cols(self):
     # Create the orphan collection
     orphan_col_name = get_next_col_name(self.db)
     self.db.add_collection(orphan_col_name)
     # Create the vertex collection
     vertex_col_name = get_next_col_name(self.db)
     self.db.add_collection(vertex_col_name)
     # Create the edge collection
     edge_col_name = get_next_col_name(self.db)
     self.db.add_collection(edge_col_name, is_edge=True)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.add_graph(
         name=graph_name,
         edge_definitions=[{
             "collection": edge_col_name,
             "from": [vertex_col_name],
             "to": [vertex_col_name]
         }],
         orphan_collections=[orphan_col_name]
     )
     self.assertIn(graph_name, self.db.graphs)
     self.assertEqual(
         graph.orphan_collections,
         [orphan_col_name]
     )
     self.assertEqual(
         graph.edge_definitions,
         [{
             "collection": edge_col_name,
             "from": [vertex_col_name],
             "to": [vertex_col_name]
         }]
     )
     self.assertEqual(
         sorted(graph.vertex_collections),
         sorted([orphan_col_name, vertex_col_name])
     )
     properties = graph.properties
     del properties["_rev"]
     del properties["_id"]
     self.assertEqual(
         properties,
         {
             "name": graph_name,
             "edge_definitions": [
                 {
                     "collection": edge_col_name,
                     "from": [vertex_col_name],
                     "to": [vertex_col_name]
                 }
             ],
             "orphan_collections": [orphan_col_name]
         }
     )
Exemplo n.º 7
0
    def setUp(self):
        # Create the test database
        self.arango = Arango()
        self.db_name = get_next_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        # Create the test vertex collection
        self.vertex_col_name = get_next_col_name(self.db)
        self.vertex_col = self.db.create_collection(self.vertex_col_name)
        # Create the test edge collection
        self.edge_col_name = get_next_col_name(self.db)
        self.edge_col = self.db.create_collection(
            self.edge_col_name, is_edge=True
        )
        # Create the test graph
        self.graph_name = get_next_graph_name(self.db)
        self.graph = self.db.create_graph(
            name=self.graph_name,
            edge_definitions=[{
                "collection": self.edge_col_name,
                "from": [self.vertex_col_name],
                "to": [self.vertex_col_name]
            }],
        )
        # Create a few test vertices
        self.graph.create_vertex(
            self.vertex_col_name,
            data={
                "_key": "vertex01",
                "value": 1
            }
        )
        self.graph.create_vertex(
            self.vertex_col_name,
            data={
                "_key": "vertex02",
                "value": 1
            }
        )
        self.graph.create_vertex(
            self.vertex_col_name,
            data={
                "_key": "vertex03",
                "value": 1
            }
        )

        # Test database cleaup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)
Exemplo n.º 8
0
    def test_replace_edge_definition(self):
        # Create edge and vertex collection set 1
        vertex_col_name = get_next_col_name(self.db)
        self.db.add_collection(vertex_col_name)
        edge_col_name = get_next_col_name(self.db)
        self.db.add_collection(edge_col_name, is_edge=True)

        # Create edge and vertex collection set 2
        vertex_col_name_2 = get_next_col_name(self.db)
        self.db.add_collection(vertex_col_name_2)
        edge_col_name_2 = get_next_col_name(self.db)
        self.db.add_collection(edge_col_name_2, is_edge=True)

        # Create the graph
        graph_name = get_next_graph_name(self.db)
        graph = self.db.add_graph(graph_name)

        # Add the edge definition to the graph
        edge_definition = {
            "collection": edge_col_name,
            "from": [vertex_col_name],
            "to": [vertex_col_name]
        }
        graph.add_edge_definition(
            edge_col_name,
            [vertex_col_name],
            [vertex_col_name]
        )
        self.assertEqual(
            graph.edge_definitions,
            [edge_definition]
        )

        # Replace the edge definition 1 with 2
        edge_definition_2 = {
            "collection": edge_col_name,
            "from": [vertex_col_name_2],
            "to": [vertex_col_name_2]
        }
        graph.replace_edge_definition(
            edge_col_name,
            [vertex_col_name_2],
            [vertex_col_name_2]
        )
        self.assertEqual(
            graph.edge_definitions,
            [edge_definition_2]
        )
Exemplo n.º 9
0
 def test_create_and_delete_vertex_collection(self):
     # Create the vertex collection
     vertex_col_name = get_next_col_name(self.db)
     self.db.create_collection(vertex_col_name)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.create_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
     self.assertEqual(graph.vertex_collections, [])
     # Create the vertex collection to the graph
     graph.create_vertex_collection(vertex_col_name)
     self.assertEqual(graph.vertex_collections, [vertex_col_name])
     # Delete the vertex collection (completely)
     graph.delete_vertex_collection(vertex_col_name, drop_collection=True)
     self.assertEqual(graph.vertex_collections, [])
     self.assertNotIn(vertex_col_name, self.db.collections["all"])
Exemplo n.º 10
0
 def test_create_graph_with_defined_cols(self):
     # Create the orphan collection
     orphan_col_name = get_next_col_name(self.db)
     self.db.create_collection(orphan_col_name)
     # Create the vertex collection
     vertex_col_name = get_next_col_name(self.db)
     self.db.create_collection(vertex_col_name)
     # Create the edge collection
     edge_col_name = get_next_col_name(self.db)
     self.db.create_collection(edge_col_name, is_edge=True)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.create_graph(name=graph_name,
                                  edge_definitions=[{
                                      "collection":
                                      edge_col_name,
                                      "from": [vertex_col_name],
                                      "to": [vertex_col_name]
                                  }],
                                  orphan_collections=[orphan_col_name])
     self.assertIn(graph_name, self.db.graphs)
     self.assertEqual(graph.orphan_collections, [orphan_col_name])
     self.assertEqual(graph.edge_definitions, [{
         "collection": edge_col_name,
         "from": [vertex_col_name],
         "to": [vertex_col_name]
     }])
     self.assertEqual(sorted(graph.vertex_collections),
                      sorted([orphan_col_name, vertex_col_name]))
     properties = graph.properties
     del properties["_rev"]
     del properties["_id"]
     self.assertEqual(
         properties, {
             "name":
             graph_name,
             "edge_definitions": [{
                 "collection": edge_col_name,
                 "from": [vertex_col_name],
                 "to": [vertex_col_name]
             }],
             "orphan_collections": [orphan_col_name]
         })
Exemplo n.º 11
0
 def test_create_and_delete_edge_definition(self):
     # Create the edge and vertex collections
     vertex_col_name = get_next_col_name(self.db)
     self.db.create_collection(vertex_col_name)
     edge_col_name = get_next_col_name(self.db)
     self.db.create_collection(edge_col_name, is_edge=True)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.create_graph(graph_name)
     # Create the edge definition to the graph
     edge_definition = {
         "collection": edge_col_name,
         "from": [vertex_col_name],
         "to": [vertex_col_name]
     }
     graph.create_edge_definition(edge_col_name, [vertex_col_name],
                                  [vertex_col_name])
     self.assertEqual(graph.edge_definitions, [edge_definition])
     graph.delete_edge_definition(edge_col_name, drop_collection=True)
     self.assertEqual(graph.edge_definitions, [])
     self.assertNotIn(edge_col_name, self.db.collections["all"])
Exemplo n.º 12
0
 def test_create_and_delete_vertex_collection(self):
     # Create the vertex collection
     vertex_col_name = get_next_col_name(self.db)
     self.db.create_collection(vertex_col_name)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.create_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
     self.assertEqual(graph.vertex_collections, [])
     # Create the vertex collection to the graph
     graph.create_vertex_collection(vertex_col_name)
     self.assertEqual(
         graph.vertex_collections,
         [vertex_col_name]
     )
     # Delete the vertex collection (completely)
     graph.delete_vertex_collection(
         vertex_col_name,
         drop_collection=True
     )
     self.assertEqual(graph.vertex_collections, [])
     self.assertNotIn(vertex_col_name, self.db.collections["all"])
Exemplo n.º 13
0
 def test_add_and_remove_vertex_collection(self):
     # Create the vertex collection
     vertex_col_name = get_next_col_name(self.db)
     self.db.add_collection(vertex_col_name)
     # Create the graph
     graph_name = get_next_graph_name(self.db)
     graph = self.db.add_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
     self.assertEqual(graph.vertex_collections, [])
     # Add the vertex collection to the graph
     graph.add_vertex_collection(vertex_col_name)
     self.assertEqual(
         graph.vertex_collections,
         [vertex_col_name]
     )
     # Remove the vertex collection (completely)
     graph.remove_vertex_collection(
         vertex_col_name,
         drop_collection=True
     )
     self.assertEqual(graph.vertex_collections, [])
     self.assertNotIn(vertex_col_name, self.db.collections["all"])
Exemplo n.º 14
0
    def setUp(self):
        self.arango = Arango()
        self.db_name = get_next_db_name(self.arango)
        self.db = self.arango.add_database(self.db_name)
        self.col_name = get_next_col_name(self.db)
        self.col = self.db.add_collection(self.col_name)

        # Create the vertex collection
        self.vertex_col_name = get_next_col_name(self.db)
        self.vertex_col = self.db.add_collection(self.vertex_col_name)
        # Create the edge collection
        self.edge_col_name = get_next_col_name(self.db)
        self.edge_col = self.db.add_collection(self.edge_col_name, is_edge=True)
        # Create the graph
        self.graph_name = get_next_graph_name(self.db)
        self.graph = self.db.add_graph(
            name=self.graph_name,
            edge_definitions=[{
                "collection": self.edge_col_name,
                "from": [self.vertex_col_name],
                "to": [self.vertex_col_name]
            }],
        )
Exemplo n.º 15
0
    def test_replace_edge_definition(self):
        # Create edge and vertex collection set 1
        vertex_col_name = get_next_col_name(self.db)
        self.db.create_collection(vertex_col_name)
        edge_col_name = get_next_col_name(self.db)
        self.db.create_collection(edge_col_name, is_edge=True)

        # Create edge and vertex collection set 2
        vertex_col_name_2 = get_next_col_name(self.db)
        self.db.create_collection(vertex_col_name_2)
        edge_col_name_2 = get_next_col_name(self.db)
        self.db.create_collection(edge_col_name_2, is_edge=True)

        # Create the graph
        graph_name = get_next_graph_name(self.db)
        graph = self.db.create_graph(graph_name)

        # Create the edge definition to the graph
        edge_definition = {
            "collection": edge_col_name,
            "from": [vertex_col_name],
            "to": [vertex_col_name]
        }
        graph.create_edge_definition(edge_col_name, [vertex_col_name],
                                     [vertex_col_name])
        self.assertEqual(graph.edge_definitions, [edge_definition])

        # Replace the edge definition 1 with 2
        edge_definition_2 = {
            "collection": edge_col_name,
            "from": [vertex_col_name_2],
            "to": [vertex_col_name_2]
        }
        graph.replace_edge_definition(edge_col_name, [vertex_col_name_2],
                                      [vertex_col_name_2])
        self.assertEqual(graph.edge_definitions, [edge_definition_2])
Exemplo n.º 16
0
 def test_create_graph(self):
     graph_name = get_next_graph_name(self.db)
     self.db.create_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
Exemplo n.º 17
0
 def test_create_graph(self):
     graph_name = get_next_graph_name(self.db)
     self.db.create_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)
Exemplo n.º 18
0
    def setUp(self):
        # Create the test database
        self.arango = Arango()
        self.db_name = get_next_db_name(self.arango)
        self.db = self.arango.add_database(self.db_name)
        # Create the test vertex "from" collection
        self.from_col_name = get_next_col_name(self.db)
        self.from_col = self.db.add_collection(self.from_col_name)
        # Create the test vertex "to" collection
        self.to_col_name = get_next_col_name(self.db)
        self.to_col = self.db.add_collection(self.to_col_name)
        # Create the test edge collection
        self.edge_col_name = get_next_col_name(self.db)
        self.edge_col = self.db.add_collection(
            self.edge_col_name, is_edge=True
        )
        # Create the test graph
        self.graph_name = get_next_graph_name(self.db)
        self.graph = self.db.add_graph(
            name=self.graph_name,
            edge_definitions=[{
                "collection": self.edge_col_name,
                "from": [self.from_col_name],
                "to": [self.to_col_name]
            }],
        )
        # Add a few test "from" vertices
        self.graph.add_vertex(
            self.from_col_name,
            data={"_key": "from01", "value": 1}
        )
        self.graph.add_vertex(
            self.from_col_name,
            data={"_key": "from02", "value": 2}
        )
        # Add a few test "to" vertices
        self.graph.add_vertex(
            self.to_col_name,
            data={"_key": "to01", "value": 1}
        )
        self.graph.add_vertex(
            self.to_col_name,
            data={"_key": "to02", "value": 2}
        )
        self.graph.add_vertex(
            self.to_col_name,
            data={"_key": "to03", "value": 3}
        )

        # Add a few test edges
        self.graph.add_edge(
            self.edge_col_name,
            {
                "_from": "{}/{}".format(self.from_col_name, "from01"),
                "_to": "{}/{}".format(self.to_col_name, "to01"),
            }
        )
        self.graph.add_edge(
            self.edge_col_name,
            {
                "_from": "{}/{}".format(self.from_col_name, "from02"),
                "_to": "{}/{}".format(self.to_col_name, "to02"),
            }
        )
        self.graph.add_edge(
            self.edge_col_name,
            {
                "_from": "{}/{}".format(self.from_col_name, "from02"),
                "_to": "{}/{}".format(self.to_col_name, "to03"),
            }
        )
Exemplo n.º 19
0
 def test_add_graph(self):
     graph_name = get_next_graph_name(self.db)
     self.db.add_graph(graph_name)
     self.assertIn(graph_name, self.db.graphs)