Skip to content

Commit

Permalink
Merge branch 'main' into DE-749
Browse files Browse the repository at this point in the history
  • Loading branch information
aMahanna committed Apr 23, 2024
2 parents 8b1d10a + b389b80 commit f6cef2b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions arango/client.py
Expand Up @@ -12,7 +12,7 @@
JwtSuperuserConnection,
)
from arango.database import StandardDatabase
from arango.exceptions import ServerConnectionError
from arango.exceptions import ArangoClientError, ServerConnectionError
from arango.http import (
DEFAULT_REQUEST_TIMEOUT,
DefaultHTTPClient,
Expand Down Expand Up @@ -300,6 +300,6 @@ def db(
except ServerConnectionError as err:
raise err
except Exception as err:
raise ServerConnectionError(f"bad connection: {err}")
raise ArangoClientError(f"bad connection: {err}")

return StandardDatabase(connection)
8 changes: 6 additions & 2 deletions arango/connection.py
Expand Up @@ -226,9 +226,13 @@ def ping(self) -> int:
request = Request(method="get", endpoint="/_api/collection")
resp = self.send_request(request)
if resp.status_code in {401, 403}:
raise ServerConnectionError("bad username/password or token is expired")
raise ServerConnectionError(
resp, request, "bad username/password or token is expired"
)
if not resp.is_success: # pragma: no cover
raise ServerConnectionError(resp.error_message or "bad server response")
raise ServerConnectionError(
resp, request, resp.error_message or "bad server response"
)
return resp.status_code

@abstractmethod
Expand Down
9 changes: 5 additions & 4 deletions arango/database.py
Expand Up @@ -1442,10 +1442,11 @@ def create_collection(
:raise arango.exceptions.CollectionCreateError: If create fails.
"""
key_options: Json = {"type": key_generator, "allowUserKeys": user_keys}
if key_increment is not None:
key_options["increment"] = key_increment
if key_offset is not None:
key_options["offset"] = key_offset
if key_generator == "autoincrement":
if key_increment is not None:
key_options["increment"] = key_increment
if key_offset is not None:
key_options["offset"] = key_offset

data: Json = {
"name": name,
Expand Down
2 changes: 1 addition & 1 deletion arango/exceptions.py
Expand Up @@ -614,7 +614,7 @@ class PregelJobDeleteError(ArangoServerError):
#####################


class ServerConnectionError(ArangoClientError):
class ServerConnectionError(ArangoServerError):
"""Failed to connect to ArangoDB server."""


Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Expand Up @@ -8,7 +8,7 @@

from arango.client import ArangoClient
from arango.database import StandardDatabase
from arango.exceptions import ServerConnectionError
from arango.exceptions import ArangoClientError, ServerConnectionError
from arango.http import DefaultHTTPClient, DeflateRequestCompression
from arango.resolver import FallbackHostResolver, RandomHostResolver, SingleHostResolver
from tests.helpers import (
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_client_bad_connection(db, username, password, cluster):

# Test connection with invalid host URL
client = ArangoClient(hosts="http://127.0.0.1:8500")
with pytest.raises(ServerConnectionError) as err:
with pytest.raises(ArangoClientError) as err:
client.db(db.name, username, password, verify=True)
assert "bad connection" in str(err.value)

Expand Down
11 changes: 9 additions & 2 deletions tests/test_collection.py
Expand Up @@ -190,14 +190,21 @@ def test_collection_management(db, bad_db, cluster):
}
]

col = db.create_collection(
name=col_name, key_generator="autoincrement", key_increment=9, key_offset=100
)
key_options = col.properties()["key_options"]
assert key_options["key_generator"] == "autoincrement"
assert key_options["key_increment"] == 9
assert key_options["key_offset"] == 100
db.delete_collection(col_name)

col = db.create_collection(
name=col_name,
sync=True,
system=False,
key_generator="traditional",
user_keys=False,
key_increment=9,
key_offset=100,
edge=True,
shard_count=2,
shard_fields=["test_attr:"],
Expand Down

0 comments on commit f6cef2b

Please sign in to comment.