|
4 | 4 | from asyncio import Lock as AsyncLock |
5 | 5 | from asyncio import sleep as async_sleep |
6 | 6 | from typing import Optional, Tuple, Union |
| 7 | +from unittest.mock import AsyncMock, call |
7 | 8 |
|
8 | 9 | import pytest |
9 | 10 | import pytest_asyncio |
10 | 11 | import redis |
11 | | -from mock.mock import Mock, call |
12 | 12 | from redis import AuthenticationError, DataError, RedisError, ResponseError |
13 | 13 | from redis.asyncio import Connection, ConnectionPool, Redis |
14 | 14 | from redis.asyncio.retry import Retry |
@@ -340,10 +340,10 @@ class TestStreamingCredentialProvider: |
340 | 340 | indirect=True, |
341 | 341 | ) |
342 | 342 | async def test_async_re_auth_all_connections(self, credential_provider): |
343 | | - mock_connection = Mock(spec=Connection) |
| 343 | + mock_connection = AsyncMock(spec=Connection) |
344 | 344 | mock_connection.retry = Retry(NoBackoff(), 0) |
345 | | - mock_another_connection = Mock(spec=Connection) |
346 | | - mock_pool = Mock(spec=ConnectionPool) |
| 345 | + mock_another_connection = AsyncMock(spec=Connection) |
| 346 | + mock_pool = AsyncMock(spec=ConnectionPool) |
347 | 347 | mock_pool.connection_kwargs = { |
348 | 348 | "credential_provider": credential_provider, |
349 | 349 | } |
@@ -391,16 +391,16 @@ async def re_auth_callback(token): |
391 | 391 | indirect=True, |
392 | 392 | ) |
393 | 393 | async def test_async_re_auth_partial_connections(self, credential_provider): |
394 | | - mock_connection = Mock(spec=Connection) |
| 394 | + mock_connection = AsyncMock(spec=Connection) |
395 | 395 | mock_connection.retry = Retry(NoBackoff(), 3) |
396 | | - mock_another_connection = Mock(spec=Connection) |
| 396 | + mock_another_connection = AsyncMock(spec=Connection) |
397 | 397 | mock_another_connection.retry = Retry(NoBackoff(), 3) |
398 | | - mock_failed_connection = Mock(spec=Connection) |
| 398 | + mock_failed_connection = AsyncMock(spec=Connection) |
399 | 399 | mock_failed_connection.read_response.side_effect = ConnectionError( |
400 | 400 | "Failed auth" |
401 | 401 | ) |
402 | 402 | mock_failed_connection.retry = Retry(NoBackoff(), 3) |
403 | | - mock_pool = Mock(spec=ConnectionPool) |
| 403 | + mock_pool = AsyncMock(spec=ConnectionPool) |
404 | 404 | mock_pool.connection_kwargs = { |
405 | 405 | "credential_provider": credential_provider, |
406 | 406 | } |
@@ -454,14 +454,14 @@ async def re_auth_callback(token): |
454 | 454 | indirect=True, |
455 | 455 | ) |
456 | 456 | async def test_re_auth_pub_sub_in_resp3(self, credential_provider): |
457 | | - mock_pubsub_connection = Mock(spec=Connection) |
| 457 | + mock_pubsub_connection = AsyncMock(spec=Connection) |
458 | 458 | mock_pubsub_connection.get_protocol.return_value = 3 |
459 | 459 | mock_pubsub_connection.credential_provider = credential_provider |
460 | 460 | mock_pubsub_connection.retry = Retry(NoBackoff(), 3) |
461 | | - mock_another_connection = Mock(spec=Connection) |
| 461 | + mock_another_connection = AsyncMock(spec=Connection) |
462 | 462 | mock_another_connection.retry = Retry(NoBackoff(), 3) |
463 | 463 |
|
464 | | - mock_pool = Mock(spec=ConnectionPool) |
| 464 | + mock_pool = AsyncMock(spec=ConnectionPool) |
465 | 465 | mock_pool.connection_kwargs = { |
466 | 466 | "credential_provider": credential_provider, |
467 | 467 | } |
@@ -516,14 +516,14 @@ async def re_auth_callback(token): |
516 | 516 | indirect=True, |
517 | 517 | ) |
518 | 518 | async def test_do_not_re_auth_pub_sub_in_resp2(self, credential_provider): |
519 | | - mock_pubsub_connection = Mock(spec=Connection) |
| 519 | + mock_pubsub_connection = AsyncMock(spec=Connection) |
520 | 520 | mock_pubsub_connection.get_protocol.return_value = 2 |
521 | 521 | mock_pubsub_connection.credential_provider = credential_provider |
522 | 522 | mock_pubsub_connection.retry = Retry(NoBackoff(), 3) |
523 | | - mock_another_connection = Mock(spec=Connection) |
| 523 | + mock_another_connection = AsyncMock(spec=Connection) |
524 | 524 | mock_another_connection.retry = Retry(NoBackoff(), 3) |
525 | 525 |
|
526 | | - mock_pool = Mock(spec=ConnectionPool) |
| 526 | + mock_pool = AsyncMock(spec=ConnectionPool) |
527 | 527 | mock_pool.connection_kwargs = { |
528 | 528 | "credential_provider": credential_provider, |
529 | 529 | } |
@@ -583,10 +583,10 @@ async def test_fails_on_token_renewal(self, credential_provider): |
583 | 583 | RequestTokenErr, |
584 | 584 | RequestTokenErr, |
585 | 585 | ] |
586 | | - mock_connection = Mock(spec=Connection) |
| 586 | + mock_connection = AsyncMock(spec=Connection) |
587 | 587 | mock_connection.retry = Retry(NoBackoff(), 0) |
588 | | - mock_another_connection = Mock(spec=Connection) |
589 | | - mock_pool = Mock(spec=ConnectionPool) |
| 588 | + mock_another_connection = AsyncMock(spec=Connection) |
| 589 | + mock_pool = AsyncMock(spec=ConnectionPool) |
590 | 590 | mock_pool.connection_kwargs = { |
591 | 591 | "credential_provider": credential_provider, |
592 | 592 | } |
|
0 commit comments