Skip to content

Commit

Permalink
test: add unit tests for key prefixing
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-boros committed Aug 19, 2021
1 parent 3caf2e3 commit 1c3d19a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions t/unit/transport/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from kombu import Connection, Consumer, Exchange, Producer, Queue
from kombu.exceptions import InconsistencyError, VersionMismatch
from kombu.transport import virtual
from kombu.transport.redis import GlobalKeyPrefixMixin
from kombu.utils import eventio # patch poll
from kombu.utils.json import dumps

Expand Down Expand Up @@ -1543,3 +1544,50 @@ def test_sentinel_with_ssl(self):
from kombu.transport.redis import SentinelManagedSSLConnection
assert (params['connection_class'] is
SentinelManagedSSLConnection)


class test_GlobalKeyPrefixMixin:

global_keyprefix = "prefix_"
mixin = GlobalKeyPrefixMixin()
mixin.global_keyprefix = global_keyprefix

def test_prefix_simple_args(self):
for command in GlobalKeyPrefixMixin.PREFIXED_SIMPLE_COMMANDS:
prefixed_args = self.mixin._prefix_args([command, "fake_key"])
assert prefixed_args == [
command,
f"{self.global_keyprefix}fake_key"
]

def test_prefix_brpop_args(self):
prefixed_args = self.mixin._prefix_args([
"BRPOP",
"fake_key",
"fake_key2",
"not_prefixed"
])

assert prefixed_args == [
"BRPOP",
f"{self.global_keyprefix}fake_key",
f"{self.global_keyprefix}fake_key2",
"not_prefixed",
]

def test_prefix_evalsha_args(self):
prefixed_args = self.mixin._prefix_args([
"EVALSHA",
"not_prefixed",
"not_prefixed",
"fake_key",
"not_prefixed",
])

assert prefixed_args == [
"EVALSHA",
"not_prefixed",
"not_prefixed",
f"{self.global_keyprefix}fake_key",
"not_prefixed",
]

0 comments on commit 1c3d19a

Please sign in to comment.