Skip to content

Commit

Permalink
add listIndexes and test
Browse files Browse the repository at this point in the history
  • Loading branch information
stik authored and michaelkryukov committed Apr 16, 2023
1 parent e2d51ff commit cc5613c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mongomock_motor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def find(self, *args, **kwargs) -> AsyncCursor:
def aggregate(self, *args, **kwargs) -> AsyncLatentCommandCursor:
return AsyncLatentCommandCursor(self.__collection.aggregate(*args, **kwargs))

def list_indexes(self, *args, **kwargs) -> AsyncCursor:
return AsyncCursor(self.__collection.list_indexes(*args, **kwargs))


@masquerade_class('motor.motor_asyncio.AsyncIOMotorDatabase')
@with_async_methods('__database', [
Expand Down
19 changes: 19 additions & 0 deletions tests/test_async_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,22 @@ async def test_async_for():

# Check docs are correct
assert docs == sample_docs


@pytest.mark.anyio
async def test_list_indexes():
collection = AsyncMongoMockClient()['tests']['test']

# Insert sample documents into database
await collection.insert_many([{'i': i} for i in range(EXPECTED_DOCUMENTS_COUNT)])

# Check that there is one default '_id' index
indexes = await collection.list_indexes().to_list()
assert len(indexes) == 1

# Create a second index on the field 'i'
await collection.create_index([('i', pymongo.DESCENDING)])

# Check that there are now two indexes
indexes = await collection.list_indexes().to_list()
assert len(indexes) == 2

0 comments on commit cc5613c

Please sign in to comment.