Exemplo n.º 1
0
    def db(self, name='_system', username='******', password='', verify=False):
        """Connect to a database and return the database API wrapper.

        :param name: Database name.
        :type name: str | unicode
        :param username: Username for basic authentication.
        :type username: str | unicode
        :param password: Password for basic authentication.
        :type password: str | unicode
        :param verify: Verify the connection by sending a test request.
        :type verify: bool
        :return: Standard database API wrapper.
        :rtype: arango.database.StandardDatabase
        :raise arango.exceptions.ServerConnectionError: If **verify** was set
            to True and the connection to ArangoDB fails.
        """
        connection = Connection(url=self._url,
                                db=name,
                                username=username,
                                password=password,
                                http_client=self._http_client)
        database = StandardDatabase(connection)

        if verify:  # Check the server connection by making a read API call
            try:
                database.ping()
            except ServerConnectionError as err:
                raise err
            except Exception as err:
                raise ServerConnectionError('bad connection: {}'.format(err))

        return database
Exemplo n.º 2
0
    def db(self, name='_system', username='******', password='', verify=False):
        """Connect to an ArangoDB database and return the database API wrapper.

        :param name: Database name.
        :type name: str | unicode
        :param username: Username for basic authentication.
        :type username: str | unicode
        :param password: Password for basic authentication.
        :type password: str | unicode
        :param verify: Verify the connection by sending a test request.
        :type verify: bool
        :return: Standard database API wrapper.
        :rtype: arango.database.StandardDatabase
        :raise arango.exceptions.ServerConnectionError: If **verify** was set
            to True and the connection fails.
        """
        connection = Connection(hosts=self._hosts,
                                host_resolver=self._host_resolver,
                                sessions=self._sessions,
                                db_name=name,
                                username=username,
                                password=password,
                                http_client=self._http,
                                serializer=self._serializer,
                                deserializer=self._deserializer)
        if verify:
            try:
                connection.ping()
            except ServerConnectionError as err:
                raise err
            except Exception as err:
                raise ServerConnectionError('bad connection: {}'.format(err))

        return StandardDatabase(connection)
Exemplo n.º 3
0
def pytest_generate_tests(metafunc):
    tst_db = global_data['tst_db']
    bad_db = global_data['bad_db']

    tst_dbs = [tst_db]
    bad_dbs = [bad_db]

    if global_data['complete']:
        test = metafunc.module.__name__.split('.test_', 1)[-1]
        tst_conn = tst_db._conn
        bad_conn = bad_db._conn

        if test in {'collection', 'document', 'graph', 'aql', 'index'}:
            # Add test transaction databases
            tst_txn_db = StandardDatabase(tst_conn)
            tst_txn_db._executor = TestTransactionExecutor(tst_conn)
            tst_dbs.append(tst_txn_db)
            bad_txn_db = StandardDatabase(bad_conn)
            bad_txn_db._executor = TestTransactionExecutor(bad_conn)
            bad_dbs.append(bad_txn_db)

        if test not in {
            'async',
            'batch',
            'transaction',
            'client',
            'exception',
            'view',
            'replication'
        }:
            # Add test async databases
            tst_async_db = StandardDatabase(tst_conn)
            tst_async_db._executor = TestAsyncExecutor(tst_conn)
            tst_dbs.append(tst_async_db)
            bad_async_db = StandardDatabase(bad_conn)
            bad_async_db._executor = TestAsyncExecutor(bad_conn)
            bad_dbs.append(bad_async_db)

            # Add test batch databases
            tst_batch_db = StandardDatabase(tst_conn)
            tst_batch_db._executor = TestBatchExecutor(tst_conn)
            tst_dbs.append(tst_batch_db)
            bad_batch_bdb = StandardDatabase(bad_conn)
            bad_batch_bdb._executor = TestBatchExecutor(bad_conn)
            bad_dbs.append(bad_batch_bdb)

    if 'db' in metafunc.fixturenames and 'bad_db' in metafunc.fixturenames:
        metafunc.parametrize('db,bad_db', zip(tst_dbs, bad_dbs))

    elif 'db' in metafunc.fixturenames:
        metafunc.parametrize('db', tst_dbs)

    elif 'bad_db' in metafunc.fixturenames:
        metafunc.parametrize('bad_db', bad_dbs)
Exemplo n.º 4
0
def pytest_generate_tests(metafunc):
    test_name = metafunc.module.__name__.split('.test_', 1)[-1]

    dbs = [_db]
    bad_dbs = [_bad_db]

    if metafunc.config.getoption('complete'):

        if test_name in {'collection', 'document', 'graph', 'aql', 'index'}:
            # Add test transaction databases
            tdb = StandardDatabase(_db._conn)
            tdb._executor = TestTransactionExecutor(_db._conn)
            tdb._is_transaction = True
            dbs.append(tdb)

            bad_tdb = StandardDatabase(_bad_db._conn)
            bad_tdb._executor = TestTransactionExecutor(_bad_db._conn)
            bad_dbs.append(bad_tdb)

        if test_name not in {
                'async', 'batch', 'transaction', 'client', 'exception'
        }:
            # Add test async databases
            adb = StandardDatabase(_db._conn)
            adb._executor = TestAsyncExecutor(_db._conn)
            dbs.append(adb)

            bad_adb = StandardDatabase(_bad_db._conn)
            bad_adb._executor = TestAsyncExecutor(_bad_db._conn)
            bad_dbs.append(bad_adb)

            # Add test batch databases
            bdb = StandardDatabase(_db._conn)
            bdb._executor = TestBatchExecutor(_db._conn)
            dbs.append(bdb)

            bad_bdb = StandardDatabase(_bad_db._conn)
            bad_bdb._executor = TestBatchExecutor(_bad_db._conn)
            bad_dbs.append(bad_bdb)

    if 'db' in metafunc.fixturenames and 'bad_db' in metafunc.fixturenames:
        metafunc.parametrize('db,bad_db', zip(dbs, bad_dbs))
    elif 'db' in metafunc.fixturenames:
        metafunc.parametrize('db', dbs)
    elif 'bad_db' in metafunc.fixturenames:
        metafunc.parametrize('bad_db', bad_dbs)
Exemplo n.º 5
0
def pytest_generate_tests(metafunc):
    tst_db = global_data.tst_db
    bad_db = global_data.bad_db

    tst_dbs = [tst_db]
    bad_dbs = [bad_db]

    if global_data.complete:
        test = metafunc.module.__name__.split(".test_", 1)[-1]
        tst_conn = tst_db._conn
        bad_conn = bad_db._conn

        if test in {"aql", "collection", "document", "index"}:
            # Add test transaction databases
            tst_txn_db = StandardDatabase(tst_conn)
            tst_txn_db._executor = TestTransactionApiExecutor(tst_conn)
            tst_dbs.append(tst_txn_db)
            bad_txn_db = StandardDatabase(bad_conn)
            bad_txn_db._executor = TestTransactionApiExecutor(bad_conn)
            bad_dbs.append(bad_txn_db)

            # Add test async databases
            tst_async_db = StandardDatabase(tst_conn)
            tst_async_db._executor = TestAsyncApiExecutor(tst_conn)
            tst_dbs.append(tst_async_db)
            bad_async_db = StandardDatabase(bad_conn)
            bad_async_db._executor = TestAsyncApiExecutor(bad_conn)
            bad_dbs.append(bad_async_db)

            # Add test batch databases
            tst_batch_db = StandardDatabase(tst_conn)
            tst_batch_db._executor = TestBatchExecutor(tst_conn)
            tst_dbs.append(tst_batch_db)
            bad_batch_bdb = StandardDatabase(bad_conn)
            bad_batch_bdb._executor = TestBatchExecutor(bad_conn)
            bad_dbs.append(bad_batch_bdb)

    if "db" in metafunc.fixturenames and "bad_db" in metafunc.fixturenames:
        metafunc.parametrize("db,bad_db", zip(tst_dbs, bad_dbs))

    elif "db" in metafunc.fixturenames:
        metafunc.parametrize("db", tst_dbs)

    elif "bad_db" in metafunc.fixturenames:
        metafunc.parametrize("bad_db", bad_dbs)
Exemplo n.º 6
0
    def db(
        self,
        name: str = "_system",
        username: str = "root",
        password: str = "",
        verify: bool = False,
        auth_method: str = "basic",
        superuser_token: Optional[str] = None,
    ) -> StandardDatabase:
        """Connect to an ArangoDB database and return the database API wrapper.

        :param name: Database name.
        :type name: str
        :param username: Username for basic authentication.
        :type username: str
        :param password: Password for basic authentication.
        :type password: str
        :param verify: Verify the connection by sending a test request.
        :type verify: bool
        :param auth_method: HTTP authentication method. Accepted values are
            "basic" (default) and "jwt". If set to "jwt", the token is
            refreshed automatically using ArangoDB username and password. This
            assumes that the clocks of the server and client are synchronized.
        :type auth_method: str
        :param superuser_token: User generated token for superuser access.
            If set, parameters **username**, **password** and **auth_method**
            are ignored. This token is not refreshed automatically.
        :type superuser_token: str
        :return: Standard database API wrapper.
        :rtype: arango.database.StandardDatabase
        :raise arango.exceptions.ServerConnectionError: If **verify** was set
            to True and the connection fails.
        """
        connection: Connection

        if superuser_token is not None:
            connection = JwtSuperuserConnection(
                hosts=self._hosts,
                host_resolver=self._host_resolver,
                sessions=self._sessions,
                db_name=name,
                http_client=self._http,
                serializer=self._serializer,
                deserializer=self._deserializer,
                superuser_token=superuser_token,
            )
        elif auth_method.lower() == "basic":
            connection = BasicConnection(
                hosts=self._hosts,
                host_resolver=self._host_resolver,
                sessions=self._sessions,
                db_name=name,
                username=username,
                password=password,
                http_client=self._http,
                serializer=self._serializer,
                deserializer=self._deserializer,
            )
        elif auth_method.lower() == "jwt":
            connection = JwtConnection(
                hosts=self._hosts,
                host_resolver=self._host_resolver,
                sessions=self._sessions,
                db_name=name,
                username=username,
                password=password,
                http_client=self._http,
                serializer=self._serializer,
                deserializer=self._deserializer,
            )
        else:
            raise ValueError(f"invalid auth_method: {auth_method}")

        if verify:
            try:
                connection.ping()
            except ServerConnectionError as err:
                raise err
            except Exception as err:
                raise ServerConnectionError(f"bad connection: {err}")

        return StandardDatabase(connection)