From b17321d28d771bec9f7fe515d4b942eea1e3d138 Mon Sep 17 00:00:00 2001 From: Rogelio Date: Thu, 21 Mar 2024 11:04:14 -0600 Subject: [PATCH] async-delete (#84) --- mongoengine_plus/aio/async_query_set.py | 7 +++++++ mongoengine_plus/version.py | 2 +- requirements.txt | 2 +- tests/aio/test_async_query_set.py | 9 +++++++++ tests/conftest.py | 21 ++++++++++++++++++--- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/mongoengine_plus/aio/async_query_set.py b/mongoengine_plus/aio/async_query_set.py index 35d072f..42d0c3c 100644 --- a/mongoengine_plus/aio/async_query_set.py +++ b/mongoengine_plus/aio/async_query_set.py @@ -29,3 +29,10 @@ async def async_insert( return await create_awaitable( self.insert, doc_or_docs, load_bulk, write_concern, signal_kwargs ) + + async def async_delete( + self, write_concern=None, _from_doc_delete=False, cascade_refs=None + ): + return await create_awaitable( + self.delete, write_concern, _from_doc_delete, cascade_refs + ) diff --git a/mongoengine_plus/version.py b/mongoengine_plus/version.py index df9144c..10939f0 100644 --- a/mongoengine_plus/version.py +++ b/mongoengine_plus/version.py @@ -1 +1 @@ -__version__ = '0.1.1' +__version__ = '0.1.2' diff --git a/requirements.txt b/requirements.txt index 8e775c0..20ff5a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -mongoengine==0.23.1 +mongoengine==0.27.0 dnspython==2.1.0 blinker==1.4 \ No newline at end of file diff --git a/tests/aio/test_async_query_set.py b/tests/aio/test_async_query_set.py index eb80916..bb671cf 100644 --- a/tests/aio/test_async_query_set.py +++ b/tests/aio/test_async_query_set.py @@ -57,3 +57,12 @@ async def test_bulk_insert(): cities_db = list(await City.objects.order_by('+name').async_to_list()) assert len(cities_db) == len(cities) assert all(a.name == b.name for a, b in zip(cities, cities_db)) + + +@pytest.mark.asyncio +async def test_async_delete(cities): + city = await City.objects(state='CDMX').async_first() + assert city + await City.objects(state='CDMX').async_delete() + city = await City.objects(state='CDMX').async_first() + assert not city diff --git a/tests/conftest.py b/tests/conftest.py index b37e00c..bc7965e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,19 @@ -from mongoengine import connect +from functools import partial -DATABASE_URI = 'mongomock://localhost:27017/db' -connect(host=DATABASE_URI) +import mongomock +import pytest +from _pytest.monkeypatch import MonkeyPatch + +DATABASE_URI = 'mongodb://localhost:27017/db' + + +@pytest.fixture(autouse=True) +def connect_database(monkeypatch: MonkeyPatch): + import mongoengine + + connect = partial( + mongoengine.connect, mongo_client_class=mongomock.MongoClient + ) + monkeypatch.setattr(mongoengine, 'connect', connect) + + connect(host=DATABASE_URI)