Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /limber-project_limberframework /tests /cache /test_lockers.py
| from unittest.mock import AsyncMock, Mock, patch | |
| from aioredlock import Aioredlock | |
| from pytest import mark, raises | |
| from limberframework.cache.lockers import AsyncRedisLocker, make_locker | |
| def test_create_async_redis_locker(): | |
| mock_locker = Mock() | |
| locker = AsyncRedisLocker(mock_locker) | |
| assert locker.lock_manager == mock_locker | |
| async def test_async_redis_locker_lock(key, expires_in): | |
| mock_aioredlock = Mock() | |
| mock_aioredlock.lock = AsyncMock() | |
| locker = AsyncRedisLocker(mock_aioredlock) | |
| locker.lock_manager = mock_aioredlock | |
| await locker.lock(key, expires_in) | |
| mock_aioredlock.lock.assert_called_once_with( | |
| f"lock-{key}", lock_timeout=expires_in | |
| ) | |
| assert locker._locks[key] == mock_aioredlock.lock.return_value | |
| async def test_async_redis_locker_unlock(): | |
| key = "resource" | |
| mock_aioredlock = Mock() | |
| mock_aioredlock.unlock = AsyncMock() | |
| mock_lock = Mock() | |
| locker = AsyncRedisLocker(mock_aioredlock) | |
| locker._locks[key] = mock_lock | |
| await locker.unlock(key) | |
| mock_aioredlock.unlock.assert_called_once_with(mock_lock) | |
| async def test_make_locker_without_password(mock_asyncredislocker): | |
| config = { | |
| "locker": "asyncredis", | |
| "host": "localhost", | |
| "port": 1234, | |
| "db": 0, | |
| "password": None, | |
| "locker_retry_count": 1, | |
| } | |
| await make_locker(config) | |
| mock_asyncredislocker.assert_called_once_with( | |
| Aioredlock( | |
| [ | |
| { | |
| "host": config["host"], | |
| "port": config["port"], | |
| "db": config["db"], | |
| "password": config["password"], | |
| } | |
| ], | |
| retry_count=config["locker_retry_count"], | |
| ) | |
| ) | |
| async def test_make_locker_with_password(mock_asyncredislocker): | |
| config = { | |
| "locker": "asyncredis", | |
| "host": "localhost", | |
| "port": 1234, | |
| "db": 0, | |
| "password": "test", | |
| "locker_retry_count": 1, | |
| } | |
| await make_locker(config) | |
| mock_asyncredislocker.assert_called_once_with( | |
| Aioredlock( | |
| [ | |
| { | |
| "host": config["host"], | |
| "port": config["port"], | |
| "db": config["db"], | |
| "password": config["password"], | |
| } | |
| ], | |
| retry_count=1, | |
| ) | |
| ) | |
| async def test_make_locker_with_invalid_locker(): | |
| config = {"locker": "test"} | |
| with raises( | |
| ValueError, match=f"Unsupported cache locker {config['locker']}." | |
| ): | |
| await make_locker(config) | |
Xet Storage Details
- Size:
- 2.89 kB
- Xet hash:
- cb67d6913c23701abd18233465487cc7bb9a81357201f8a2cfe08d301d724ee8
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.