Skip to content
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

Mongodb collection drop function #225

Merged
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
7 changes: 7 additions & 0 deletions astrapy/idiomatic/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ def delete_many(
f"(gotten '${json.dumps(dm_response)}')"
)

def drop(self, name_or_collection: Union[str, AsyncCollection]) -> None:
return self._astra_db_collection.astra_db.delete_collection(name_or_collection)

@unsupported
def find_raw_batches(*pargs: Any, **kwargs: Any) -> Any: ...

Expand Down Expand Up @@ -445,6 +448,10 @@ async def delete_many(
f"(gotten '${json.dumps(dm_response)}')"
)

async def drop(self, name_or_collection: Union[str, AsyncCollection]) -> None:
return await self._astra_db_collection.astra_db.delete_collection(name_or_collection)


@unsupported
async def find_raw_batches(*pargs: Any, **kwargs: Any) -> Any: ...

Expand Down
1 change: 1 addition & 0 deletions tests/idiomatic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 0 additions & 1 deletion tests/idiomatic/integration/test_collections_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from astrapy import AsyncCollection, AsyncDatabase


class TestCollectionsAsync:
@pytest.mark.describe("test of instantiating Collection, async")
async def test_instantiate_collection_async(
Expand Down
3 changes: 2 additions & 1 deletion tests/idiomatic/integration/test_ddl_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -35,6 +35,7 @@ async def test_collection_lifecycle_async(
assert col1 == col2
await async_database.drop_collection(TEST_LOCAL_COLLECTION_NAME)


@pytest.mark.describe("test of Database list_collections, async")
async def test_database_list_collections_async(
self,
Expand Down
15 changes: 13 additions & 2 deletions tests/idiomatic/integration/test_ddl_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Loading