diff --git a/mongoengine_plus/aio/async_query_set.py b/mongoengine_plus/aio/async_query_set.py index fd3e1b6..35d072f 100644 --- a/mongoengine_plus/aio/async_query_set.py +++ b/mongoengine_plus/aio/async_query_set.py @@ -18,3 +18,14 @@ async def async_to_list(self): async def async_update(self, *u_objs, **query): return await create_awaitable(self.update, *u_objs, **query) + + async def async_insert( + self, + doc_or_docs, + load_bulk=True, + write_concern=None, + signal_kwargs=None, + ): + return await create_awaitable( + self.insert, doc_or_docs, load_bulk, write_concern, signal_kwargs + ) diff --git a/mongoengine_plus/version.py b/mongoengine_plus/version.py index 156d6f9..b794fd4 100644 --- a/mongoengine_plus/version.py +++ b/mongoengine_plus/version.py @@ -1 +1 @@ -__version__ = '0.0.4' +__version__ = '0.1.0' diff --git a/tests/aio/test_async_query_set.py b/tests/aio/test_async_query_set.py index d82062b..eb80916 100644 --- a/tests/aio/test_async_query_set.py +++ b/tests/aio/test_async_query_set.py @@ -40,3 +40,20 @@ async def test_update(cities): ) sancris = await City.objects.async_get(name__contains='San Cristobal') assert sancris.name == 'San Cristobal de las Casas' + + +@pytest.mark.asyncio +async def test_bulk_insert(): + cities = [ + City(name='Villahermosa', state='Tabasco'), + City(name='Ciudad de México', state='CDMX'), + City(name='Monterrey', state='Nuevo León'), + City(name='San Cristobal', state='Chiapas'), + City(name='Tuxtla Gutiérrez', state='Chiapas'), + ] + cities.sort(key=lambda c: c.name) + await City.objects.async_insert(cities, load_bulk=False) + + 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))