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

Testing with mongoengine #24

Open
Inventrohyder opened this issue Nov 3, 2022 · 1 comment
Open

Testing with mongoengine #24

Inventrohyder opened this issue Nov 3, 2022 · 1 comment

Comments

@Inventrohyder
Copy link

Is it possible to use this library to test mongoengine?

Here is a preliminary test:

def test_something(mongodb: Database):
    print(f"type(mongodb.user)\t->\t{type(mongodb.user)}")
    print(f"mongodb.user.count()\t->\t{mongodb.user.count()}")
    print(f"type(User.objects()\t->\t{type(User.objects())}")
    print(f"User.objects().count()\t->\t{User.objects().count()}")
    print(f"type(User)\t->\t{type(User)}")
    print(f"{mongodb.list_collection_names()}")
    print(mongodb.client)
    print(User._get_collection_name())
    for i in User.objects():
        print(f"type(user object)\t->\t{type(i)}")
        print(I)

Output:

tests/services/test_announcement.py ....type(mongodb.user)      ->      <class 'mongomock.collection.Collection'>
mongodb.user.count()    ->      15726
type(User.objects()     ->      <class 'mongoengine.queryset.queryset.QuerySet'>
User.objects().count()  ->      1
type(User)      ->      <class 'modules.mongoengine_extensions.IndexDocumentsMeta'>
['user', 'venue', 'players']
mongomock.MongoClient('localhost', 27017)
user
type(user object)       ->      <class 'src.models.model.User'>
User object

As we can see above mongodb.user.count() is 15726 but User.objects().count() is 1.
How do I make the mongoengine documents work with pytest-mongodb?

@mdomke
Copy link
Owner

mdomke commented Nov 3, 2022

To be honest, I don't know. If not been working with MongoDB under Python for quite some time, and I currently don't have the time to investigate this. I would very much appreciate a pull-request if you figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants