Skip to content

Commit

Permalink
Fix creating fakeredis.aioredis using url with user/password (#139)
Browse files Browse the repository at this point in the history
* Fix creating fakeredis.aioredis using url with user/password
---------

Co-authored-by: m.pinter <[email protected]>
Co-authored-by: Daniel M <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2023
1 parent dcc852e commit baaed90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fakeredis/aioredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __init__(
username: Optional[str] = None,
server: Optional[_server.FakeServer] = None,
connected: bool = True,
**kwargs
**kwargs,
):
if not connection_pool:
# Adapted from aioredis
Expand All @@ -218,8 +218,9 @@ def __init__(
server.connected = connected
connection_kwargs: ConnectionKwargs = {
"db": db,
"username": username,
"password": password,
# Ignoring because AUTH is not implemented
# 'username',
# 'password',
"socket_timeout": socket_timeout,
"encoding": encoding,
"encoding_errors": encoding_errors,
Expand All @@ -245,7 +246,7 @@ def __init__(
health_check_interval=health_check_interval,
client_name=client_name,
username=username,
**kwargs
**kwargs,
)

@classmethod
Expand All @@ -258,4 +259,6 @@ def from_url(cls, url: str, **kwargs):
pool = self.connection_pool
pool.connection_class = FakeConnection
pool.connection_kwargs['server'] = server
pool.connection_kwargs.pop('username', None)
pool.connection_kwargs.pop('password', None)
return self
9 changes: 9 additions & 0 deletions test/test_redis_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,12 @@ async def test_connection_disconnect(nowait):
await conn.disconnect(nowait=nowait)

assert conn._sock is None

async def test_connection_with_username_and_password():
server = FakeServer()
r = aioredis.FakeRedis(server=server, username='username', password='password')

test_value = "this_is_a_test"
await r.hset('test:key', "test_hash", test_value)
result = await r.hget('test:key', "test_hash")
assert result.decode() == test_value

0 comments on commit baaed90

Please sign in to comment.