2012-02-09 09:53:03 -08:00
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
|
|
|
|
from keystone import exception
|
2012-02-06 18:49:03 -08:00
|
|
|
from keystone import test
|
|
|
|
from keystone.token.backends import memcache as token_memcache
|
|
|
|
|
2012-02-09 09:53:03 -08:00
|
|
|
import test_backend
|
|
|
|
|
2012-02-06 18:49:03 -08:00
|
|
|
|
|
|
|
class MemcacheClient(object):
|
|
|
|
"""Replicates a tiny subset of memcached client interface."""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""Ignores the passed in args."""
|
|
|
|
self.cache = {}
|
|
|
|
|
|
|
|
def get(self, key):
|
|
|
|
"""Retrieves the value for a key or None."""
|
2012-02-09 09:53:03 -08:00
|
|
|
try:
|
|
|
|
return self.cache[key]
|
|
|
|
except KeyError:
|
|
|
|
raise exception.TokenNotFound(token_id=key)
|
2012-02-06 18:49:03 -08:00
|
|
|
|
|
|
|
def set(self, key, value):
|
|
|
|
"""Sets the value for a key."""
|
|
|
|
self.cache[key] = value
|
|
|
|
return True
|
|
|
|
|
|
|
|
def delete(self, key):
|
|
|
|
try:
|
|
|
|
del self.cache[key]
|
|
|
|
except KeyError:
|
|
|
|
#NOTE(bcwaldon): python-memcached always returns the same value
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2012-02-09 09:53:03 -08:00
|
|
|
class MemcacheToken(test.TestCase, test_backend.TokenTests):
|
2012-02-06 18:49:03 -08:00
|
|
|
def setUp(self):
|
|
|
|
super(MemcacheToken, self).setUp()
|
|
|
|
fake_client = MemcacheClient()
|
|
|
|
self.token_api = token_memcache.Token(client=fake_client)
|