From 7a83b897218de00ef48701dc947134bb20caf409 Mon Sep 17 00:00:00 2001 From: Manuel Weitzman <8472961+mudetz@users.noreply.github.com> Date: Fri, 31 Mar 2023 17:21:54 -0300 Subject: [PATCH] Fix/v1.10.1/random import generic commands mixin (#136) * Fix import used in GenericCommandsMixin.randomkey * Bump pyproject version to 1.10.2 --- fakeredis/commands_mixins/_generic_mixin.py | 2 +- pyproject.toml | 2 +- test/test_mixins/test_generic_mixin.py | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/test_mixins/test_generic_mixin.py diff --git a/fakeredis/commands_mixins/_generic_mixin.py b/fakeredis/commands_mixins/_generic_mixin.py index 03eb957f..2e6bc4ed 100644 --- a/fakeredis/commands_mixins/_generic_mixin.py +++ b/fakeredis/commands_mixins/_generic_mixin.py @@ -1,6 +1,6 @@ import hashlib import pickle -from random import random +import random from fakeredis import _msgs as msgs from fakeredis._commands import command, Key, Int, DbIndex, BeforeAny, CommandItem, SortFloat diff --git a/pyproject.toml b/pyproject.toml index 3835ef6a..7290dfef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ name = "fakeredis" packages = [ { include = "fakeredis" }, ] -version = "1.10.1" +version = "1.10.2" description = "Fake implementation of redis API for testing purposes." readme = "README.md" keywords = ["redis", "rq", "django-rq", "rq-scheduler"] diff --git a/test/test_mixins/test_generic_mixin.py b/test/test_mixins/test_generic_mixin.py new file mode 100644 index 00000000..7abf280a --- /dev/null +++ b/test/test_mixins/test_generic_mixin.py @@ -0,0 +1,9 @@ +def test_randomkey_returns_none_on_empty_db(r): + assert r.randomkey() is None + + +def test_randomkey_returns_existing_key(r): + r.set("foo", 1) + r.set("bar", 2) + r.set("baz", 3) + assert r.randomkey().decode() in ("foo", "bar", "baz")