diff options
author | Joe Gordon <jogo@pinterest.com> | 2016-10-31 14:04:00 -0700 |
---|---|---|
committer | Joe Gordon <jogo@pinterest.com> | 2016-11-03 09:52:53 -0700 |
commit | 3613587536673154b45dbb8fe482e736f13a3a36 (patch) | |
tree | eded78af8c6e3aa53d1f493c4d770fa36f2a4577 /pymemcache/test/test_client.py | |
parent | f1c939be4dbc99aa6cc9d90b24c500893d65097d (diff) | |
download | pymemcache-3613587536673154b45dbb8fe482e736f13a3a36.tar.gz |
Add optional support for unicode keys
memcached's ASCII protocol supports unicode keys, so lets support them
as well. Since using unicode keys for memcache is uncommon and to
preserve the previous behavior disable support by default.
Diffstat (limited to 'pymemcache/test/test_client.py')
-rw-r--r-- | pymemcache/test/test_client.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pymemcache/test/test_client.py b/pymemcache/test/test_client.py index ab72652..ae18c28 100644 --- a/pymemcache/test/test_client.py +++ b/pymemcache/test/test_client.py @@ -1,4 +1,5 @@ # Copyright 2012 Pinterest.com +# -*- coding: utf-8 -*- # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -92,6 +93,18 @@ class ClientTestMixin(object): with pytest.raises(MemcacheIllegalInputError): _set() + def test_set_unicode_key_ok(self): + client = self.make_client([b'STORED\r\n'], allow_unicode_keys=True) + + result = client.set(u'\u0FFF', b'value', noreply=False) + assert result is True + + def test_set_unicode_key_ok_snowman(self): + client = self.make_client([b'STORED\r\n'], allow_unicode_keys=True) + + result = client.set('my☃', b'value', noreply=False) + assert result is True + def test_set_unicode_char_in_middle_of_key(self): client = self.make_client([b'STORED\r\n']) @@ -101,6 +114,15 @@ class ClientTestMixin(object): with pytest.raises(MemcacheIllegalInputError): _set() + def test_set_unicode_char_in_middle_of_key_snowman(self): + client = self.make_client([b'STORED\r\n']) + + def _set(): + client.set('my☃', b'value', noreply=False) + + with pytest.raises(MemcacheIllegalInputError): + _set() + def test_set_unicode_value(self): client = self.make_client([b'']) @@ -110,6 +132,12 @@ class ClientTestMixin(object): with pytest.raises(MemcacheIllegalInputError): _set() + def test_set_unicode_char_in_middle_of_key_ok(self): + client = self.make_client([b'STORED\r\n'], allow_unicode_keys=True) + + result = client.set('helloworld_\xb1901520_%c3', b'value', noreply=False) + assert result is True + def test_set_noreply(self): client = self.make_client([]) result = client.set(b'key', b'value', noreply=True) @@ -626,6 +654,15 @@ class TestClient(ClientTestMixin, unittest.TestCase): with pytest.raises(MemcacheClientError): client.get(b'x' * 251) + def test_too_long_unicode_key(self): + client = self.make_client([b'STORED\r\n'], allow_unicode_keys=True) + + with pytest.raises(MemcacheClientError): + client.get('my☃'*150) + + with pytest.raises(MemcacheClientError): + client.get(u'\u0FFF'*150) + def test_key_contains_spae(self): client = self.make_client([b'END\r\n']) with pytest.raises(MemcacheClientError): |