Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Foxx to be disabled #248

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pyArango/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand All @@ -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:
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pyArango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions pyArango/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

set -e

PYTHON=python3
while [ $# -gt 0 ]; do
case "$1" in
Expand Down