-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support await
tortoise.contrib.fastapi.RegisterTortoise
(#1662)
* Support await RegisterTortoise * Update changelog
- Loading branch information
1 parent
bc18384
commit b87f485
Showing
3 changed files
with
66 additions
and
24 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
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,34 @@ | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from fastapi import FastAPI | ||
|
||
from tortoise.contrib import test | ||
from tortoise.contrib.fastapi import RegisterTortoise | ||
|
||
|
||
class TestRegisterTortoise(test.TestCase): | ||
@test.requireCapability(dialect="sqlite") # type:ignore[misc] | ||
@patch("tortoise.Tortoise.init") | ||
@patch("tortoise.connections.close_all") | ||
async def test_await( | ||
self, | ||
mocked_close: AsyncMock, | ||
mocked_init: AsyncMock, | ||
) -> None: | ||
app = FastAPI() | ||
orm = await RegisterTortoise( | ||
app, | ||
db_url="sqlite://:memory:", | ||
modules={"models": ["__main__"]}, | ||
) | ||
mocked_init.assert_awaited_once() | ||
mocked_init.assert_called_once_with( | ||
config=None, | ||
config_file=None, | ||
db_url="sqlite://:memory:", | ||
modules={"models": ["__main__"]}, | ||
use_tz=False, | ||
timezone="UTC", | ||
) | ||
await orm.close_orm() | ||
mocked_close.assert_awaited_once() |
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