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

async-delete #84

Merged
merged 1 commit into from
Mar 21, 2024
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 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)
Loading