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

Question: how to mock/write propper unittests #403

Open
jesusch opened this issue Jan 13, 2024 · 2 comments
Open

Question: how to mock/write propper unittests #403

jesusch opened this issue Jan 13, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@jesusch
Copy link

jesusch commented Jan 13, 2024

Question

I'd really love to use odmantic/fastapi to replace my current database setup (dynamodb)

Yet any way I try to implement testcases seem to fail as mongomock doesn't support sessions

Any way to tell odmantic not to use them?

@jesusch jesusch added the enhancement New feature or request label Jan 13, 2024
@jesusch
Copy link
Author

jesusch commented Apr 2, 2024

given this code raises "RuntimeError: Event loop is closed" as soon as more then one test is performed

from typing import Optional
from unittest import IsolatedAsyncioTestCase
from odmantic import AIOEngine, Model, Field


class Publisher(Model):
    name: str
    founded: int = Field(ge=1440)
    location: Optional[str] = None

engine = AIOEngine()

class TestPatients(IsolatedAsyncioTestCase):

    async def test_one(self):
        await engine.save(
            Publisher(
                name="Penguin",
                founded=1935,
                location="London"
            )
        )

    async def test_two(self):
        await engine.save(
            Publisher(
                name="Penguin",
                founded=1935,
                location="London"
            )
        )

@jesusch
Copy link
Author

jesusch commented Apr 2, 2024

If anyone interested - I started an example project which (still) fails
https://github.com/jesusch/odmantic-test

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

No branches or pull requests

1 participant