diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-09 20:46:36 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-09 21:34:21 -0400 |
commit | 43469815859f2536404329cf2a3a2df95dc74c92 (patch) | |
tree | 756ab8293815441ddee574a1bfd7f66c67b94030 /tests | |
parent | d0ff02b8bd776a093f0216596dcc3be742b6fc17 (diff) | |
download | dogpile-cache-43469815859f2536404329cf2a3a2df95dc74c92.tar.gz |
Encode string key for sha1 function
Fixed the :func:`.sha1_mangle_key` key mangler to coerce incoming Unicode
objects into bytes as is required by the Py3k version of this function.
Fixes: #159
Change-Id: Ia7686f8586766f586905a539e2237d2c29cb8952
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cache/test_decorator.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/cache/test_decorator.py b/tests/cache/test_decorator.py index 76a67f7..156b6e3 100644 --- a/tests/cache/test_decorator.py +++ b/tests/cache/test_decorator.py @@ -460,6 +460,35 @@ class KeyGenerationTest(TestCase): "tests.cache.test_decorator:" "one|mynamespace|m\xe9il dr\xf4le", ) + def test_sha1_key_mangler(self): + + decorate, canary = self._keygen_decorator() + + @decorate + def one(a, b): + pass + + gen = canary[0] + + key = gen(1, 2) + + eq_( + util.sha1_mangle_key(key), + "aead490a8ace2d69a00160f1fd8fd8a16552c24f", + ) + + def test_sha1_key_mangler_unicode_py2k(self): + eq_( + util.sha1_mangle_key(u"some_key"), + "53def077a4264bd3183d4eb21b1f56f883e1b572", + ) + + def test_sha1_key_mangler_bytes_py3k(self): + eq_( + util.sha1_mangle_key(b"some_key"), + "53def077a4264bd3183d4eb21b1f56f883e1b572", + ) + class CacheDecoratorTest(_GenericBackendFixture, TestCase): backend = "mock" |