diff --git a/arango/formatter.py b/arango/formatter.py index 71686b4f..e159c23f 100644 --- a/arango/formatter.py +++ b/arango/formatter.py @@ -275,6 +275,11 @@ def format_collection(body: Json) -> Json: if "internalValidatorType" in body: result["internal_validator_type"] = body["internalValidatorType"] + if "deleted" in body: + result["deleted"] = body["deleted"] + if "supportsRBAC" in body: + result["supportsRBAC"] = body["supportsRBAC"] + return verify_format(body, result) diff --git a/tests/helpers.py b/tests/helpers.py index b6fa76ce..c9d84075 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -6,7 +6,11 @@ import pytest from arango.cursor import Cursor -from arango.exceptions import AsyncExecuteError, TransactionInitError +from arango.exceptions import ( + AsyncExecuteError, + ReplicationClusterInventoryError, + TransactionInitError, +) def generate_db_name(): @@ -190,3 +194,40 @@ def assert_raises(*exc): :type: exc """ return pytest.raises(exc + (AsyncExecuteError, TransactionInitError)) + + +def wait_for_cluster_resilient(sys_db): + collections_in_sync = False + max_attempts = 100 + + while not collections_in_sync and max_attempts > 0: + count_in_sync = 0 + count_still_waiting = 0 + + try: + inventory = sys_db.replication.cluster_inventory(include_system=True) + except ReplicationClusterInventoryError: + print("Failed to get cluster inventory, retrying...") + time.sleep(1) + max_attempts -= 1 + continue + + collections_in_sync = True + for col in inventory["collections"]: + if not col["all_in_sync"]: + count_still_waiting += 1 + collections_in_sync = False + else: + count_in_sync += 1 + + if not collections_in_sync: + if max_attempts % 50 == 0: + print(inventory) + print(f"In sync: {count_in_sync}") + print(f"Still not in sync: {count_still_waiting}") + time.sleep(1) + + max_attempts -= 1 + + if not collections_in_sync: + raise Exception("Collections didn't come in sync!") diff --git a/tests/static/cluster-3.12.conf b/tests/static/cluster-3.12.conf index d33e07a3..37737111 100644 --- a/tests/static/cluster-3.12.conf +++ b/tests/static/cluster-3.12.conf @@ -13,3 +13,7 @@ all.database.extended-names = true all.log.api-enabled = true all.javascript.allow-admin-execute = true all.server.options-api = admin +all.javascript.files-allowlist = ".*"; +all.javascript.environment-variables-allowlist = ".*"; +all.javascript.endpoints-allowlist = ".*"; +all.javascript.startup-options-allowlist = ".*"; diff --git a/tests/static/single-3.12.conf b/tests/static/single-3.12.conf index d5df3aa9..3c438832 100644 --- a/tests/static/single-3.12.conf +++ b/tests/static/single-3.12.conf @@ -11,3 +11,7 @@ all.database.password = passwd all.database.extended-names = true all.javascript.allow-admin-execute = true all.server.options-api = admin +all.javascript.files-allowlist = ".*"; +all.javascript.environment-variables-allowlist = ".*"; +all.javascript.endpoints-allowlist = ".*"; +all.javascript.startup-options-allowlist = ".*"; diff --git a/tests/test_backup.py b/tests/test_backup.py index 150b9e16..be13578c 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -1,5 +1,3 @@ -import time - import pytest from packaging import version @@ -11,46 +9,8 @@ BackupGetError, BackupRestoreError, BackupUploadError, - ReplicationClusterInventoryError, ) -from tests.helpers import assert_raises - - -def wait_for_cluster_resilient(sys_db): - collections_in_sync = False - max_attempts = 100 - - while not collections_in_sync and max_attempts > 0: - count_in_sync = 0 - count_still_waiting = 0 - - try: - inventory = sys_db.replication.cluster_inventory(include_system=True) - except ReplicationClusterInventoryError: - print("Failed to get cluster inventory, retrying...") - time.sleep(1) - max_attempts -= 1 - continue - - collections_in_sync = True - for col in inventory["collections"]: - if not col["all_in_sync"]: - count_still_waiting += 1 - collections_in_sync = False - else: - count_in_sync += 1 - - if not collections_in_sync: - if max_attempts % 50 == 0: - print(inventory) - print(f"In sync: {count_in_sync}") - print(f"Still not in sync: {count_still_waiting}") - time.sleep(1) - - max_attempts -= 1 - - if not collections_in_sync: - raise Exception("Collections didn't come in sync!") +from tests.helpers import assert_raises, wait_for_cluster_resilient def test_backup_management(sys_db, bad_db, cluster, skip_tests, db_version): diff --git a/tests/test_collection.py b/tests/test_collection.py index 56af95cd..ad5bc581 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -27,6 +27,7 @@ generate_col_name, generate_string, generate_username, + wait_for_cluster_resilient, ) @@ -170,7 +171,10 @@ def test_collection_misc_methods(col, bad_col, cluster): assert result == info -def test_collection_management(db, bad_db, cluster): +def test_collection_management(sys_db, db, bad_db, cluster): + if cluster: + wait_for_cluster_resilient(sys_db) + # Test create collection col_name = generate_col_name() assert db.has_collection(col_name) is False @@ -249,25 +253,33 @@ def test_collection_management(db, bad_db, cluster): # schema must not be empty db.create_collection(name=col_name, schema={}) - col = db.create_collection( - name=col_name, - sync=True, - system=False, - key_generator="traditional", - user_keys=False, - edge=True, - shard_count=2, - shard_fields=["test_attr:"], - replication_factor=1, - sync_replication=False, - enforce_replication_factor=False, - sharding_strategy="community-compat", - smart_join_attribute="test_attr", - write_concern=1, - schema=schema, - computedValues=computed_values, - ) + for _ in range(10): + try: + col = db.create_collection( + name=col_name, + sync=True, + system=False, + key_generator="traditional", + user_keys=False, + edge=True, + shard_count=2, + shard_fields=["test_attr:"], + replication_factor=1, + sync_replication=False, + enforce_replication_factor=False, + sharding_strategy="community-compat", + smart_join_attribute="test_attr", + write_concern=1, + schema=schema, + computedValues=computed_values, + ) + except CollectionCreateError as err: + if err.error_code != DUPLICATE_NAME or not db.has_collection(col_name): + print(f"Failed to create collection with name {col_name}: {err}") + time.sleep(3) + continue assert db.has_collection(col_name) is True + col = db.collection(col_name) if cluster: for details in (False, True):