Skip to content

Commit bfc6787

Browse files
committed
More changes
1 parent d0d2429 commit bfc6787

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

tests/unit/app/test_database.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
import tempfile
77
import pytest
8+
from pytest_mock import MockerFixture
89
from sqlalchemy.engine.base import Engine
910
from sqlalchemy.orm import Session
1011

@@ -46,7 +47,7 @@ def base_postgres_config_fixture():
4647
class TestGetEngine:
4748
"""Test cases for get_engine function."""
4849

49-
def test_get_engine_when_initialized(self, mocker):
50+
def test_get_engine_when_initialized(self, mocker: MockerFixture):
5051
"""Test get_engine returns engine when initialized."""
5152
mock_engine = mocker.MagicMock(spec=Engine)
5253
database.engine = mock_engine
@@ -67,7 +68,7 @@ def test_get_engine_when_not_initialized(self):
6768
class TestGetSession:
6869
"""Test cases for get_session function."""
6970

70-
def test_get_session_when_initialized(self, mocker):
71+
def test_get_session_when_initialized(self, mocker: MockerFixture):
7172
"""Test get_session returns session when initialized."""
7273
mock_session_local = mocker.MagicMock()
7374
mock_session = mocker.MagicMock(spec=Session)
@@ -90,7 +91,7 @@ def test_get_session_when_not_initialized(self):
9091
class TestCreateTables:
9192
"""Test cases for create_tables function."""
9293

93-
def test_create_tables_success(self, mocker):
94+
def test_create_tables_success(self, mocker: MockerFixture):
9495
"""Test create_tables calls Base.metadata.create_all with engine."""
9596
mock_base = mocker.patch("app.database.Base")
9697
mock_get_engine = mocker.patch("app.database.get_engine")
@@ -102,7 +103,7 @@ def test_create_tables_success(self, mocker):
102103
mock_get_engine.assert_called_once()
103104
mock_base.metadata.create_all.assert_called_once_with(mock_engine)
104105

105-
def test_create_tables_when_engine_not_initialized(self, mocker):
106+
def test_create_tables_when_engine_not_initialized(self, mocker: MockerFixture):
106107
"""Test create_tables raises error when engine not initialized."""
107108
mock_get_engine = mocker.patch("app.database.get_engine")
108109
mock_get_engine.side_effect = RuntimeError("Database engine not initialized")
@@ -134,7 +135,7 @@ def test_create_sqlite_engine_directory_not_exists(self):
134135
):
135136
database._create_sqlite_engine(config)
136137

137-
def test_create_sqlite_engine_creation_failure(self, mocker):
138+
def test_create_sqlite_engine_creation_failure(self, mocker: MockerFixture):
138139
"""Test _create_sqlite_engine handles engine creation failure."""
139140
mock_create_engine = mocker.patch("app.database.create_engine")
140141
with tempfile.TemporaryDirectory() as temp_dir:
@@ -150,7 +151,7 @@ class TestCreatePostgresEngine:
150151
"""Test cases for _create_postgres_engine function."""
151152

152153
def test_create_postgres_engine_success_default_schema(
153-
self, mocker, base_postgres_config
154+
self, mocker: MockerFixture, base_postgres_config
154155
):
155156
"""Test _create_postgres_engine creates engine successfully with default schema."""
156157
mock_create_engine = mocker.patch("app.database.create_engine")
@@ -170,7 +171,7 @@ def test_create_postgres_engine_success_default_schema(
170171
assert expected_url == call_args[0][0]
171172

172173
def test_create_postgres_engine_success_custom_schema(
173-
self, mocker, base_postgres_config
174+
self, mocker: MockerFixture, base_postgres_config
174175
):
175176
"""Test _create_postgres_engine creates engine successfully with custom schema."""
176177
mock_create_engine = mocker.patch("app.database.create_engine")
@@ -191,7 +192,9 @@ def test_create_postgres_engine_success_custom_schema(
191192
mock_connection.execute.assert_called_once()
192193
mock_connection.commit.assert_called_once()
193194

194-
def test_create_postgres_engine_with_ca_cert(self, mocker, base_postgres_config):
195+
def test_create_postgres_engine_with_ca_cert(
196+
self, mocker: MockerFixture, base_postgres_config
197+
):
195198
"""Test _create_postgres_engine with CA certificate path."""
196199
mock_create_engine = mocker.patch("app.database.create_engine")
197200
mock_engine = mocker.MagicMock(spec=Engine)
@@ -209,7 +212,7 @@ def test_create_postgres_engine_with_ca_cert(self, mocker, base_postgres_config)
209212
assert call_args[1]["connect_args"]["sslrootcert"] == cert_file.name
210213

211214
def test_create_postgres_engine_creation_failure(
212-
self, mocker, base_postgres_config
215+
self, mocker: MockerFixture, base_postgres_config
213216
):
214217
"""Test _create_postgres_engine handles engine creation failure."""
215218
mock_create_engine = mocker.patch("app.database.create_engine")
@@ -219,7 +222,7 @@ def test_create_postgres_engine_creation_failure(
219222
database._create_postgres_engine(base_postgres_config)
220223

221224
def test_create_postgres_engine_schema_creation_failure(
222-
self, mocker, base_postgres_config
225+
self, mocker: MockerFixture, base_postgres_config
223226
):
224227
"""Test _create_postgres_engine handles schema creation failure."""
225228
mock_create_engine = mocker.patch("app.database.create_engine")
@@ -240,7 +243,12 @@ class TestInitializeDatabase:
240243
"""Test cases for initialize_database function."""
241244

242245
def _setup_common_mocks(
243-
self, *, mocker, mock_sessionmaker, mock_logger, enable_debug=False
246+
self,
247+
*,
248+
mocker: MockerFixture,
249+
mock_sessionmaker,
250+
mock_logger,
251+
enable_debug=False,
244252
):
245253
"""Setup common mocks for initialize_database tests."""
246254
mock_engine = mocker.MagicMock(spec=Engine)
@@ -261,7 +269,7 @@ def _verify_common_assertions(
261269

262270
def test_initialize_database_sqlite(
263271
self,
264-
mocker,
272+
mocker: MockerFixture,
265273
):
266274
"""Test initialize_database with SQLite configuration."""
267275
# Setup mocks
@@ -295,7 +303,7 @@ def test_initialize_database_sqlite(
295303

296304
def test_initialize_database_postgres(
297305
self,
298-
mocker,
306+
mocker: MockerFixture,
299307
base_postgres_config,
300308
):
301309
"""Test initialize_database with PostgreSQL configuration."""

tests/unit/utils/test_endpoints.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ async def test_get_agent_with_conversation_id(
284284

285285
@pytest.mark.asyncio
286286
async def test_get_agent_with_conversation_id_and_no_agent_in_llama_stack(
287-
setup_configuration, prepare_agent_mocks, mocker
287+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
288288
):
289289
"""Test get_agent function when conversation_id is provided."""
290290
mock_client, mock_agent = prepare_agent_mocks
@@ -342,7 +342,7 @@ async def test_get_agent_with_conversation_id_and_no_agent_in_llama_stack(
342342

343343
@pytest.mark.asyncio
344344
async def test_get_agent_no_conversation_id(
345-
setup_configuration, prepare_agent_mocks, mocker
345+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
346346
):
347347
"""Test get_agent function when conversation_id is None."""
348348
mock_client, mock_agent = prepare_agent_mocks
@@ -396,7 +396,7 @@ async def test_get_agent_no_conversation_id(
396396

397397
@pytest.mark.asyncio
398398
async def test_get_agent_empty_shields(
399-
setup_configuration, prepare_agent_mocks, mocker
399+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
400400
):
401401
"""Test get_agent function with empty shields list."""
402402
mock_client, mock_agent = prepare_agent_mocks
@@ -450,7 +450,7 @@ async def test_get_agent_empty_shields(
450450

451451
@pytest.mark.asyncio
452452
async def test_get_agent_multiple_mcp_servers(
453-
setup_configuration, prepare_agent_mocks, mocker
453+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
454454
):
455455
"""Test get_agent function with multiple MCP servers."""
456456
mock_client, mock_agent = prepare_agent_mocks
@@ -506,7 +506,7 @@ async def test_get_agent_multiple_mcp_servers(
506506

507507
@pytest.mark.asyncio
508508
async def test_get_agent_session_persistence_enabled(
509-
setup_configuration, prepare_agent_mocks, mocker
509+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
510510
):
511511
"""Test get_agent function ensures session persistence is enabled."""
512512
mock_client, mock_agent = prepare_agent_mocks
@@ -555,7 +555,7 @@ async def test_get_agent_session_persistence_enabled(
555555

556556
@pytest.mark.asyncio
557557
async def test_get_agent_no_tools_no_parser(
558-
setup_configuration, prepare_agent_mocks, mocker
558+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
559559
):
560560
"""Test get_agent function sets tool_parser=None when no_tools=True."""
561561
mock_client, mock_agent = prepare_agent_mocks
@@ -610,7 +610,7 @@ async def test_get_agent_no_tools_no_parser(
610610

611611
@pytest.mark.asyncio
612612
async def test_get_agent_no_tools_false_preserves_parser(
613-
setup_configuration, prepare_agent_mocks, mocker
613+
setup_configuration, prepare_agent_mocks, mocker: MockerFixture
614614
):
615615
"""Test get_agent function preserves tool_parser when no_tools=False."""
616616
mock_client, mock_agent = prepare_agent_mocks

0 commit comments

Comments
 (0)