Merge "Fix bug where serialization_format is ignored"

This commit is contained in:
Jenkins 2012-09-18 18:54:11 +00:00 committed by Gerrit Code Review
commit 73aa3cbda1
2 changed files with 12 additions and 2 deletions

View File

@ -52,6 +52,8 @@ class MemcacheMiddleware(object):
self.memcache_servers = '127.0.0.1:11211'
if serialization_format is None:
serialization_format = 2
else:
serialization_format = int(serialization_format)
self.memcache = MemcacheRing(
[s.strip() for s in self.memcache_servers.split(',') if s.strip()],

View File

@ -48,7 +48,7 @@ class SetConfigParser(object):
if option == 'memcache_servers':
return '1.2.3.4:5'
elif option == 'memcache_serialization_support':
return '2'
return '1'
else:
raise NoOptionError(option)
else:
@ -104,6 +104,8 @@ class TestCacheMiddleware(unittest.TestCase):
finally:
memcache.ConfigParser = orig_parser
self.assertEquals(app.memcache_servers, '127.0.0.1:11211')
self.assertEquals(app.memcache._allow_pickle, False)
self.assertEquals(app.memcache._allow_unpickle, False)
def test_conf_from_extra_conf(self):
orig_parser = memcache.ConfigParser
@ -113,16 +115,22 @@ class TestCacheMiddleware(unittest.TestCase):
finally:
memcache.ConfigParser = orig_parser
self.assertEquals(app.memcache_servers, '1.2.3.4:5')
self.assertEquals(app.memcache._allow_pickle, False)
self.assertEquals(app.memcache._allow_unpickle, True)
def test_conf_from_inline_conf(self):
orig_parser = memcache.ConfigParser
memcache.ConfigParser = SetConfigParser
try:
app = memcache.MemcacheMiddleware(
FakeApp(), {'memcache_servers': '6.7.8.9:10'})
FakeApp(),
{'memcache_servers': '6.7.8.9:10',
'serialization_format': '0'})
finally:
memcache.ConfigParser = orig_parser
self.assertEquals(app.memcache_servers, '6.7.8.9:10')
self.assertEquals(app.memcache._allow_pickle, False)
self.assertEquals(app.memcache._allow_unpickle, True)
if __name__ == '__main__':