当前位置: 首页>>代码示例>>Python>>正文


Python Arango.create_database方法代码示例

本文整理汇总了Python中arango.Arango.create_database方法的典型用法代码示例。如果您正苦于以下问题:Python Arango.create_database方法的具体用法?Python Arango.create_database怎么用?Python Arango.create_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arango.Arango的用法示例。


在下文中一共展示了Arango.create_database方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DatabaseManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class DatabaseManagementTest(unittest.TestCase):
    """Tests for managing ArangoDB databases."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = get_next_db_name(self.arango)

        # Test database cleaup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_database_create_and_delete(self):
        self.arango.create_database(self.db_name)
        self.assertIn(self.db_name, self.arango.databases["all"])

        # Check the properties of the new database
        self.assertEqual(self.arango.database(self.db_name).name,
                         self.db_name)
        self.assertEqual(self.arango.database(self.db_name).is_system, False)

        # Delete the test database
        self.arango.delete_database(self.db_name)
        self.assertNotIn(self.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)
开发者ID:zopyx,项目名称:python-arango,代码行数:33,代码来源:test_databases.py

示例2: AQLFunctionManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class AQLFunctionManagementTest(unittest.TestCase):
    """Tests for ArangoDB AQL functions."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = get_next_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)

        # Test database cleaup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_create_valid_aql_function(self):
        self.db.create_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_create_invalid_aql_function(self):
        self.assertRaises(
            AQLFunctionCreateError,
            self.db.create_aql_function,
            "myfunctions::temperature::celsiustofahrenheit",
            "function (celsius) { invalid syntax }"
        )

    def test_delete_aql_function(self):
        self.db.create_aql_function(
            "myfunctions::temperature::celsiustofahrenheit",
            "function (celsius) { return celsius * 1.8 + 32; }"
        )
        self.db.delete_aql_function(
            "myfunctions::temperature::celsiustofahrenheit",
        )
        self.assertEqual(self.db.aql_functions, {})

    # TODO create functions within function
    def test_delete_aql_functions_by_group(self):
        self.db.create_aql_function(
            "myfunctions::temperature::celsiustofahrenheit",
            "function (celsius) { return celsius * 1.8 + 32; }"
        )
        self.db.delete_aql_function(
            "myfunctions::temperature::celsiustofahrenheit",
            group=True
        )
        self.assertEqual(self.db.aql_functions, {})
开发者ID:zopyx,项目名称:python-arango,代码行数:57,代码来源:test_aql_functions.py

示例3: Arango

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
#! /usr/bin/env python

import ujson
import fileinput
import arango
from arango import Arango
from pprint import pprint

dbcnx = Arango(host="localhost")
try:
    dbcnx.delete_database("eris0")
except arango.exceptions.DatabaseDeleteError:
    pass
dbcnx.create_database("eris0")
db = dbcnx.database("eris0")
db.create_collection("events")
col = db.collection("events")
col.wait_for_sync = False


def main():
    for line in fileinput.input():
        line = line.strip()
        event = None
        try:
            event = ujson.loads(line)
        except ValueError:
            continue
        event["_key"] = event["id"]
        del event["id"]
        col.create_document(event)
开发者ID:dip-proto,项目名称:eris,代码行数:33,代码来源:insert.py

示例4: BatchRequestTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class BatchRequestTest(unittest.TestCase):
    """Tests for ArangoDB batch requests."""

    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_batch_document_create(self):
        self.db.execute_batch(
            [
                (self.col.create_document, [{"_key": "doc01", "value": 1}], {}),
                (self.col.create_document, [{"_key": "doc02", "value": 2}], {}),
                (self.col.create_document, [{"_key": "doc03", "value": 3}], {}),
            ]
        )
        self.assertEqual(len(self.col), 3)
        self.assertEqual(self.col.document("doc01")["value"], 1)
        self.assertEqual(self.col.document("doc02")["value"], 2)
        self.assertEqual(self.col.document("doc03")["value"], 3)

    def test_batch_document_replace(self):
        self.col.import_documents(
            [{"_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.document("doc01")["value"], 2)
        self.assertEqual(self.col.document("doc02")["value"], 2)
        self.assertEqual(self.col.document("doc03")["value"], 2)

    def test_batch_document_update(self):
        self.col.import_documents(
            [{"_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.document("doc01")["value"], 2)
        self.assertEqual(self.col.document("doc02")["value"], 2)
        self.assertEqual(self.col.document("doc03")["value"], 2)

    def test_batch_document_Delete(self):
        self.col.import_documents(
            [{"_key": "doc01", "value": 1}, {"_key": "doc02", "value": 1}, {"_key": "doc03", "value": 1}]
        )
        self.db.execute_batch(
            [
                (self.col.delete_document, ["doc01"], {}),
                (self.col.delete_document, ["doc02"], {}),
                (self.col.delete_document, ["doc03"], {}),
            ]
        )
        self.assertEqual(len(self.col), 0)

    def test_batch_document_mixed(self):
        self.col.import_documents(
            [{"_key": "doc01", "value": 0}, {"_key": "doc02", "value": 0}, {"_key": "doc03", "value": 0}]
        )
        self.db.execute_batch(
            [
                (self.col.create_document, [{"_key": "doc04", "value": 1}], {"wait_for_sync": True}),
                (self.col.update_document, ["doc01", {"value": 2}], {"wait_for_sync": True}),
                (self.col.replace_document, ["doc02", {"new_value": 3}], {"wait_for_sync": True}),
                (self.col.delete_document, ["doc03"], {"wait_for_sync": True}),
                (self.col.create_document, [{"_key": "doc05", "value": 5}], {"wait_for_sync": True}),
            ]
        )
        self.assertEqual(len(self.col), 4)
        self.assertEqual(self.col.document("doc01")["value"], 2)
        self.assertEqual(self.col.document("doc02")["new_value"], 3)
#.........这里部分代码省略.........
开发者ID:zopyx,项目名称:python-arango,代码行数:103,代码来源:test_batch_requests.py

示例5: SimpleQueriesTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class SimpleQueriesTest(unittest.TestCase):
    """Tests for managing ArangoDB documents."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        self.col_name = generate_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 cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_first(self):
        self.assertEqual(strip_system_keys(self.col.first(1)), [])
        self.col.import_documents([
            {"name": "test_doc_01"},
            {"name": "test_doc_02"},
            {"name": "test_doc_03"}
        ])
        self.assertEqual(len(self.col), 3)
        self.assertEqual(
            strip_system_keys(self.col.first(1)),
            [{"name": "test_doc_01"}]
        )
        self.assertEqual(
            strip_system_keys(self.col.first(2)),
            [{"name": "test_doc_01"}, {"name": "test_doc_02"}]
        )

    def test_last(self):
        self.assertEqual(strip_system_keys(self.col.last(1)), [])
        self.col.import_documents([
            {"name": "test_doc_01"},
            {"name": "test_doc_02"},
            {"name": "test_doc_03"}
        ])
        self.assertEqual(len(self.col), 3)
        self.assertEqual(
            strip_system_keys(self.col.last(1)),
            [{"name": "test_doc_03"}]
        )
        docs = strip_system_keys(self.col.last(2))
        self.assertIn({"name": "test_doc_03"}, docs)
        self.assertIn({"name": "test_doc_02"}, docs)

    def test_all(self):
        self.assertEqual(list(self.col.all()), [])
        self.col.import_documents([
            {"name": "test_doc_01"},
            {"name": "test_doc_02"},
            {"name": "test_doc_03"}
        ])
        self.assertEqual(len(self.col), 3)

        docs = strip_system_keys(self.col.all())
        self.assertIn({"name": "test_doc_01"}, docs)
        self.assertIn({"name": "test_doc_02"}, docs)
        self.assertIn({"name": "test_doc_03"}, docs)

    def test_any(self):
        self.assertEqual(strip_system_keys(self.col.all()), [])
        self.col.import_documents([
            {"name": "test_doc_01"},
            {"name": "test_doc_02"},
            {"name": "test_doc_03"}
        ])
        self.assertIn(
            strip_system_keys(self.col.any()),
            [
                {"name": "test_doc_01"},
                {"name": "test_doc_02"},
                {"name": "test_doc_03"}
            ]
        )

    def test_get_first_example(self):
        self.assertEqual(
            self.col.get_first_example({"value": 1}), None
        )
        self.col.import_documents([
            {"name": "test_doc_01", "value": 1},
            {"name": "test_doc_02", "value": 1},
            {"name": "test_doc_03", "value": 3}
        ])
        self.assertIn(
            strip_system_keys(self.col.get_first_example({"value": 1})),
            [
                {"name": "test_doc_01", "value": 1},
                {"name": "test_doc_02", "value": 1}
            ]
        )

    def test_get_by_example(self):
        self.col.import_documents([
            {"name": "test_doc_01", "value": 1},
#.........这里部分代码省略.........
开发者ID:allanino,项目名称:python-arango,代码行数:103,代码来源:test_simple_queries.py

示例6: IndexManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class IndexManagementTest(unittest.TestCase):
    """Tests for managing ArangoDB indexes."""

    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)

        # Test database cleaup
        self.addCleanup(self.arango.delete_database, name=self.db_name, safe_delete=True)

    def test_list_indexes(self):
        self.assertIn(
            {"selectivity_estimate": 1, "sparse": False, "type": "primary", "fields": ["_key"], "unique": True},
            self.col.indexes.values(),
        )

    def test_create_hash_index(self):
        self.col.create_hash_index(["attr1", "attr2"], unique=True)
        self.assertIn(
            {"selectivity_estimate": 1, "sparse": False, "type": "hash", "fields": ["attr1", "attr2"], "unique": True},
            self.col.indexes.values(),
        )

    def test_create_cap_constraint(self):
        self.col.create_cap_constraint(size=10, byte_size=40000)
        self.assertIn({"type": "cap", "size": 10, "byte_size": 40000, "unique": False}, self.col.indexes.values())

    def test_create_skiplist_index(self):
        self.col.create_skiplist_index(["attr1", "attr2"], unique=True)
        self.assertIn(
            {"sparse": False, "type": "skiplist", "fields": ["attr1", "attr2"], "unique": True},
            self.col.indexes.values(),
        )

    def test_create_geo_index_with_one_attr(self):
        self.col.create_geo_index(fields=["attr1"], geo_json=False)
        self.assertIn(
            {
                "sparse": True,
                "type": "geo1",
                "fields": ["attr1"],
                "unique": False,
                "geo_json": False,
                "ignore_null": True,
                "constraint": False,
            },
            self.col.indexes.values(),
        )

    def test_create_geo_index_with_two_attrs(self):
        self.col.create_geo_index(fields=["attr1", "attr2"], geo_json=False)
        self.assertIn(
            {
                "sparse": True,
                "type": "geo2",
                "fields": ["attr1", "attr2"],
                "unique": False,
                "ignore_null": True,
                "constraint": False,
            },
            self.col.indexes.values(),
        )

    def test_create_geo_index_with_more_than_two_attrs(self):
        self.assertRaises(IndexCreateError, self.col.create_geo_index, fields=["attr1", "attr2", "attr3"])

    def test_create_fulltext_index(self):
        self.assertRaises(IndexCreateError, self.col.create_fulltext_index, fields=["attr1", "attr2"])
        self.col.create_fulltext_index(fields=["attr1"], min_length=10)
        self.assertIn(
            {"sparse": True, "type": "fulltext", "fields": ["attr1"], "min_length": 10, "unique": False},
            self.col.indexes.values(),
        )

    def test_delete_index(self):
        old_indexes = set(self.col.indexes)
        self.col.create_hash_index(["attr1", "attr2"], unique=True)
        self.col.create_skiplist_index(["attr1", "attr2"], unique=True)
        self.col.create_fulltext_index(fields=["attr1"], min_length=10)
        new_indexes = set(self.col.indexes)
        self.assertNotEqual(old_indexes, new_indexes)

        for index_id in new_indexes - old_indexes:
            self.col.delete_index(index_id)

        self.assertEqual(old_indexes, set(self.col.indexes))
开发者ID:zopyx,项目名称:python-arango,代码行数:91,代码来源:test_indexes.py

示例7: DocumentManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class DocumentManagementTest(unittest.TestCase):
    """Tests for ArangoDB document management."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        self.col_name = generate_col_name(self.db)
        self.col = self.db.create_collection(self.col_name)

        # Test database cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_create_document(self):
        self.assertEqual(len(self.col), 0)
        self.col.create_document({"_key": "test_doc"})
        self.assertEqual(len(self.col), 1)
        self.assertIn("test_doc", self.col)

    def test_delete_document(self):
        rev = self.col.create_document({"_key": "test_doc"})["_rev"]
        self.assertEqual(len(self.col), 1)
        self.assertRaises(
            DocumentDeleteError,
            self.col.delete_document,
            "test_doc",
            rev="wrong_revision"
        )
        self.col.delete_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.create_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.create_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.create_document({"_key": "test_doc_01"})
        self.col.create_document({"_key": "test_doc_02"})
        self.col.create_document({"_key": "test_doc_03"})
        self.assertEqual(len(self.col), 3)
        self.col.truncate()
        self.assertEqual(len(self.col), 0)

    def test_import_documents(self):
        documents = [
            {"_key": "test_doc_01"},
            {"_key": "test_doc_02"},
            {"_key": 1}  # invalid key
        ]
        # This should succeed partially
        res = self.col.import_documents(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(
            DocumentsImportError,
            self.col.import_documents,
            documents,
            complete=True
        )
#.........这里部分代码省略.........
开发者ID:allanino,项目名称:python-arango,代码行数:103,代码来源:test_documents.py

示例8: VertexManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class VertexManagementTest(unittest.TestCase):
    """Tests for managing ArangoDB vertices."""

    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_create_vertex(self):
        self.graph.create_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.create_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.create_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_delete_vertex(self):
        self.graph.create_vertex(
            self.vertex_col_name,
            data={"_key": "vertex01", "value": 10}
        )
        self.graph.delete_vertex(
            "{}/{}".format(self.vertex_col_name, "vertex01")
        )
        self.assertNotIn("vertex01", self.vertex_col)
        self.assertEqual(len(self.vertex_col), 0)
开发者ID:zopyx,项目名称:python-arango,代码行数:100,代码来源:test_vertexes.py

示例9: EdgeManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class EdgeManagementTest(unittest.TestCase):
    """Tests for ArangoDB graph traversals."""

    def setUp(self):
        # Create the test database
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        # Create the test vertex "from" collection
        self.from_col_name = generate_col_name(self.db)
        self.from_col = self.db.create_collection(self.from_col_name)
        # Create the test vertex "to" collection
        self.to_col_name = generate_col_name(self.db)
        self.to_col = self.db.create_collection(self.to_col_name)
        # Create the test edge collection
        self.edge_col_name = generate_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 = generate_graph_name(self.db)
        self.graph = self.db.create_graph(
            name=self.graph_name,
            edge_definitions=[{
                "collection": self.edge_col_name,
                "from": [self.from_col_name],
                "to": [self.to_col_name]
            }],
        )
        # Create a few test "from" vertices
        self.graph.create_vertex(
            self.from_col_name,
            data={"_key": "from01", "value": 1}
        )
        self.graph.create_vertex(
            self.from_col_name,
            data={"_key": "from02", "value": 2}
        )
        # Create a few test "to" vertices
        self.graph.create_vertex(
            self.to_col_name,
            data={"_key": "to01", "value": 1}
        )
        self.graph.create_vertex(
            self.to_col_name,
            data={"_key": "to02", "value": 2}
        )
        self.graph.create_vertex(
            self.to_col_name,
            data={"_key": "to03", "value": 3}
        )

        # Create a few test edges
        self.graph.create_edge(
            self.edge_col_name,
            {
                "_from": "{}/{}".format(self.from_col_name, "from01"),
                "_to": "{}/{}".format(self.to_col_name, "to01"),
            }
        )
        self.graph.create_edge(
            self.edge_col_name,
            {
                "_from": "{}/{}".format(self.from_col_name, "from02"),
                "_to": "{}/{}".format(self.to_col_name, "to02"),
            }
        )
        self.graph.create_edge(
            self.edge_col_name,
            {
                "_from": "{}/{}".format(self.from_col_name, "from02"),
                "_to": "{}/{}".format(self.to_col_name, "to03"),
            }

        )
        # Test database cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    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"),
            ]
        )
开发者ID:allanino,项目名称:python-arango,代码行数:94,代码来源:test_traversals.py

示例10: GraphManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class GraphManagementTest(unittest.TestCase):
    """Tests for managing ArangoDB graphs."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)

        # Test database cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_create_graph(self):
        graph_name = generate_graph_name(self.db)
        self.db.create_graph(graph_name)
        self.assertIn(graph_name, self.db.graphs)

    def test_delete_graph(self):
        # Create a new collection
        graph_name = generate_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)

    def test_create_graph_with_defined_cols(self):
        # Create the orphan collection
        orphan_col_name = generate_col_name(self.db)
        self.db.create_collection(orphan_col_name)
        # Create the vertex collection
        vertex_col_name = generate_col_name(self.db)
        self.db.create_collection(vertex_col_name)
        # Create the edge collection
        edge_col_name = generate_col_name(self.db)
        self.db.create_collection(edge_col_name, is_edge=True)
        # Create the graph
        graph_name = generate_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_vertex_collection(self):
        # Create the vertex collection
        vertex_col_name = generate_col_name(self.db)
        self.db.create_collection(vertex_col_name)
        # Create the graph
        graph_name = generate_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,
#.........这里部分代码省略.........
开发者ID:allanino,项目名称:python-arango,代码行数:103,代码来源:test_graphs.py

示例11: BatchRequestTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class BatchRequestTest(unittest.TestCase):
    """Tests for ArangoDB transactions."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        self.col_name01 = generate_col_name(self.db)
        self.col01 = self.db.create_collection(self.col_name01)
        self.col_name02 = generate_col_name(self.db)
        self.col02 = self.db.create_collection(self.col_name02)

        # Test database cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    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)

    def test_execute_transaction_with_params(self):
        action = """
            function (params) {
                var db = require('internal').db;
                db.%s.save({ _key: 'doc11', val: params.val1 });
                db.%s.save({ _key: 'doc12', val: params.val2 });
                return 'success!';
            }
        """ % (self.col_name01, self.col_name02)

        params = {"val1": 1, "val2": 2}

        res = self.db.execute_transaction(
            action=action,
            read_collections=[self.col_name01, self.col_name02],
            write_collections=[self.col_name01, self.col_name02],
            params=params,
            wait_for_sync=True,
            lock_timeout=10000
        )

        self.assertEqual(res, "success!")
        self.assertIn("doc11", self.col01)
        self.assertIn("doc12", self.col02)
        self.assertEqual(self.col01["doc11"]["val"], params["val1"])
        self.assertEqual(self.col02["doc12"]["val"], params["val2"])
开发者ID:allanino,项目名称:python-arango,代码行数:65,代码来源:test_transactions.py

示例12: Arango

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
import os
import sys
import uuid
from arango import Arango

db_name = 'fstest'
col_name = 'filesystem'
arango = Arango(host="localhost", port=8529)

try:
    arango.delete_database(db_name)
except:
    pass

db = arango.create_database(db_name)
graph = db.create_graph('filesystem')
fsnodes = db.create_collection('fsnodes')
graph.create_vertex_collection('fsnodes')

db.create_collection('contains', is_edge=True)

graph.create_edge_definition(
        edge_collection='contains',
        from_vertex_collections=['fsnodes'],
        to_vertex_collections=['fsnodes'])


for dirname, dirnames, filenames in os.walk(sys.argv[1]):
    key = dirname.replace('/', '_')
    d = dict(type='dir', dirname=dirname, _key=key)
    graph.create_vertex('fsnodes', d)
开发者ID:zopyx,项目名称:python-arango,代码行数:33,代码来源:test2.py

示例13: ArangoDBQueryTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class ArangoDBQueryTest(unittest.TestCase):
    """Tests for ArangoDB AQL queries."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        self.col_name = generate_col_name(self.db)
        self.db.create_collection(self.col_name)

        # Test database cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_explain_query(self):
        self.assertRaises(
            AQLQueryValidateError,
            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(
            AQLQueryValidateError,
            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.import_documents([
            {"_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.import_documents([
            {"_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"]
        )
开发者ID:allanino,项目名称:python-arango,代码行数:91,代码来源:test_aql_queries.py

示例14: CollectionManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class CollectionManagementTest(unittest.TestCase):
    """Tests for managing ArangoDB collections."""

    def setUp(self):
        self.arango = Arango()
        self.db_name = get_next_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)

        # Test database cleaup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    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"])

    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 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 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_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_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"})

#.........这里部分代码省略.........
开发者ID:zopyx,项目名称:python-arango,代码行数:103,代码来源:test_collections.py

示例15: EdgeManagementTest

# 需要导入模块: from arango import Arango [as 别名]
# 或者: from arango.Arango import create_database [as 别名]
class EdgeManagementTest(unittest.TestCase):
    """Tests for managing ArangoDB edges."""

    def setUp(self):
        # Create the test database
        self.arango = Arango()
        self.db_name = generate_db_name(self.arango)
        self.db = self.arango.create_database(self.db_name)
        # Create the test vertex collection
        self.vertex_col_name = generate_col_name(self.db)
        self.vertex_col = self.db.create_collection(self.vertex_col_name)
        # Create the test edge collection
        self.edge_col_name = generate_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 = generate_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 cleanup
        self.addCleanup(self.arango.delete_database,
                        name=self.db_name, safe_delete=True)

    def test_create_edge(self):
        self.graph.create_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(len(self.edge_col), 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.create_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"),
#.........这里部分代码省略.........
开发者ID:allanino,项目名称:python-arango,代码行数:103,代码来源:test_edges.py


注:本文中的arango.Arango.create_database方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。