Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
masquerade and more async methods (#2)
* feat: added `masquerade_class` decorator; added tests using beanie; added `create_indexes` and `index_information` to collections async methods * style: prefer single quotes * style: fixed linting from Makefile and tyle issues * docs: added badge with pypi version * feat: added `*args, **kwargs` to AsyncMongoMockClients __init__
- Loading branch information
1 parent
9a458cd
commit 2a3c9d8
Showing
8 changed files
with
102 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Changelog | ||
|
||
# v0.0.1 | ||
## v0.0.2 | ||
|
||
- Initial version with basic functionality loosely based on [this repository](https://github.com/gonzaloverussa/pytest-async-mongodb). | ||
- Updated mock clasess to be treated as native motor's clasess. | ||
- Added `create_indexes` and `index_information` to collection's async methods. | ||
|
||
## v0.0.1 | ||
|
||
- Initial version with basic functionality loosely based on | ||
[this repository](https://github.com/gonzaloverussa/pytest-async-mongodb). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mongomock>=3.23.0,<4.0.0 | ||
|
||
# Development requirements | ||
flake8 | ||
flake8-quotes | ||
pytest | ||
beanie>=1.7.2,<2.0.0 | ||
flake8-quotes>=3.3.1,<4.0.0 | ||
flake8>=4.0.1,<5.0.0 | ||
pytest>=6.2.5,<7.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import setuptools | ||
|
||
|
||
VERSION = "0.0.1" | ||
VERSION = "0.0.2" | ||
|
||
|
||
with open("README.md", "r") as fh: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Optional | ||
from beanie import Document, Indexed, init_beanie | ||
from pydantic import BaseModel | ||
from mongomock_motor import AsyncMongoMockClient | ||
|
||
|
||
class Category(BaseModel): | ||
name: str | ||
description: str | ||
|
||
|
||
class Product(Document): | ||
name: str | ||
description: Optional[str] = None | ||
price: Indexed(float) | ||
category: Category | ||
|
||
|
||
async def test_beanie(): | ||
client = AsyncMongoMockClient('mongodb://user:pass@host:27017', connectTimeoutMS=250) | ||
|
||
await init_beanie(database=client.beanie_test, document_models=[Product]) | ||
|
||
chocolate = Category(name='Chocolate', description='A preparation of roasted and ground cacao seeds.') | ||
tonybar = Product(name="Tony's", price=5.95, category=chocolate) | ||
await tonybar.insert() | ||
|
||
find_many = Product.find_many(Product.category == chocolate) | ||
assert find_many.motor_cursor | ||
assert await find_many.count() == 1 | ||
|
||
product = await Product.find_one(Product.price < 10) | ||
await product.set({Product.name: 'Gold bar'}) | ||
|
||
product = await Product.find_one(Product.category.name == 'Chocolade') | ||
assert product.name == 'Gold bar' | ||
assert product.category.description == chocolate.description |