Skip to content

Commit

Permalink
Adding async_first and abstract base class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Sánchez committed May 20, 2021
1 parent 3129d4a commit fa95061
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mongoengine_plus/aio/async_query_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@


class AsyncQuerySet(QuerySet):
async def async_first(self):
return await create_awaitable(self.first)

async def async_get(self, *q_objs, **query):
return await create_awaitable(self.get, *q_objs, **query)

Expand Down
3 changes: 3 additions & 0 deletions mongoengine_plus/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@


class BaseModel:
meta = {
'abstract': True,
}
_excluded: ClassVar = []
_hidden: ClassVar = []

Expand Down
2 changes: 1 addition & 1 deletion mongoengine_plus/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.2'
__version__ = '0.0.3.dev0'
6 changes: 6 additions & 0 deletions tests/aio/test_async_query_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ async def test_to_list(cities):
Q(state='Chiapas') | Q(state='Tabasco')
).async_to_list()
assert len(filtered) == 3


@pytest.mark.asyncio
async def test_first(cities):
first_city = await City.objects(state='Tabasco').async_first()
assert first_city.state == 'Tabasco'

0 comments on commit fa95061

Please sign in to comment.