本文整理汇总了Python中arango.Arango.add_database方法的典型用法代码示例。如果您正苦于以下问题:Python Arango.add_database方法的具体用法?Python Arango.add_database怎么用?Python Arango.add_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arango.Arango
的用法示例。
在下文中一共展示了Arango.add_database方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DatabaseManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class DatabaseManagementTest(unittest.TestCase):
def setUp(self):
self.arango = Arango()
def test_database_add_and_remove(self):
db_name = get_next_db_name(self.arango)
self.arango.add_database(db_name)
self.assertIn(db_name, self.arango.databases["all"])
# Check the properties of the new database
self.assertEqual(self.arango.db(db_name).name, db_name)
self.assertEqual(self.arango.db(db_name).is_system, False)
# Remove the test database
self.arango.remove_database(db_name)
self.assertNotIn(db_name, self.arango.databases["all"])
def test_database_properties(self):
db = self.arango.database("_system")
self.assertEqual(db.name, "_system")
self.assertTrue(isinstance(db.properties, dict))
self.assertTrue(is_string(db.id))
self.assertTrue(is_string(db.path))
self.assertEqual(db.is_system, True)
示例2: BatchRequestTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class BatchRequestTest(unittest.TestCase):
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 tearDown(self):
self.arango.remove_database(self.db_name)
def test_execute_transaction(self):
action = """
function () {
var db = require('internal').db;
db.%s.save({ _key: 'doc01'});
db.%s.save({ _key: 'doc02'});
return 'success!';
}
""" % (self.col_name01, self.col_name02)
res = self.db.execute_transaction(
action=action,
read_collections=[self.col_name01, self.col_name02],
write_collections=[self.col_name01, self.col_name02],
wait_for_sync=True,
lock_timeout=10000
)
self.assertEqual(res, "success!")
self.assertIn("doc01", self.col01)
self.assertIn("doc02", self.col02)
示例3: AQLFunctionManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class AQLFunctionManagementTest(unittest.TestCase):
def setUp(self):
self.arango = Arango()
self.db_name = get_next_db_name(self.arango)
self.db = self.arango.add_database(self.db_name)
def tearDown(self):
self.arango.remove_database(self.db_name)
def test_add_valid_aql_function(self):
self.db.add_aql_function(
"myfunctions::temperature::celsiustofahrenheit",
"function (celsius) { return celsius * 1.8 + 32; }"
)
self.assertEqual(
self.db.aql_functions,
{
"myfunctions::temperature::celsiustofahrenheit": (
"function (celsius) { return celsius * 1.8 + 32; }"
)
}
)
def test_add_invalid_aql_function(self):
self.assertRaises(
AQLFunctionAddError,
self.db.add_aql_function,
"myfunctions::temperature::celsiustofahrenheit",
"function (celsius) { invalid syntax }"
)
def test_remove_aql_function(self):
self.db.add_aql_function(
"myfunctions::temperature::celsiustofahrenheit",
"function (celsius) { return celsius * 1.8 + 32; }"
)
self.db.remove_aql_function(
"myfunctions::temperature::celsiustofahrenheit",
)
self.assertEqual(self.db.aql_functions, {})
# TODO create functions within function
def test_remove_aql_functions_by_group(self):
self.db.add_aql_function(
"myfunctions::temperature::celsiustofahrenheit",
"function (celsius) { return celsius * 1.8 + 32; }"
)
self.db.remove_aql_function(
"myfunctions::temperature::celsiustofahrenheit",
group=True
)
self.assertEqual(self.db.aql_functions, {})
示例4: VertexManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class VertexManagementTest(unittest.TestCase):
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 tearDown(self):
self.arango.remove_database(self.db_name)
def test_add_vertex(self):
self.graph.add_vertex(
self.vertex_col_name,
data={"_key": "vertex01", "value": 10}
)
self.assertEqual(self.vertex_col.count, 1)
self.assertEqual(
self.graph.get_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01")
)["value"],
10
)
def test_update_vertex(self):
self.graph.add_vertex(
self.vertex_col_name,
data={"_key": "vertex01", "value": 10}
)
self.graph.update_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01"),
data={"value": 20, "new_value": 30}
)
self.assertEqual(
self.graph.get_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01")
)["value"],
20
)
self.assertEqual(
self.graph.get_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01")
)["new_value"],
30
)
def test_replace_vertex(self):
self.graph.add_vertex(
self.vertex_col_name,
data={"_key": "vertex01", "value": 10}
)
self.graph.replace_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01"),
data={"new_value": 30}
)
self.assertNotIn(
"value",
self.graph.get_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01")
)
)
self.assertEqual(
self.graph.get_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01")
)["new_value"],
30
)
def test_remove_vertex(self):
self.graph.add_vertex(
self.vertex_col_name,
data={"_key": "vertex01", "value": 10}
)
self.graph.remove_vertex(
"{}/{}".format(self.vertex_col_name, "vertex01")
)
self.assertNotIn("vertex01", self.vertex_col)
self.assertEqual(len(self.vertex_col), 0)
示例5: GraphManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class GraphManagementTest(unittest.TestCase):
def setUp(self):
self.arango = Arango()
self.db_name = get_next_db_name(self.arango)
self.db = self.arango.add_database(self.db_name)
def tearDown(self):
self.arango.remove_database(self.db_name)
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)
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)
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_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
)
#.........这里部分代码省略.........
示例6: BatchRequestTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class BatchRequestTest(unittest.TestCase):
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 tearDown(self):
self.arango.remove_database(self.db_name)
def test_batch_document_add(self):
self.db.execute_batch([
(self.col.add_document, [{"_key": "doc01", "value": 1}], {}),
(self.col.add_document, [{"_key": "doc02", "value": 2}], {}),
(self.col.add_document, [{"_key": "doc03", "value": 3}], {}),
])
self.assertEqual(len(self.col), 3)
self.assertEqual(self.col.get_document("doc01")["value"], 1)
self.assertEqual(self.col.get_document("doc02")["value"], 2)
self.assertEqual(self.col.get_document("doc03")["value"], 3)
def test_batch_document_replace(self):
self.col.bulk_import([
{"_key": "doc01", "value": 1},
{"_key": "doc02", "value": 1},
{"_key": "doc03", "value": 1}
])
self.db.execute_batch([
(self.col.replace_document, ["doc01", {"value": 2}], {}),
(self.col.replace_document, ["doc02", {"value": 2}], {}),
(self.col.replace_document, ["doc03", {"value": 2}], {}),
])
self.assertEqual(self.col.get_document("doc01")["value"], 2)
self.assertEqual(self.col.get_document("doc02")["value"], 2)
self.assertEqual(self.col.get_document("doc03")["value"], 2)
def test_batch_document_update(self):
self.col.bulk_import([
{"_key": "doc01", "value": 1},
{"_key": "doc02", "value": 1},
{"_key": "doc03", "value": 1}
])
self.db.execute_batch([
(
self.col.update_document,
["doc01", {"value": 2}],
{"wait_for_sync": True}
),
(
self.col.update_document,
["doc02", {"value": 2}],
{"wait_for_sync": True}
),
(
self.col.update_document,
["doc03", {"value": 2}],
{"wait_for_sync": True}
),
])
self.assertEqual(self.col.get_document("doc01")["value"], 2)
self.assertEqual(self.col.get_document("doc02")["value"], 2)
self.assertEqual(self.col.get_document("doc03")["value"], 2)
def test_batch_document_remove(self):
self.col.bulk_import([
{"_key": "doc01", "value": 1},
{"_key": "doc02", "value": 1},
{"_key": "doc03", "value": 1}
])
self.db.execute_batch([
(self.col.remove_document, ["doc01"], {}),
(self.col.remove_document, ["doc02"], {}),
(self.col.remove_document, ["doc03"], {}),
])
self.assertEqual(len(self.col), 0)
def test_batch_document_mixed(self):
self.col.bulk_import([
{"_key": "doc01", "value": 0},
{"_key": "doc02", "value": 0},
{"_key": "doc03", "value": 0}
#.........这里部分代码省略.........
示例7: ArangoDBQueryTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class ArangoDBQueryTest(unittest.TestCase):
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.db.add_collection(self.col_name)
def tearDown(self):
self.arango.remove_database(self.db_name)
def test_explain_query(self):
self.assertRaises(
QueryValidateError,
self.db.validate_query,
"THIS IS AN INVALID QUERY"
)
plans = self.db.explain_query(
"FOR d IN {} RETURN d".format(self.col_name),
all_plans=True,
optimizer_rules=["-all", "+use-index-range"]
)
for plan in plans:
self.assertGreaterEqual(
set(plan),
{
"collections",
"estimated_cost",
"estimated_nr_items",
"nodes",
"rules",
"variables"
}
)
def test_validate_query(self):
self.assertRaises(
QueryValidateError,
self.db.validate_query,
"THIS IS AN INVALID QUERY"
)
self.assertEqual(
None,
self.db.validate_query(
"FOR d IN {} RETURN d".format(self.col_name)
),
)
def test_execute_query(self):
collection = self.db.collection(self.col_name)
collection.bulk_import([
{"_key": "doc01"},
{"_key": "doc02"},
{"_key": "doc03"},
])
res = self.db.execute_query(
"FOR d IN {} RETURN d".format(self.col_name),
count=True,
batch_size=1,
ttl=10,
optimizer_rules=["+all"]
)
self.assertEqual(
sorted([doc["_key"] for doc in list(res)]),
["doc01", "doc02", "doc03"]
)
def test_execute_query_2(self):
collection = self.db.collection(self.col_name)
collection.bulk_import([
{"_key": "doc01", "value": 1},
{"_key": "doc02", "value": 2},
{"_key": "doc03", "value": 3},
])
res = self.db.execute_query(
"FOR d IN {} FILTER d.value == @value RETURN d".format(
self.col_name
),
bind_vars={
"value": 1
}
)
self.assertEqual(
sorted([doc["_key"] for doc in list(res)]),
["doc01"]
)
示例8: EdgeManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class EdgeManagementTest(unittest.TestCase):
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 tearDown(self):
self.arango.remove_database(self.db_name)
def test_basic_traversal(self):
visited = self.graph.execute_traversal(
"{}/{}".format(self.from_col_name, "from01"),
direction="outbound"
)["visited"]
self.assertEqual(len(visited["paths"]), 2)
self.assertEqual(
[vertex["_id"] for vertex in visited["vertices"]],
[
"{}/{}".format(self.from_col_name, "from01"),
"{}/{}".format(self.to_col_name, "to01"),
]
)
示例9: EdgeManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class EdgeManagementTest(unittest.TestCase):
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 collection
self.vertex_col_name = get_next_col_name(self.db)
self.vertex_col = self.db.add_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.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.vertex_col_name],
"to": [self.vertex_col_name]
}],
)
# Add a few test vertices
self.graph.add_vertex(
self.vertex_col_name,
data={
"_key": "vertex01",
"value": 1
}
)
self.graph.add_vertex(
self.vertex_col_name,
data={
"_key": "vertex02",
"value": 1
}
)
self.graph.add_vertex(
self.vertex_col_name,
data={
"_key": "vertex03",
"value": 1
}
)
def tearDown(self):
self.arango.remove_database(self.db_name)
def test_add_edge(self):
self.graph.add_edge(
self.edge_col_name,
data={
"_key": "edge01",
"_from": "{}/{}".format(self.vertex_col_name, "vertex01"),
"_to": "{}/{}".format(self.vertex_col_name, "vertex01"),
"value": "foobar"
}
)
self.assertEqual(self.edge_col.count, 1)
self.assertEqual(
self.graph.get_edge(
"{}/{}".format(self.edge_col_name, "edge01")
)["value"],
"foobar"
)
self.assertEqual(
self.graph.get_edge(
"{}/{}".format(self.edge_col_name, "edge01")
)["_from"],
"{}/{}".format(self.vertex_col_name, "vertex01")
)
self.assertEqual(
self.graph.get_edge(
"{}/{}".format(self.edge_col_name, "edge01")
)["_to"],
"{}/{}".format(self.vertex_col_name, "vertex01")
)
def test_update_edge(self):
self.graph.add_edge(
self.edge_col_name,
data={
"_key": "edge01",
"_from": "{}/{}".format(self.vertex_col_name, "vertex01"),
"_to": "{}/{}".format(self.vertex_col_name, "vertex01"),
"value": 10
}
)
self.graph.update_edge(
"{}/{}".format(self.edge_col_name, "edge01"),
data={"value": 20, "new_value": 30}
)
self.assertEqual(
self.graph.get_edge(
"{}/{}".format(self.edge_col_name, "edge01"),
)["value"],
20
#.........这里部分代码省略.........
示例10: DocumentManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class DocumentManagementTest(unittest.TestCase):
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 tearDown(self):
self.arango.remove_database(self.db_name)
def test_add_document(self):
self.assertEqual(len(self.col), 0)
self.col.add_document({"_key": "test_doc"})
self.assertEqual(len(self.col), 1)
self.assertIn("test_doc", self.col)
def test_remove_document(self):
rev = self.col.add_document({"_key": "test_doc"})["_rev"]
self.assertEqual(len(self.col), 1)
self.assertRaises(
DocumentRemoveError,
self.col.remove_document,
"test_doc",
rev="wrong_revision"
)
self.col.remove_document("test_doc", rev=rev)
self.assertEqual(len(self.col), 0)
self.assertNotIn("test_doc", self.col)
def test_replace_document(self):
rev = self.col.add_document({
"_key": "test_doc",
"value": 1,
"value2": 2,
})["_rev"]
self.assertRaises(
DocumentReplaceError,
self.col.replace_document,
"test_doc",
{"_rev": "wrong_revision", "value": 2},
)
self.col.replace_document(
"test_doc",
{"_rev": rev, "value": 2}
)
self.assertEqual(self.col["test_doc"]["value"], 2)
self.assertNotIn("value2", self.col["test_doc"])
def test_update_document(self):
rev = self.col.add_document({
"_key": "test_doc",
"value": 1,
"value2": 2,
})["_rev"]
self.assertRaises(
DocumentUpdateError,
self.col.update_document,
"test_doc",
{"_rev": "wrong_revision", "value": 2},
)
self.col.update_document(
"test_doc",
{"_rev": rev, "new_value": 2}
)
self.assertEqual(self.col["test_doc"]["value"], 1)
self.assertEqual(self.col["test_doc"]["new_value"], 2)
def test_truncate(self):
self.col.add_document({"_key": "test_doc_01"})
self.col.add_document({"_key": "test_doc_02"})
self.col.add_document({"_key": "test_doc_03"})
self.assertEqual(len(self.col), 3)
self.col.truncate()
self.assertEqual(len(self.col), 0)
def test_bulk_import(self):
documents = [
{"_key": "test_doc_01"},
{"_key": "test_doc_02"},
{"_key": 1} # invalid key
]
# This should succeed partially
res = self.col.bulk_import(documents, complete=False)
self.assertEqual(len(self.col), 2)
self.assertIn("test_doc_01", self.col)
self.assertIn("test_doc_01", self.col)
self.assertEqual(res["errors"], 1)
self.assertEqual(res["created"], 2)
# This should fail because of the last document
self.col.truncate()
self.assertRaises(
CollectionBulkImportError,
self.col.bulk_import,
documents,
complete=True
#.........这里部分代码省略.........
示例11: IndexManagementTest
# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import add_database [as 别名]
class IndexManagementTest(unittest.TestCase):
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)
def tearDown(self):
self.arango.remove_database(self.db_name)
def test_list_indexes(self):
self.assertIn(
{
"selectivity_estimate": 1,
"sparse": False,
"type": "primary",
"fields": ["_key"],
"unique": True
},
self.col.indexes.values()
)
def test_add_hash_index(self):
self.col.add_hash_index(["attr1", "attr2"], unique=True)
self.assertIn(
{
"selectivity_estimate": 1,
"sparse": False,
"type": "hash",
"fields": ["attr1", "attr2"],
"unique": True
},
self.col.indexes.values()
)
self.assertIn(
{
"selectivity_estimate": 1,
"sparse": False,
"type": "primary",
"fields": ["_key"],
"unique": True
},
self.col.indexes.values()
)
def test_add_cap_constraint(self):
self.col.add_cap_constraint(size=10, byte_size=40000)
self.assertIn(
{
"type": "cap",
"size": 10,
"byte_size": 40000,
"unique": False
},
self.col.indexes.values()
)
self.assertIn(
{
"selectivity_estimate": 1,
"sparse": False,
"type": "primary",
"fields": ["_key"],
"unique": True
},
self.col.indexes.values()
)
def test_add_skiplist_index(self):
self.col.add_skiplist_index(["attr1", "attr2"], unique=True)
self.assertIn(
{
"sparse": False,
"type": "skiplist",
"fields": ["attr1", "attr2"],
"unique": True
},
self.col.indexes.values()
)
self.assertIn(
{
"selectivity_estimate": 1,
"sparse": False,
"type": "primary",
"fields": ["_key"],
"unique": True
},
self.col.indexes.values()
)
def test_add_geo_index_with_one_attr(self):
self.skipTest("I have no idea why unique comes back as false, on the geo creation."
"Perhaps that index type doesn't support it.")
self.col.add_geo_index(
fields=["attr1"],
geo_json=False,
unique=True,
ignore_null=False
)
#.........这里部分代码省略.........