Skip to content

Commit 8519aa8

Browse files
authored
Adding schema validation (#83)
* Waiting for backup restore * Schema validation * Bumping version number * Added await
1 parent 1791684 commit 8519aa8

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

arangoasync/collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ async def configure(
570570
571571
Raises:
572572
CollectionConfigureError: If configuration fails.
573+
ValueError: If parameters are invalid.
573574
574575
References:
575576
- `change-the-properties-of-a-collection <https://docs.arango.ai/arangodb/stable/develop/http-api/collections/#change-the-properties-of-a-collection>`__
@@ -582,6 +583,8 @@ async def configure(
582583
if replication_factor is not None:
583584
data["replicationFactor"] = replication_factor
584585
if schema is not None:
586+
if not isinstance(schema, dict) or len(schema) == 0:
587+
raise ValueError("schema parameter must be a non-empty dict")
585588
data["schema"] = schema
586589
if wait_for_sync is not None:
587590
data["waitForSync"] = wait_for_sync

arangoasync/database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ async def create_collection(
694694
key_options.validate()
695695
data["keyOptions"] = key_options.to_dict()
696696
if schema is not None:
697+
if not isinstance(schema, dict) or len(schema) == 0:
698+
raise ValueError("schema parameter must be a non-empty dict")
697699
data["schema"] = schema
698700
if shard_keys is not None:
699701
data["shardKeys"] = shard_keys

arangoasync/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.1.0"
1+
__version__ = "1.2.0"

tests/test_backup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import asyncio
2+
13
import pytest
24
from packaging import version
35

@@ -36,6 +38,10 @@ async def test_backup(
3638
assert "list" in result
3739
result = await backup.restore(backup_id)
3840
assert "previous" in result
41+
42+
# Wait for restore to complete
43+
await asyncio.sleep(10)
44+
3945
config = {"local": {"type": "local"}}
4046
result = await backup.upload(backup_id, repository=backup_path, config=config)
4147
assert "uploadId" in result

tests/test_collection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ async def test_collection_misc_methods(doc_col, bad_col, docs, cluster):
5050
assert new_properties.wait_for_sync == wfs
5151
with pytest.raises(CollectionConfigureError):
5252
await bad_col.configure(wait_for_sync=wfs)
53+
with pytest.raises(ValueError):
54+
await doc_col.configure(schema={})
5355

5456
# Statistics
5557
statistics = await doc_col.statistics()

tests/test_database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ async def test_create_drop_collection(db, bad_db, cluster):
352352
await db.create_collection(generate_col_name(), col_type=db)
353353
with pytest.raises(ValueError):
354354
await db.create_collection(generate_col_name(), key_options={})
355+
with pytest.raises(ValueError):
356+
await db.create_collection(generate_col_name(), schema={})
355357

356358
# Drop the newly created collection
357359
assert await db.delete_collection(col_name) is True

0 commit comments

Comments
 (0)