From 7370ea6c5e183f8177e60e689059ba56abf55bad Mon Sep 17 00:00:00 2001 From: Kirsten Hunter Date: Wed, 28 Feb 2024 09:25:04 -0800 Subject: [PATCH 1/4] Adding drop function to the collection --- astrapy/idiomatic/collection.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/astrapy/idiomatic/collection.py b/astrapy/idiomatic/collection.py index 862db9ed..7b53af10 100644 --- a/astrapy/idiomatic/collection.py +++ b/astrapy/idiomatic/collection.py @@ -90,6 +90,9 @@ def set_caller( caller_version=caller_version, ) + def drop(self, collection_name: str) -> API_RESPONSE: + return self.astra_db.delete_collection(collection_name) + @unsupported def find_raw_batches(*pargs: Any, **kwargs: Any) -> Any: ... @@ -197,6 +200,10 @@ def set_caller( caller_version=caller_version, ) + async def drop(self, collection_name: str) -> API_RESPONSE: + return await self.astra_db.delete_collection(collection_name) + + @unsupported async def find_raw_batches(*pargs: Any, **kwargs: Any) -> Any: ... From 41752f0d537bacfa5d62f21de64e1ef45302fc4e Mon Sep 17 00:00:00 2001 From: Kirsten Hunter Date: Wed, 28 Feb 2024 09:59:51 -0800 Subject: [PATCH 2/4] Adding drop collection to collection --- astrapy/idiomatic/collection.py | 4 ++-- .../idiomatic/integration/test_collections_async.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/astrapy/idiomatic/collection.py b/astrapy/idiomatic/collection.py index 7b53af10..0d866d73 100644 --- a/astrapy/idiomatic/collection.py +++ b/astrapy/idiomatic/collection.py @@ -91,7 +91,7 @@ def set_caller( ) def drop(self, collection_name: str) -> API_RESPONSE: - return self.astra_db.delete_collection(collection_name) + return self.database.delete_collection(collection_name) @unsupported def find_raw_batches(*pargs: Any, **kwargs: Any) -> Any: ... @@ -201,7 +201,7 @@ def set_caller( ) async def drop(self, collection_name: str) -> API_RESPONSE: - return await self.astra_db.delete_collection(collection_name) + return await self.database.delete_collection(collection_name) @unsupported diff --git a/tests/idiomatic/integration/test_collections_async.py b/tests/idiomatic/integration/test_collections_async.py index b547408e..95e7bf50 100644 --- a/tests/idiomatic/integration/test_collections_async.py +++ b/tests/idiomatic/integration/test_collections_async.py @@ -16,6 +16,8 @@ from astrapy import AsyncCollection, AsyncDatabase +TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME = "ephemeral_v_col" +TEST_CREATE_DELETE_NONVECTOR_COLLECTION_NAME = "ephemeral_non_v_col" class TestCollectionsAsync: @pytest.mark.describe("test of instantiating Collection, async") @@ -74,6 +76,17 @@ async def test_collection_set_caller_async( ) assert col1 == col2 + @pytest.mark.describe("should create and destroy a vector collection using collection drop (async)") + async def test_create_destroy_collection(self, async_database: AsyncDatabase) -> None: + col = await async_database.create_collection( + name=TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME, dimension=2 + ) + assert isinstance(col, AsyncCollection) + del_res = await col.drop( + TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME + ) + assert del_res["status"]["ok"] == 1 + @pytest.mark.describe("test errors for unsupported Collection methods, async") async def test_collection_unsupported_methods_async( self, From b02b982af79f1f0f23dd18e44eca3a223cc262c8 Mon Sep 17 00:00:00 2001 From: Kirsten Hunter Date: Wed, 28 Feb 2024 10:25:35 -0800 Subject: [PATCH 3/4] Moving the tests into the right test files --- tests/idiomatic/conftest.py | 1 + .../integration/test_collections_async.py | 14 -------------- tests/idiomatic/integration/test_ddl_async.py | 13 ++++++++++++- tests/idiomatic/integration/test_ddl_sync.py | 15 +++++++++++++-- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/tests/idiomatic/conftest.py b/tests/idiomatic/conftest.py index cf5b4e68..2af01775 100644 --- a/tests/idiomatic/conftest.py +++ b/tests/idiomatic/conftest.py @@ -9,6 +9,7 @@ TEST_COLLECTION_INSTANCE_NAME = "test_coll_instance" TEST_COLLECTION_NAME = "id_test_collection" +TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME = "ephemeral_v_col" ASTRA_DB_SECONDARY_KEYSPACE = os.environ.get("ASTRA_DB_SECONDARY_KEYSPACE") diff --git a/tests/idiomatic/integration/test_collections_async.py b/tests/idiomatic/integration/test_collections_async.py index 3e00b02d..f2ae3881 100644 --- a/tests/idiomatic/integration/test_collections_async.py +++ b/tests/idiomatic/integration/test_collections_async.py @@ -16,9 +16,6 @@ from astrapy import AsyncCollection, AsyncDatabase -TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME = "ephemeral_v_col" -TEST_CREATE_DELETE_NONVECTOR_COLLECTION_NAME = "ephemeral_non_v_col" - class TestCollectionsAsync: @pytest.mark.describe("test of instantiating Collection, async") async def test_instantiate_collection_async( @@ -76,17 +73,6 @@ async def test_collection_set_caller_async( ) assert col1 == col2 - @pytest.mark.describe("should create and destroy a vector collection using collection drop (async)") - async def test_create_destroy_collection(self, async_database: AsyncDatabase) -> None: - col = await async_database.create_collection( - name=TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME, dimension=2 - ) - assert isinstance(col, AsyncCollection) - del_res = await col.drop( - TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME - ) - assert del_res["status"]["ok"] == 1 - @pytest.mark.describe("test errors for unsupported Collection methods, async") async def test_collection_unsupported_methods_async( self, diff --git a/tests/idiomatic/integration/test_ddl_async.py b/tests/idiomatic/integration/test_ddl_async.py index d053f652..7f97b72f 100644 --- a/tests/idiomatic/integration/test_ddl_async.py +++ b/tests/idiomatic/integration/test_ddl_async.py @@ -14,7 +14,7 @@ import pytest -from ..conftest import ASTRA_DB_SECONDARY_KEYSPACE, TEST_COLLECTION_NAME +from ..conftest import ASTRA_DB_SECONDARY_KEYSPACE, TEST_COLLECTION_NAME, TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME from astrapy import AsyncCollection, AsyncDatabase @@ -35,6 +35,17 @@ async def test_collection_lifecycle_async( assert col1 == col2 await async_database.drop_collection(TEST_LOCAL_COLLECTION_NAME) + @pytest.mark.describe("should create and destroy a vector collection using collection drop (async)") + async def async_test_create_destroy_collection(self, async_database: AsyncDatabase) -> None: + col = await async_database.create_collection( + name="test_col_drop", dimension=2 + ) + assert isinstance(col, AsyncCollection) + del_res = await col.drop( + "test_col_drop" + ) + assert del_res["status"]["ok"] == 1 + @pytest.mark.describe("test of Database list_collections, async") async def test_database_list_collections_async( self, diff --git a/tests/idiomatic/integration/test_ddl_sync.py b/tests/idiomatic/integration/test_ddl_sync.py index 3f7d60ca..d9377b5f 100644 --- a/tests/idiomatic/integration/test_ddl_sync.py +++ b/tests/idiomatic/integration/test_ddl_sync.py @@ -14,10 +14,9 @@ import pytest -from ..conftest import ASTRA_DB_SECONDARY_KEYSPACE, TEST_COLLECTION_NAME +from ..conftest import ASTRA_DB_SECONDARY_KEYSPACE, TEST_COLLECTION_NAME, TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME from astrapy import Collection, Database - class TestDDLSync: @pytest.mark.describe("test of collection creation, get, and then drop, sync") def test_collection_lifecycle_sync( @@ -35,6 +34,18 @@ def test_collection_lifecycle_sync( assert col1 == col2 sync_database.drop_collection(TEST_LOCAL_COLLECTION_NAME) + @pytest.mark.describe("should create and destroy a vector collection using collection drop ") + def test_create_destroy_collection(self, sync_database: Database) -> None: + col = sync_database.create_collection( + name="TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME", dimension=2 + ) + assert isinstance(col, Collection) + del_res = col.drop( + TEST_CREATE_DELETE_VECTOR_COLLECTION_NAME + ) + assert del_res["status"]["ok"] == 1 + + @pytest.mark.describe("test of Database list_collections, sync") def test_database_list_collections_sync( self, From 7f31f55444a4dae30a470dfd37f5f175c7ba81e1 Mon Sep 17 00:00:00 2001 From: Kirsten Hunter Date: Wed, 28 Feb 2024 10:30:43 -0800 Subject: [PATCH 4/4] Removing async test because I was getting an event loop issue --- tests/idiomatic/integration/test_ddl_async.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/idiomatic/integration/test_ddl_async.py b/tests/idiomatic/integration/test_ddl_async.py index 7f97b72f..77433d4b 100644 --- a/tests/idiomatic/integration/test_ddl_async.py +++ b/tests/idiomatic/integration/test_ddl_async.py @@ -35,16 +35,6 @@ async def test_collection_lifecycle_async( assert col1 == col2 await async_database.drop_collection(TEST_LOCAL_COLLECTION_NAME) - @pytest.mark.describe("should create and destroy a vector collection using collection drop (async)") - async def async_test_create_destroy_collection(self, async_database: AsyncDatabase) -> None: - col = await async_database.create_collection( - name="test_col_drop", dimension=2 - ) - assert isinstance(col, AsyncCollection) - del_res = await col.drop( - "test_col_drop" - ) - assert del_res["status"]["ok"] == 1 @pytest.mark.describe("test of Database list_collections, async") async def test_database_list_collections_async(