forked from fastapi/full-stack-fastapi-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏷️ Add mypy to the GitHub Action for tests and fixed types in the who…
…le project (fastapi#655) Co-authored-by: Sebastián Ramírez <[email protected]>
- Loading branch information
1 parent
86c0ed7
commit 16f2564
Showing
19 changed files
with
106 additions
and
79 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
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
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
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,28 +1,33 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from pytest_mock import MockerFixture | ||
from sqlmodel import select | ||
|
||
from app.backend_pre_start import init, logger | ||
|
||
|
||
def test_init_successful_connection(mocker): | ||
def test_init_successful_connection(mocker: MockerFixture) -> None: | ||
engine_mock = MagicMock() | ||
|
||
session_mock = MagicMock() | ||
exec_mock = MagicMock(return_value=True) | ||
session_mock.configure_mock(**{'exec.return_value': exec_mock}) | ||
mocker.patch('sqlmodel.Session', return_value=session_mock) | ||
session_mock.configure_mock(**{"exec.return_value": exec_mock}) | ||
mocker.patch("sqlmodel.Session", return_value=session_mock) | ||
|
||
mocker.patch.object(logger, 'info') | ||
mocker.patch.object(logger, 'error') | ||
mocker.patch.object(logger, 'warn') | ||
mocker.patch.object(logger, "info") | ||
mocker.patch.object(logger, "error") | ||
mocker.patch.object(logger, "warn") | ||
|
||
try: | ||
init(engine_mock) | ||
connection_successful = True | ||
except Exception: | ||
connection_successful = False | ||
|
||
assert connection_successful, "The database connection should be successful and not raise an exception." | ||
assert ( | ||
connection_successful | ||
), "The database connection should be successful and not raise an exception." | ||
|
||
assert session_mock.exec.called_once_with(select(1)), "The session should execute a select statement once." | ||
assert session_mock.exec.called_once_with( | ||
select(1) | ||
), "The session should execute a select statement once." |
Oops, something went wrong.