pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
969 B
33 lines
969 B
from unittest.mock import MagicMock, patch
|
|
|
|
from sqlmodel import select
|
|
|
|
from app.tests_pre_start import init, logger
|
|
|
|
|
|
def test_init_successful_connection() -> None:
|
|
engine_mock = MagicMock()
|
|
|
|
session_mock = MagicMock()
|
|
exec_mock = MagicMock(return_value=True)
|
|
session_mock.configure_mock(**{"exec.return_value": exec_mock})
|
|
|
|
with (
|
|
patch("sqlmodel.Session", return_value=session_mock),
|
|
patch.object(logger, "info"),
|
|
patch.object(logger, "error"),
|
|
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 session_mock.exec.called_once_with(select(1)), (
|
|
"The session should execute a select statement once."
|
|
)
|
|
|