11"""Unit tests for PostgreSQL cache implementation."""
22
33import pytest
4+ from pytest_mock import MockerFixture
45
56import psycopg2
67
@@ -69,7 +70,7 @@ def postgres_cache_config():
6970 )
7071
7172
72- def test_cache_initialization (postgres_cache_config_fixture , mocker ):
73+ def test_cache_initialization (postgres_cache_config_fixture , mocker : MockerFixture ):
7374 """Test the get operation when DB is connected."""
7475 # prevent real connection to PG instance
7576 mocker .patch ("psycopg2.connect" )
@@ -80,7 +81,9 @@ def test_cache_initialization(postgres_cache_config_fixture, mocker):
8081 assert cache .connection is not None
8182
8283
83- def test_cache_initialization_on_error (postgres_cache_config_fixture , mocker ):
84+ def test_cache_initialization_on_error (
85+ postgres_cache_config_fixture , mocker : MockerFixture
86+ ):
8487 """Test the get operation when DB is not connected."""
8588 # prevent real connection to PG instance
8689 mocker .patch ("psycopg2.connect" , side_effect = Exception ("foo" ))
@@ -90,7 +93,9 @@ def test_cache_initialization_on_error(postgres_cache_config_fixture, mocker):
9093 _ = PostgresCache (postgres_cache_config_fixture )
9194
9295
93- def test_cache_initialization_connect_finalizer (postgres_cache_config_fixture , mocker ):
96+ def test_cache_initialization_connect_finalizer (
97+ postgres_cache_config_fixture , mocker : MockerFixture
98+ ):
9499 """Test the get operation when DB is not connected."""
95100 # prevent real connection to PG instance
96101 mocker .patch ("psycopg2.connect" )
@@ -106,7 +111,7 @@ def test_cache_initialization_connect_finalizer(postgres_cache_config_fixture, m
106111 _ = PostgresCache (postgres_cache_config_fixture )
107112
108113
109- def test_connected_when_connected (postgres_cache_config_fixture , mocker ):
114+ def test_connected_when_connected (postgres_cache_config_fixture , mocker : MockerFixture ):
110115 """Test the connected() method."""
111116 # prevent real connection to PG instance
112117 mocker .patch ("psycopg2.connect" )
@@ -116,7 +121,9 @@ def test_connected_when_connected(postgres_cache_config_fixture, mocker):
116121 assert cache .connected () is True
117122
118123
119- def test_connected_when_disconnected (postgres_cache_config_fixture , mocker ):
124+ def test_connected_when_disconnected (
125+ postgres_cache_config_fixture , mocker : MockerFixture
126+ ):
120127 """Test the connected() method."""
121128 # prevent real connection to PG instance
122129 mocker .patch ("psycopg2.connect" )
@@ -128,7 +135,9 @@ def test_connected_when_disconnected(postgres_cache_config_fixture, mocker):
128135 assert cache .connected () is False
129136
130137
131- def test_connected_when_connection_error (postgres_cache_config_fixture , mocker ):
138+ def test_connected_when_connection_error (
139+ postgres_cache_config_fixture , mocker : MockerFixture
140+ ):
132141 """Test the connected() method."""
133142 # prevent real connection to PG instance
134143 mocker .patch ("psycopg2.connect" )
@@ -139,7 +148,9 @@ def test_connected_when_connection_error(postgres_cache_config_fixture, mocker):
139148 assert cache .connected () is False
140149
141150
142- def test_initialize_cache_when_connected (postgres_cache_config_fixture , mocker ):
151+ def test_initialize_cache_when_connected (
152+ postgres_cache_config_fixture , mocker : MockerFixture
153+ ):
143154 """Test the initialize_cache()."""
144155 # prevent real connection to PG instance
145156 mocker .patch ("psycopg2.connect" )
@@ -148,7 +159,9 @@ def test_initialize_cache_when_connected(postgres_cache_config_fixture, mocker):
148159 cache .initialize_cache ()
149160
150161
151- def test_initialize_cache_when_disconnected (postgres_cache_config_fixture , mocker ):
162+ def test_initialize_cache_when_disconnected (
163+ postgres_cache_config_fixture , mocker : MockerFixture
164+ ):
152165 """Test the initialize_cache()."""
153166 # prevent real connection to PG instance
154167 mocker .patch ("psycopg2.connect" )
@@ -159,7 +172,7 @@ def test_initialize_cache_when_disconnected(postgres_cache_config_fixture, mocke
159172 cache .initialize_cache ()
160173
161174
162- def test_ready_method (postgres_cache_config_fixture , mocker ):
175+ def test_ready_method (postgres_cache_config_fixture , mocker : MockerFixture ):
163176 """Test the ready() method."""
164177 # prevent real connection to PG instance
165178 mocker .patch ("psycopg2.connect" )
@@ -170,7 +183,9 @@ def test_ready_method(postgres_cache_config_fixture, mocker):
170183 assert ready is True
171184
172185
173- def test_get_operation_when_disconnected (postgres_cache_config_fixture , mocker ):
186+ def test_get_operation_when_disconnected (
187+ postgres_cache_config_fixture , mocker : MockerFixture
188+ ):
174189 """Test the get() method."""
175190 # prevent real connection to PG instance
176191 mocker .patch ("psycopg2.connect" )
@@ -184,7 +199,9 @@ def test_get_operation_when_disconnected(postgres_cache_config_fixture, mocker):
184199 cache .get (USER_ID_1 , CONVERSATION_ID_1 , False )
185200
186201
187- def test_get_operation_when_connected (postgres_cache_config_fixture , mocker ):
202+ def test_get_operation_when_connected (
203+ postgres_cache_config_fixture , mocker : MockerFixture
204+ ):
188205 """Test the get() method."""
189206 # prevent real connection to PG instance
190207 mocker .patch ("psycopg2.connect" )
@@ -203,7 +220,9 @@ def test_get_operation_returned_values():
203220 # Need to mock the cursor.execute() method
204221
205222
206- def test_insert_or_append_when_disconnected (postgres_cache_config_fixture , mocker ):
223+ def test_insert_or_append_when_disconnected (
224+ postgres_cache_config_fixture , mocker : MockerFixture
225+ ):
207226 """Test the insert_or_append() method."""
208227 # prevent real connection to PG instance
209228 mocker .patch ("psycopg2.connect" )
@@ -217,7 +236,7 @@ def test_insert_or_append_when_disconnected(postgres_cache_config_fixture, mocke
217236
218237
219238def test_insert_or_append_operation_when_connected (
220- postgres_cache_config_fixture , mocker
239+ postgres_cache_config_fixture , mocker : MockerFixture
221240):
222241 """Test the insert_or_append() method."""
223242 # prevent real connection to PG instance
@@ -229,7 +248,7 @@ def test_insert_or_append_operation_when_connected(
229248
230249
231250def test_insert_or_append_operation_operation_error (
232- postgres_cache_config_fixture , mocker
251+ postgres_cache_config_fixture , mocker : MockerFixture
233252):
234253 """Test the insert_or_append() method."""
235254 # prevent real connection to PG instance
@@ -244,7 +263,7 @@ def test_insert_or_append_operation_operation_error(
244263 cache .insert_or_append (USER_ID_1 , CONVERSATION_ID_1 , cache_entry_1 , False )
245264
246265
247- def test_delete_when_disconnected (postgres_cache_config_fixture , mocker ):
266+ def test_delete_when_disconnected (postgres_cache_config_fixture , mocker : MockerFixture ):
248267 """Test the delete() method."""
249268 # prevent real connection to PG instance
250269 mocker .patch ("psycopg2.connect" )
@@ -258,7 +277,9 @@ def test_delete_when_disconnected(postgres_cache_config_fixture, mocker):
258277 cache .delete (USER_ID_1 , CONVERSATION_ID_1 , False )
259278
260279
261- def test_delete_operation_when_connected (postgres_cache_config_fixture , mocker ):
280+ def test_delete_operation_when_connected (
281+ postgres_cache_config_fixture , mocker : MockerFixture
282+ ):
262283 """Test the delete() method."""
263284 # prevent real connection to PG instance
264285 mock_connect = mocker .patch ("psycopg2.connect" )
@@ -274,7 +295,9 @@ def test_delete_operation_when_connected(postgres_cache_config_fixture, mocker):
274295 assert cache .delete (USER_ID_1 , CONVERSATION_ID_1 , False ) is False
275296
276297
277- def test_delete_operation_operation_error (postgres_cache_config_fixture , mocker ):
298+ def test_delete_operation_operation_error (
299+ postgres_cache_config_fixture , mocker : MockerFixture
300+ ):
278301 """Test the delete() method."""
279302 # prevent real connection to PG instance
280303 mocker .patch ("psycopg2.connect" )
@@ -288,7 +311,9 @@ def test_delete_operation_operation_error(postgres_cache_config_fixture, mocker)
288311 cache .delete (USER_ID_1 , CONVERSATION_ID_1 , False )
289312
290313
291- def test_list_operation_when_disconnected (postgres_cache_config_fixture , mocker ):
314+ def test_list_operation_when_disconnected (
315+ postgres_cache_config_fixture , mocker : MockerFixture
316+ ):
292317 """Test the list() method."""
293318 # prevent real connection to PG instance
294319 mocker .patch ("psycopg2.connect" )
@@ -302,7 +327,9 @@ def test_list_operation_when_disconnected(postgres_cache_config_fixture, mocker)
302327 cache .list (USER_ID_1 , False )
303328
304329
305- def test_list_operation_when_connected (postgres_cache_config_fixture , mocker ):
330+ def test_list_operation_when_connected (
331+ postgres_cache_config_fixture , mocker : MockerFixture
332+ ):
306333 """Test the list() method."""
307334 # prevent real connection to PG instance
308335 mocker .patch ("psycopg2.connect" )
@@ -314,7 +341,7 @@ def test_list_operation_when_connected(postgres_cache_config_fixture, mocker):
314341 assert isinstance (lst , list )
315342
316343
317- def test_topic_summary_operations (postgres_cache_config_fixture , mocker ):
344+ def test_topic_summary_operations (postgres_cache_config_fixture , mocker : MockerFixture ):
318345 """Test topic summary set operations and retrieval via list."""
319346 # prevent real connection to PG instance
320347 mock_connect = mocker .patch ("psycopg2.connect" )
@@ -343,7 +370,9 @@ def test_topic_summary_operations(postgres_cache_config_fixture, mocker):
343370 assert isinstance (conversations [0 ], ConversationData )
344371
345372
346- def test_topic_summary_after_conversation_delete (postgres_cache_config_fixture , mocker ):
373+ def test_topic_summary_after_conversation_delete (
374+ postgres_cache_config_fixture , mocker : MockerFixture
375+ ):
347376 """Test that topic summary is deleted when conversation is deleted."""
348377 # prevent real connection to PG instance
349378 mock_connect = mocker .patch ("psycopg2.connect" )
@@ -364,7 +393,9 @@ def test_topic_summary_after_conversation_delete(postgres_cache_config_fixture,
364393 assert deleted is True
365394
366395
367- def test_topic_summary_when_disconnected (postgres_cache_config_fixture , mocker ):
396+ def test_topic_summary_when_disconnected (
397+ postgres_cache_config_fixture , mocker : MockerFixture
398+ ):
368399 """Test topic summary operations when cache is disconnected."""
369400 # prevent real connection to PG instance
370401 mocker .patch ("psycopg2.connect" )
0 commit comments