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)
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"])
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_name01 = get_next_col_name(self.db) self.col01 = self.db.add_collection(self.col_name01) self.col_name02 = get_next_col_name(self.db) self.col02 = self.db.add_collection(self.col_name02)
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] } )
def test_rename_collection(self): # Create a new collection col_name = get_next_col_name(self.db) self.db.create_collection(col_name) col_id = self.db.collection(col_name).id # Rename the collection new_col_name = get_next_col_name(self.db) self.db.rename_collection(col_name, new_col_name) self.assertNotIn(col_name, self.db.collections["all"]) self.assertIn(new_col_name, self.db.collections["all"]) # Ensure it is the same collection by checking the ID self.assertEqual(self.db.collection(new_col_name).id, col_id)
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_name01 = get_next_col_name(self.db) self.col01 = self.db.create_collection(self.col_name01) self.col_name02 = get_next_col_name(self.db) self.col02 = self.db.create_collection(self.col_name02) # Test database cleaup self.addCleanup(self.arango.delete_database, name=self.db_name, safe_delete=True)
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)
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] )
def test_delete_collection(self): # Create a new collection col_name = get_next_col_name(self.db) self.db.create_collection(col_name) self.assertIn(col_name, self.db.collections["all"]) # Delete the collection and ensure that it's gone self.db.delete_collection(col_name) self.assertNotIn(col_name, self.db.collections)
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) self.col.add_geo_index(["coord"]) self.col.add_skiplist_index(["value"]) self.col.add_fulltext_index(["text"])
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] })
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"])
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) self.col.create_geo_index(["coord"]) self.col.create_skiplist_index(["value"]) self.col.create_fulltext_index(["text"]) # Test database cleaup self.addCleanup(self.arango.delete_database, name=self.db_name, safe_delete=True)
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] }], )
def test_collection_setters(self): # Create a new collection with predefined properties col = self.db.create_collection( name=get_next_col_name(self.db), wait_for_sync=False, journal_size=7774208 ) self.assertFalse(col.wait_for_sync) self.assertEqual(col.journal_size, 7774208) # Change the properties of the graph and ensure that it went through col.wait_for_sync = True col.journal_size = 8884208 self.assertTrue(col.wait_for_sync) self.assertEqual(col.journal_size, 8884208)
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])
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"])
def test_collection_create_with_config(self): # Create a new collection with custom defined properties col_name = get_next_col_name(self.db) col = self.db.create_collection( name=col_name, wait_for_sync=True, do_compact=False, journal_size=7774208, is_system=False, is_volatile=False, key_generator_type="autoincrement", allow_user_keys=False, key_increment=9, key_offset=100, is_edge=True, number_of_shards=2, shard_keys=["test_attr"], ) # Ensure that the new collection's properties are set correctly self.assertEqual(col.name, col_name) self.assertTrue(col.revision, "0") self.assertEqual(col.status, "loaded") self.assertEqual(col.journal_size, 7774208) self.assertEqual(col.checksum(), 0) self.assertEqual( col.key_options, { "allow_user_keys": False, "increment": 9, "offset": 100, "type": "autoincrement" } ) self.assertFalse(col.is_system) self.assertFalse(col.is_volatile) self.assertFalse(col.do_compact) self.assertTrue(col.wait_for_sync) self.assertTrue(col.is_edge) self.assertTrue(is_string(col.id)) self.assertTrue(isinstance(col.figures, dict))
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"])
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"])
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"), } )
def test_collection_load_unload(self): col = self.db.create_collection(get_next_col_name(self.db)) self.assertIn(col.unload(), {"unloaded", "unloading"}) self.assertIn(col.load(), {"loaded", "loading"})
def test_collection_rotate_journal(self): col = self.db.create_collection(get_next_col_name(self.db)) self.assertRaises( CollectionRotateJournalError, col.rotate_journal )
def test_create_collection(self): col_name = get_next_col_name(self.db) self.db.create_collection(col_name) self.assertIn(col_name, self.db.collections["all"])