From 5b28160ca7cd1f073bf77b608efd241c81df0677 Mon Sep 17 00:00:00 2001 From: grahamlyons Date: Mon, 25 Nov 2024 11:39:22 +0000 Subject: [PATCH 1/2] add -e flag in test script Ensure that the script will not continue and report an appropriate exit status if there is an error. --- run_tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/run_tests.sh b/run_tests.sh index 7a6b971..a7c873a 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,4 +1,7 @@ #!/bin/bash + +set -e + PYTHON=python3 while [ $# -gt 0 ]; do case "$1" in From 4e08434df395ac1293821b91f58120354cbced31 Mon Sep 17 00:00:00 2001 From: grahamlyons Date: Mon, 25 Nov 2024 11:41:29 +0000 Subject: [PATCH 2/2] add boolean flag to skip loading Foxx services This allows the library to be used when Foxx is disabled on the server, preventing an exception being raised by trying to load available services. --- pyArango/connection.py | 6 +++++- pyArango/database.py | 3 ++- pyArango/tests/tests.py | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pyArango/connection.py b/pyArango/connection.py index c7fa332..4c944be 100644 --- a/pyArango/connection.py +++ b/pyArango/connection.py @@ -192,6 +192,8 @@ class Connection(object): max number of open connections. (Not intended for grequest) timeout: int number of seconds to wait on a hanging connection before giving up + foxx_enabled: bool + when set to False prevents attempted loading of Foxx services """ LOAD_BLANCING_METHODS = {'round-robin', 'random'} @@ -213,7 +215,8 @@ def __init__( max_retries=5, max_conflict_retries=5, pool_maxsize=10, - timeout=30 + timeout=30, + foxx_enabled=True, ): if loadBalancing not in Connection.LOAD_BLANCING_METHODS: @@ -230,6 +233,7 @@ def __init__( self.max_conflict_retries = max_conflict_retries self.action = ConnectionAction(self) self.timeout = timeout + self.foxx_enabled = foxx_enabled self.databases = {} self.verbose = verbose diff --git a/pyArango/database.py b/pyArango/database.py index 1dfe24e..b3f6d2a 100644 --- a/pyArango/database.py +++ b/pyArango/database.py @@ -95,7 +95,8 @@ def reload(self): "reloads collections and graphs" self.reloadCollections() self.reloadGraphs() - self.foxx.reload() + if self.connection.foxx_enabled: + self.foxx.reload() def createCollection(self, className = 'Collection', **colProperties): """Creates a collection and returns it. diff --git a/pyArango/tests/tests.py b/pyArango/tests/tests.py index d08889a..31c0fbf 100644 --- a/pyArango/tests/tests.py +++ b/pyArango/tests/tests.py @@ -2,10 +2,13 @@ import os from unittest.mock import MagicMock, patch +from requests import HTTPError + from pyArango.connection import * from pyArango.database import * from pyArango.collection import * from pyArango.document import * +from pyArango.foxx import Foxx from pyArango.query import * from pyArango.graph import * from pyArango.users import * @@ -32,6 +35,9 @@ def setUp(self): except CreationError: pass + url = f"{self.conn.getURL()}/database/test_db_foxx_error" + self.conn.session.delete(url) + self.db = self.conn["test_db_2"] self.admin = Admin(self.conn) self.is_cluster = self.admin.is_cluster() @@ -1152,6 +1158,19 @@ def test_timeout_parameter(self): # Verify that the Connection session was created with the correct timeout assert connection.session.timeout == timeout + + def test_foxx_disabled(self): + with patch("pyArango.database.Foxx", autospec=True) as Moxx: + moxx = MagicMock(spec_set=Foxx) + moxx.reload.side_effect = HTTPError() + Moxx.return_value = moxx + connection = Connection(arangoURL=ARANGODB_URL, username=ARANGODB_ROOT_USERNAME, password=ARANGODB_ROOT_PASSWORD, foxx_enabled=False) + try: + connection.createDatabase(name="test_db_foxx_error") + except HTTPError: + self.fail("Should not raise error") + + if __name__ == "__main__": # Change default username/password in bash like this: