From 1c3d19ae055c77e71c4d237ead04fbfdaf757ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Boros?= Date: Thu, 19 Aug 2021 12:13:39 +0400 Subject: [PATCH] test: add unit tests for key prefixing --- t/unit/transport/test_redis.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py index ac46d3437e..b3542918d2 100644 --- a/t/unit/transport/test_redis.py +++ b/t/unit/transport/test_redis.py @@ -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 @@ -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", + ]