28 lines
792 B
Python
28 lines
792 B
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from app.core.redis_client import get_redis, reset_redis_client_for_tests
|
|
|
|
|
|
class ApiRedisClientTests(unittest.TestCase):
|
|
def tearDown(self) -> None:
|
|
reset_redis_client_for_tests()
|
|
|
|
@patch("app.core.redis_client.redis.Redis")
|
|
@patch("app.core.redis_client.redis.BlockingConnectionPool")
|
|
def test_get_redis_reuses_singleton_client(self, mock_pool, mock_redis) -> None:
|
|
singleton = object()
|
|
mock_redis.return_value = singleton
|
|
|
|
client_a = get_redis()
|
|
client_b = get_redis()
|
|
|
|
self.assertIs(client_a, singleton)
|
|
self.assertIs(client_b, singleton)
|
|
mock_pool.assert_called_once()
|
|
mock_redis.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|