Skip to content

Commit

Permalink
test init args
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Oct 29, 2024
1 parent e2b2aaa commit e692878
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test/test_internals/test_init_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,40 @@ def test_host_init_arg(self):
db.set("foo", "bar")
assert db.get("foo") == b"bar"

def test_with_user_password(self):
username = "fakeredis-user"
password = "fakeredis-password"
db = fakeredis.FakeStrictRedis(host="localhost")
db.acl_setuser(username, enabled=True, passwords=[f"+{password}"], commands=["+set", "+get"])

db = fakeredis.FakeStrictRedis(host="localhost", username=username, password=password)
db.set("foo", "bar")
assert db.get("foo") == b"bar"

def test_from_url(self):
db = fakeredis.FakeStrictRedis.from_url("redis://localhost:6390/0")
db.set("foo", "bar")
assert db.get("foo") == b"bar"

def test_from_url_user(self):
db = fakeredis.FakeStrictRedis.from_url("redis://user@localhost:6390/0")
username = "fakeredis-user"
password = "fakeredis-password"
db = fakeredis.FakeStrictRedis(host="localhost", port=6390, db=0)
db.acl_setuser(username, enabled=True, nopass=True, commands=["+set", "+get"])

db = fakeredis.FakeStrictRedis.from_url(f"redis://{username}@localhost:6390/0")
db.set("foo", "bar")
assert db.get("foo") == b"bar"

def test_from_url_user_password(self):
db = fakeredis.FakeStrictRedis.from_url("redis://user:password@localhost:6390/0")
username = "fakeredis-user"
password = "fakeredis-password"
db = fakeredis.FakeStrictRedis(host="localhost", server=fakeredis.FakeServer())
db.acl_setuser(username, enabled=True, passwords=[f"+{password}"], commands=["+set", "+get"])

db = fakeredis.FakeStrictRedis.from_url(
f"redis://{username}:{password}@localhost:6390/0", server=fakeredis.FakeServer()
)
db.set("foo", "bar")
assert db.get("foo") == b"bar"

Expand Down

0 comments on commit e692878

Please sign in to comment.