Skip to content

Commit

Permalink
async-delete (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogelioLpz authored Mar 21, 2024
1 parent 4e16bc5 commit b17321d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
7 changes: 7 additions & 0 deletions mongoengine_plus/aio/async_query_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion mongoengine_plus/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.1'
__version__ = '0.1.2'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mongoengine==0.23.1
mongoengine==0.27.0
dnspython==2.1.0
blinker==1.4
9 changes: 9 additions & 0 deletions tests/aio/test_async_query_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 18 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b17321d

Please sign in to comment.