Skip to content

[DE-545] UTF-8 names #260

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

Merged
merged 4 commits into from
Jul 28, 2023
Merged
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
2 changes: 2 additions & 0 deletions tests/static/cluster.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ jwt-secret = /tests/static/keyfile

[args]
all.database.password = passwd
# Extended names can be used starting with 3.11
# all.database.extended-names = true
all.log.api-enabled = true
2 changes: 2 additions & 0 deletions tests/static/single.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ jwt-secret = /tests/static/keyfile

[args]
all.database.password = passwd
# Extended names can be used starting with 3.11
# all.database.extended-names = true
94 changes: 93 additions & 1 deletion tests/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import pytest
from packaging import version

from arango.client import ArangoClient
from arango.collection import StandardCollection
from arango.exceptions import (
CollectionChecksumError,
Expand All @@ -13,8 +17,15 @@
CollectionStatisticsError,
CollectionTruncateError,
CollectionUnloadError,
DatabaseDeleteError,
)
from tests.helpers import (
assert_raises,
extract,
generate_col_name,
generate_string,
generate_username,
)
from tests.helpers import assert_raises, extract, generate_col_name


def test_collection_attributes(db, col, username):
Expand Down Expand Up @@ -228,3 +239,84 @@ def test_collection_management(db, bad_db, cluster):
with assert_raises(CollectionRenameError) as err:
bad_db.collection(new_name).rename(new_name)
assert err.value.error_code in {11, 1228}


@pytest.fixture
def special_collection_names(db):
names = ["abc123", "maçã", "mötör", "😀", "ﻚﻠﺑ ﻞﻄﻴﻓ", "かわいい犬"]

yield names

for name in names:
try:
db.delete_collection(name)
except CollectionDeleteError:
pass


# Code duplication from `test_database.py`...
@pytest.fixture
def special_db_names(sys_db):
names = ["abc123", "maçã", "mötör", "😀", "ﻚﻠﺑ ﻞﻄﻴﻓ", "かわいい犬"]

yield names

for name in names:
try:
sys_db.delete_database(name)
except DatabaseDeleteError:
pass


def test_collection_utf8(db, db_version, special_collection_names):
if db_version < version.parse("3.11.0"):
pytest.skip("UTF8 collection names require ArangoDB 3.11+")

for name in special_collection_names:
create_and_delete_collection(db, name)


# Not sure if this belongs in here or in `test_database.py`...
def test_database_and_collection_utf8(
sys_db, db_version, special_collection_names, special_db_names
):
if db_version < version.parse("3.11.0"):
pytest.skip("UTF8 collection names require ArangoDB 3.11+")

client = ArangoClient(hosts="http://127.0.0.1:8529")
for db_name in special_db_names:
username = generate_username()
password = generate_string()

assert sys_db.create_database(
name=db_name,
users=[
{
"active": True,
"username": username,
"password": password,
}
],
)

assert sys_db.has_database(db_name)

db = client.db(db_name, username, password, verify=True)

for col_name in special_collection_names:
create_and_delete_collection(db, col_name)

assert sys_db.delete_database(db_name)


def create_and_delete_collection(db, name):
col = db.create_collection(name)
assert col.name == name
assert db.has_collection(name) is True

index_id = col.add_hash_index(fields=["foo"])["name"]
assert index_id == col.indexes()[-1]["name"]
assert col.delete_index(index_id) is True

assert db.delete_collection(name) is True
assert db.has_collection(name) is False
26 changes: 26 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from datetime import datetime

import pytest
from packaging import version

from arango.aql import AQL
from arango.backup import Backup
from arango.cluster import Cluster
Expand Down Expand Up @@ -281,3 +284,26 @@ def test_database_management(db, sys_db, bad_db):
sys_db.delete_database(db_name)
assert err.value.error_code in {FORBIDDEN, DATABASE_NOT_FOUND}
assert sys_db.delete_database(db_name, ignore_missing=True) is False


@pytest.fixture
def special_db_names(sys_db):
names = ["abc123", "maçã", "mötör", "😀", "ﻚﻠﺑ ﻞﻄﻴﻓ", "かわいい犬"]

yield names

for name in names:
try:
sys_db.delete_database(name)
except DatabaseDeleteError:
pass


def test_database_utf8(sys_db, db_version, special_db_names):
if db_version < version.parse("3.11.0"):
pytest.skip("UTF8 collection names require ArangoDB 3.11+")

for name in special_db_names:
assert sys_db.create_database(name)
assert sys_db.has_database(name)
assert sys_db.delete_database(name)